Skip to content

Commit

Permalink
stdenv.mkDerivation: support structuredAttrs in inputDerivation
Browse files Browse the repository at this point in the history
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
  • Loading branch information
wolfgangwalther committed Dec 3, 2024
1 parent 53f3c92 commit 6648c58
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions pkgs/stdenv/generic/make-derivation.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6648c58

Please sign in to comment.