Merge pull request #573 from jnovy/348

Add optional systemd support for static builds
This commit is contained in:
Jindrich Novy 2025-08-25 11:52:38 +02:00 committed by GitHub
commit 11bcc31eae
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 0 deletions

View File

@ -38,10 +38,14 @@ override CFLAGS += $(shell $(PKG_CONFIG) --cflags glib-2.0) -DVERSION=\"$(VERSIO
# "pkg-config --exists" will error if the package doesn't exist. Make can only compare # "pkg-config --exists" will error if the package doesn't exist. Make can only compare
# output of commands, so the echo commands are to allow pkg-config to error out, make to catch it, # output of commands, so the echo commands are to allow pkg-config to error out, make to catch it,
# and allow the compilation to complete. # and allow the compilation to complete.
#
# For static builds, systemd can be disabled with DISABLE_SYSTEMD=1
ifneq ($(DISABLE_SYSTEMD), 1)
ifeq ($(shell $(PKG_CONFIG) --exists libsystemd && echo "0"), 0) ifeq ($(shell $(PKG_CONFIG) --exists libsystemd && echo "0"), 0)
override LIBS += $(shell $(PKG_CONFIG) --libs libsystemd) override LIBS += $(shell $(PKG_CONFIG) --libs libsystemd)
override CFLAGS += $(shell $(PKG_CONFIG) --cflags libsystemd) -D USE_JOURNALD=1 override CFLAGS += $(shell $(PKG_CONFIG) --cflags libsystemd) -D USE_JOURNALD=1
endif endif
endif
ifeq ($(shell hack/seccomp-notify.sh), 0) ifeq ($(shell hack/seccomp-notify.sh), 0)
override LIBS += $(shell $(PKG_CONFIG) --libs libseccomp) -ldl override LIBS += $(shell $(PKG_CONFIG) --libs libseccomp) -ldl

View File

@ -1,5 +1,6 @@
{ stdenv { stdenv
, pkgs , pkgs
, enableSystemd ? false
}: }:
with pkgs; stdenv.mkDerivation rec { with pkgs; stdenv.mkDerivation rec {
name = "conmon"; name = "conmon";
@ -18,11 +19,15 @@ with pkgs; stdenv.mkDerivation rec {
] ++ [ ] ++ [
pkgsStatic.glib pkgsStatic.glib
libseccomp libseccomp
] ++ lib.optionals enableSystemd [
# Only include systemd for dynamic builds, not static builds
# Static builds will use PKG_CONFIG_PATH approach instead
]; ];
prePatch = '' prePatch = ''
export CFLAGS='-static -pthread' export CFLAGS='-static -pthread'
export LDFLAGS='-s -w -static-libgcc -static' export LDFLAGS='-s -w -static-libgcc -static'
export EXTRA_LDFLAGS='-s -w -linkmode external -extldflags "-static -lm"' export EXTRA_LDFLAGS='-s -w -linkmode external -extldflags "-static -lm"'
${lib.optionalString (!enableSystemd) "export DISABLE_SYSTEMD=1"}
''; '';
buildPhase = '' buildPhase = ''
patchShebangs . patchShebangs .