Skip to content

Commit 1a29857

Browse files
stdenv/setup.sh: deal with Nix < 2.4 structured attrs
Nix does not (as far it is documented) guarantee that NIX_ATTRS_*_FILE is set, the only [documented] guarantee seems to be: > […] made available to the builder via the file .attrs.json in the > builder’s temporary directory. This guarantee is of course affected by NixOS/nix#6736, so it seems to be prudent to fall back to the Nix 2.3 style ATTRS_*_FILE env vars before defaulting to the expected location in case neither is available. See also: - #214937 (comment) - afef6588e250 [documented]: https://nixos.org/manual/nix/stable/language/advanced-attributes.html#adv-attr-structuredAttrs
1 parent 8d7893b commit 1a29857

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

pkgs/stdenv/generic/setup.sh

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,23 @@ if [ -n "$__structuredAttrs" ]; then
2929
export "$outputName=${outputs[$outputName]}"
3030
done
3131

32+
# Before Nix 2.4, $NIX_ATTRS_*_FILE was named differently:
33+
# https://github.com/NixOS/nix/commit/27ce722
34+
if [[ -n "${ATTRS_JSON_FILE:-}" ]]; then
35+
export NIX_ATTRS_JSON_FILE="$ATTRS_JSON_FILE"
36+
fi
37+
38+
if [[ -n "${ATTRS_SH_FILE:-}" ]]; then
39+
export NIX_ATTRS_SH_FILE="$ATTRS_SH_FILE"
40+
fi
41+
3242
# $NIX_ATTRS_JSON_FILE pointed to the wrong location in sandbox
3343
# https://github.com/NixOS/nix/issues/6736; please keep around until the
3444
# fix reaches *every patch version* that's >= lib/minver.nix
35-
if ! [[ -e "$NIX_ATTRS_JSON_FILE" ]]; then
45+
if ! [[ -e "${NIX_ATTRS_JSON_FILE:-}" ]]; then
3646
export NIX_ATTRS_JSON_FILE="$NIX_BUILD_TOP/.attrs.json"
3747
fi
38-
if ! [[ -e "$NIX_ATTRS_SH_FILE" ]]; then
48+
if ! [[ -e "${NIX_ATTRS_SH_FILE:-}" ]]; then
3949
export NIX_ATTRS_SH_FILE="$NIX_BUILD_TOP/.attrs.sh"
4050
fi
4151
else

0 commit comments

Comments
 (0)