From dc42ccec8763730af36bce384d8d42f920d05604 Mon Sep 17 00:00:00 2001 From: nikstur Date: Thu, 20 Jul 2023 19:15:42 +0200 Subject: [PATCH] systemd: fix ukify (to cross compile) --- pkgs/os-specific/linux/systemd/default.nix | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/pkgs/os-specific/linux/systemd/default.nix b/pkgs/os-specific/linux/systemd/default.nix index 53244a5a9147..f037d7221ad3 100644 --- a/pkgs/os-specific/linux/systemd/default.nix +++ b/pkgs/os-specific/linux/systemd/default.nix @@ -82,6 +82,9 @@ , bpftools , libbpf + # Needed to produce a ukify that works for cross compiling UKIs. +, targetPackages + , withAcl ? true , withAnalyze ? true , withApparmor ? true @@ -242,6 +245,16 @@ stdenv.mkDerivation (finalAttrs: { # BPF does not work with stack protector substituteInPlace src/core/bpf/meson.build \ --replace "clang_flags = [" "clang_flags = [ '-fno-stack-protector'," + '' + lib.optionalString withUkify '' + substituteInPlace src/ukify/ukify.py \ + --replace \ + "'readelf'" \ + "'${targetPackages.stdenv.cc.bintools.targetPrefix}readelf'" + # The objcopy dependency is removed in v254 + substituteInPlace src/ukify/ukify.py \ + --replace \ + "'objcopy'" \ + "'${targetPackages.stdenv.cc.bintools.targetPrefix}objcopy'" '' + ( let # The following patches references to dynamic libraries to ensure that @@ -731,6 +744,11 @@ stdenv.mkDerivation (finalAttrs: { done '' + lib.optionalString withEfi '' mv $out/dont-strip-me $out/lib/systemd/boot/efi + '' + lib.optionalString withUkify '' + # To cross compile a derivation that builds a UKI with ukify, we need to wrap + # ukify with the correct binutils. When wrapping, no splicing happens so we + # have to explicitly pull binutils from targetPackages. + wrapProgram $out/lib/systemd/ukify --set PATH ${lib.makeBinPath [ targetPackages.stdenv.cc.bintools ] } ''; disallowedReferences = lib.optionals (stdenv.buildPlatform != stdenv.hostPlatform)