Skip to content

Commit ff8cce1

Browse files
authored
Merge pull request #12026 from Ma27/2.3-backport-structured-attrs-env
[2.3] build: backport NIX_ATTRS_*_FILE
2 parents 99f14d4 + 0c5333a commit ff8cce1

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/libstore/build.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2584,6 +2584,7 @@ void DerivationGoal::writeStructuredAttrs()
25842584

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

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

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

26582660

tests/structured-attrs.nix

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ mkDerivation {
3838
[[ $json =~ '"narSize":288' ]]
3939
[[ $json =~ '"closureSize":288' ]]
4040
[[ $json =~ '"references":[]' ]]
41+
42+
[[ -e "$NIX_ATTRS_SH_FILE" ]]
43+
[[ -e "$NIX_ATTRS_JSON_FILE" ]]
44+
45+
[[ "$(<"$NIX_ATTRS_SH_FILE")" = "$(<.attrs.sh)" ]]
46+
[[ "$(<"$NIX_ATTRS_JSON_FILE")" = "$(<.attrs.json)" ]]
4147
'';
4248

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

0 commit comments

Comments
 (0)