mirror of
https://github.com/NixOS/nix
synced 2025-06-27 16:51:15 +02:00
Set environment variables for .attrs.json & .attrs.sh
This way no derivation has to expect that these files are in the `cwd` during the build. This is problematic for `nix-shell` where these files would have to be inserted into the nix-shell's `cwd` which can become problematic with e.g. recursive `nix-shell`. To remain backwards-compatible, the location inside the build sandbox will be kept, however using these files directly should be deprecated from now on.
This commit is contained in:
parent
3b5429aec1
commit
3944a120ec
4 changed files with 11 additions and 10 deletions
|
@ -428,7 +428,6 @@ static void main_nix_build(int argc, char * * argv)
|
|||
env[var.first] = var.second;
|
||||
|
||||
std::string structuredAttrsRC;
|
||||
std::string exitCmd;
|
||||
|
||||
if (env.count("__json")) {
|
||||
StorePathSet inputs;
|
||||
|
@ -448,11 +447,13 @@ static void main_nix_build(int argc, char * * argv)
|
|||
if (auto structAttrs = parsedDrv.generateStructuredAttrs(std::nullopt, *store, inputs)) {
|
||||
auto val = structAttrs.value();
|
||||
structuredAttrsRC = val.first;
|
||||
auto attrsJSON = std::filesystem::current_path().string() + "/.attrs.json";
|
||||
auto attrsJSON = (Path) tmpDir + "/.attrs.json";
|
||||
writeFile(attrsJSON, val.second.dump());
|
||||
exitCmd = "\n_rm_attrs_json() { rm -f " + attrsJSON + "; }"
|
||||
+ "\nexitHooks+=(_rm_attrs_json)"
|
||||
+ "\nfailureHooks+=(_rm_attrs_json)\n";
|
||||
auto attrsSH = (Path) tmpDir + "/.attrs.sh";
|
||||
writeFile(attrsSH, val.first);
|
||||
env["ATTRS_SH_FILE"] = attrsSH;
|
||||
env["ATTRS_JSON_FILE"] = attrsJSON;
|
||||
keepTmp = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -471,7 +472,7 @@ static void main_nix_build(int argc, char * * argv)
|
|||
(pure ? "" : "[ -n \"$PS1\" ] && [ -e ~/.bashrc ] && source ~/.bashrc;") +
|
||||
"%2%"
|
||||
"dontAddDisableDepTrack=1;\n"
|
||||
+ structuredAttrsRC + exitCmd +
|
||||
+ structuredAttrsRC +
|
||||
"\n[ -e $stdenv/setup ] && source $stdenv/setup; "
|
||||
"%3%"
|
||||
"PATH=%4%:\"$PATH\"; "
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue