Skip to content

Commit

Permalink
Merge pull request #12026 from Ma27/2.3-backport-structured-attrs-env
Browse files Browse the repository at this point in the history
[2.3] build: backport NIX_ATTRS_*_FILE
  • Loading branch information
edolstra authored Dec 9, 2024
2 parents 99f14d4 + 0c5333a commit ff8cce1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/libstore/build.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2584,6 +2584,7 @@ void DerivationGoal::writeStructuredAttrs()

writeFile(tmpDir + "/.attrs.json", rewriteStrings(json.dump(), inputRewrites));
chownToBuilder(tmpDir + "/.attrs.json");
env["NIX_ATTRS_JSON_FILE"] = tmpDirInSandbox + "/.attrs.json";

/* As a convenience to bash scripts, write a shell file that
maps all attributes that are representable in bash -
Expand Down Expand Up @@ -2653,6 +2654,7 @@ void DerivationGoal::writeStructuredAttrs()

writeFile(tmpDir + "/.attrs.sh", rewriteStrings(jsonSh, inputRewrites));
chownToBuilder(tmpDir + "/.attrs.sh");
env["NIX_ATTRS_SH_FILE"] = tmpDirInSandbox + "/.attrs.sh";
}


Expand Down
6 changes: 6 additions & 0 deletions tests/structured-attrs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ mkDerivation {
[[ $json =~ '"narSize":288' ]]
[[ $json =~ '"closureSize":288' ]]
[[ $json =~ '"references":[]' ]]
[[ -e "$NIX_ATTRS_SH_FILE" ]]
[[ -e "$NIX_ATTRS_JSON_FILE" ]]
[[ "$(<"$NIX_ATTRS_SH_FILE")" = "$(<.attrs.sh)" ]]
[[ "$(<"$NIX_ATTRS_JSON_FILE")" = "$(<.attrs.json)" ]]
'';

buildInputs = [ "a" "b" "c" 123 "'" "\"" null ];
Expand Down

0 comments on commit ff8cce1

Please sign in to comment.