Skip to content

Commit ce1ca6a

Browse files
committed
fix(base): build s6 with setgroups compat for FreeBSD 14
FreeBSD 15 renumbered setgroups w/ the introduction of libsys, causing SIGSYS on older kernels. This injects a .symver directive via CFLAGS to bind setgroups@FBSD_1.0. While daemonless does not offically support FreeBSD 14, this provides best-effort compatibility for older hosts. Fixes: daemonless/immich-postgres#2
1 parent 611cefa commit ce1ca6a

5 files changed

Lines changed: 103 additions & 12 deletions

File tree

.daemonless/config.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
type: base
22
build:
3-
auto_version: true
43
architectures:
54
- amd64
65
variants:

Containerfile

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,46 @@
55
# --------------------------------------------------------------------------
66

77
ARG BASE_VERSION=15-pkg
8+
9+
# Builder: compile s6 from ports with FreeBSD 14 compat symver patch.
10+
# The FreeBSD 15 pkg for s6 links setgroups() against libsys syscall 596
11+
# (freebsd15_setgroups), which does not exist on FreeBSD 14. Injecting
12+
# .symver via CFLAGS forces setgroups@FBSD_1.0 (syscall 80) in every
13+
# compilation unit, making the resulting binaries work on both FreeBSD 14+15.
14+
FROM ghcr.io/daemonless/base-core:${BASE_VERSION} AS s6-builder
15+
16+
RUN pkg update && pkg install -y \
17+
FreeBSD-clang FreeBSD-clibs-dev FreeBSD-toolchain FreeBSD-bmake gmake \
18+
&& pkg clean -ay && rm -rf /var/cache/pkg/* /var/db/pkg/repos/*
19+
20+
COPY patches/fbsd14_compat.h /tmp/fbsd14_compat.h
21+
22+
# Fetch only the ports we need (skalibs -> execline -> s6) plus build infra
23+
RUN fetch -qo /tmp/ports.tar.zst \
24+
"https://download.freebsd.org/ports/ports/ports.tar.zst" && \
25+
mkdir -p /usr/ports && \
26+
tar -xf /tmp/ports.tar.zst -C /usr/ports --strip-components=1 \
27+
ports/devel/skalibs \
28+
ports/lang/execline \
29+
ports/sysutils/s6 \
30+
ports/Mk ports/Templates ports/Keywords && \
31+
rm /tmp/ports.tar.zst
32+
33+
# Build skalibs -> execline -> s6 from ports in dependency order.
34+
# CFLAGS in make.conf propagates to all ports. USE_PACKAGE_DEPENDS_ONLY
35+
# satisfies external build deps (gmake etc.) from pkg without building them.
36+
# pkg create produces packages that pkg add installs in the final stage.
37+
RUN echo 'CFLAGS+=-include /tmp/fbsd14_compat.h' >> /etc/make.conf && \
38+
mkdir -p /tmp/packages && \
39+
make -C /usr/ports/devel/skalibs BATCH=yes USE_PACKAGE_DEPENDS_ONLY=yes install clean && \
40+
pkg create -o /tmp/packages skalibs && \
41+
make -C /usr/ports/lang/execline BATCH=yes USE_PACKAGE_DEPENDS_ONLY=yes install clean && \
42+
pkg create -o /tmp/packages execline && \
43+
make -C /usr/ports/sysutils/s6 BATCH=yes USE_PACKAGE_DEPENDS_ONLY=yes install clean && \
44+
pkg create -o /tmp/packages s6 && \
45+
rm -rf /usr/ports
46+
47+
# Production image
848
FROM ghcr.io/daemonless/base-core:${BASE_VERSION}
949

1050
ARG PACKAGES="s6"
@@ -23,10 +63,12 @@ LABEL org.opencontainers.image.title="FreeBSD Base" \
2363

2464
COPY root/ /
2565

26-
RUN pkg update && \
27-
pkg install -y ${PACKAGES} && \
28-
pkg clean -ay && \
29-
rm -rf /var/cache/pkg/* /var/db/pkg/repos/*
66+
# Install s6 and deps from packages built in builder (patched for FreeBSD 14 compat)
67+
COPY --from=s6-builder /tmp/packages/ /tmp/packages/
68+
RUN pkg add /tmp/packages/skalibs-*.pkg && \
69+
pkg add /tmp/packages/execline-*.pkg && \
70+
pkg add /tmp/packages/s6-*.pkg && \
71+
rm -rf /tmp/packages
3072

3173
RUN mkdir -p /etc/cont-init.d \
3274
/etc/services.d \

Containerfile.j2

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,44 @@
11
ARG BASE_VERSION=15-pkg
2+
3+
# Builder: compile s6 from ports with FreeBSD 14 compat symver patch.
4+
# The FreeBSD 15 pkg for s6 links setgroups() against libsys syscall 596
5+
# (freebsd15_setgroups), which does not exist on FreeBSD 14. Injecting
6+
# .symver via CFLAGS forces setgroups@FBSD_1.0 (syscall 80) in every
7+
# compilation unit, making the resulting binaries work on both FreeBSD 14+15.
8+
FROM ghcr.io/daemonless/base-core:${BASE_VERSION} AS s6-builder
9+
10+
RUN pkg update && pkg install -y \
11+
FreeBSD-clang FreeBSD-clibs-dev FreeBSD-toolchain FreeBSD-bmake gmake \
12+
&& pkg clean -ay && rm -rf /var/cache/pkg/* /var/db/pkg/repos/*
13+
14+
COPY patches/fbsd14_compat.h /tmp/fbsd14_compat.h
15+
16+
# Fetch only the ports we need (skalibs -> execline -> s6) plus build infra
17+
RUN fetch -qo /tmp/ports.tar.zst \
18+
"https://download.freebsd.org/ports/ports/ports.tar.zst" && \
19+
mkdir -p /usr/ports && \
20+
tar -xf /tmp/ports.tar.zst -C /usr/ports --strip-components=1 \
21+
ports/devel/skalibs \
22+
ports/lang/execline \
23+
ports/sysutils/s6 \
24+
ports/Mk ports/Templates ports/Keywords && \
25+
rm /tmp/ports.tar.zst
26+
27+
# Build skalibs -> execline -> s6 from ports in dependency order.
28+
# CFLAGS in make.conf propagates to all ports. USE_PACKAGE_DEPENDS_ONLY
29+
# satisfies external build deps (gmake etc.) from pkg without building them.
30+
# pkg create produces packages that pkg add installs in the final stage.
31+
RUN echo 'CFLAGS+=-include /tmp/fbsd14_compat.h' >> /etc/make.conf && \
32+
mkdir -p /tmp/packages && \
33+
make -C /usr/ports/devel/skalibs BATCH=yes USE_PACKAGE_DEPENDS_ONLY=yes install clean && \
34+
pkg create -o /tmp/packages skalibs && \
35+
make -C /usr/ports/lang/execline BATCH=yes USE_PACKAGE_DEPENDS_ONLY=yes install clean && \
36+
pkg create -o /tmp/packages execline && \
37+
make -C /usr/ports/sysutils/s6 BATCH=yes USE_PACKAGE_DEPENDS_ONLY=yes install clean && \
38+
pkg create -o /tmp/packages s6 && \
39+
rm -rf /usr/ports
40+
41+
# Production image
242
FROM ghcr.io/daemonless/base-core:${BASE_VERSION}
343

444
ARG PACKAGES="s6"
@@ -17,10 +57,12 @@ LABEL org.opencontainers.image.title="{{ title }}" \
1757

1858
COPY root/ /
1959

20-
RUN pkg update && \
21-
pkg install -y ${PACKAGES} && \
22-
pkg clean -ay && \
23-
rm -rf /var/cache/pkg/* /var/db/pkg/repos/*
60+
# Install s6 and deps from packages built in builder (patched for FreeBSD 14 compat)
61+
COPY --from=s6-builder /tmp/packages/ /tmp/packages/
62+
RUN pkg add /tmp/packages/skalibs-*.pkg && \
63+
pkg add /tmp/packages/execline-*.pkg && \
64+
pkg add /tmp/packages/s6-*.pkg && \
65+
rm -rf /tmp/packages
2466

2567
RUN mkdir -p /etc/cont-init.d \
2668
/etc/services.d \

README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ services:
3939
restart: unless-stopped
4040
```
4141
42-
4342
### Podman CLI
4443
4544
```bash
@@ -58,8 +57,6 @@ podman run -d --name base \
5857
restart_policy: always
5958
```
6059
61-
## Parameters
62-
6360
**Architectures:** amd64
6461
**User:** `root` (UID/GID via PUID/PGID, defaults to 1000:1000)
6562
**Base:** FreeBSD 15.0

patches/fbsd14_compat.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*
2+
* FreeBSD 14 compatibility header for s6 source builds.
3+
*
4+
* FreeBSD 15 introduced libsys.so.7 which renumbered setgroups() from
5+
* syscall 80 (FBSD_1.0) to syscall 596 (FBSD_1.8). Binaries compiled on
6+
* FreeBSD 15 reference setgroups@@FBSD_1.8 which does not exist on FreeBSD 14.
7+
*
8+
*/
9+
#if defined(__FreeBSD__) && __FreeBSD__ >= 15
10+
__asm__(".symver setgroups, setgroups@FBSD_1.0");
11+
#endif

0 commit comments

Comments
 (0)