From 6648c58eae48ea85b00413dbebb8993650e128c9 Mon Sep 17 00:00:00 2001 From: Wolfgang Walther Date: Mon, 2 Dec 2024 22:31:17 +0100 Subject: [PATCH] stdenv.mkDerivation: support structuredAttrs in inputDerivation The goal is to print all store references into $out. First, $out itself is not defined with structuredAttrs, but we can work around that with placeholder. Alternatively we could source $stdenv/setup after sourcing the attrs.sh file, but that feels like overkill. To support structuredAttrs we source the attrs.sh file. export will not be enough anymore, because the attrs file sets bash variables, not environment variables. Thus we resort to declare -p. Resolves #321005 --- pkgs/stdenv/generic/make-derivation.nix | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pkgs/stdenv/generic/make-derivation.nix b/pkgs/stdenv/generic/make-derivation.nix index ca878fe1032d..c4e4bd930936 100644 --- a/pkgs/stdenv/generic/make-derivation.nix +++ b/pkgs/stdenv/generic/make-derivation.nix @@ -613,13 +613,19 @@ extendDerivation _derivation_original_args = derivationArg.args; builder = stdenv.shell; - # The bash builtin `export` dumps all current environment variables, + # The builtin `declare -p` dumps all bash and environment variables, # which is where all build input references end up (e.g. $PATH for # binaries). By writing this to $out, Nix can find and register # them as runtime dependencies (since Nix greps for store paths - # through $out to find them) + # through $out to find them). Using placeholder for $out works with + # and without structuredAttrs. + # This build script does not use setup.sh or stdenv, to keep + # the env most pristine. This gives us a very bare bones env, + # hence the extra/duplicated compatibility logic and "pure bash" style. args = [ "-c" '' - export > $out + out="${placeholder "out"}" + if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi + declare -p > $out for var in $passAsFile; do pathVar="''${var}Path" printf "%s" "$(< "''${!pathVar}")" >> $out