1
0
mirror of https://github.com/containers/conmon.git synced 2026-02-05 06:46:42 +01:00

Add optional systemd support for static builds

Implement conditional systemd linking to fix static build failures.
Static builds can now disable systemd with DISABLE_SYSTEMD=1.
Nix derivation updated with enableSystemd parameter for flexibility.
Provides backward compatibility while solving static linking issues.

Fixes: #348

Signed-off-by: Jindrich Novy <jnovy@redhat.com>
This commit is contained in:
Jindrich Novy
2025-08-11 17:43:13 +02:00
parent 83cfddd484
commit 270aa5a640
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
# 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.
#
# For static builds, systemd can be disabled with DISABLE_SYSTEMD=1
ifneq ($(DISABLE_SYSTEMD), 1)
ifeq ($(shell $(PKG_CONFIG) --exists libsystemd && echo "0"), 0)
override LIBS += $(shell $(PKG_CONFIG) --libs libsystemd)
override CFLAGS += $(shell $(PKG_CONFIG) --cflags libsystemd) -D USE_JOURNALD=1
endif
endif
ifeq ($(shell hack/seccomp-notify.sh), 0)
override LIBS += $(shell $(PKG_CONFIG) --libs libseccomp) -ldl

View File

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