From 1a29857b8a93f5259f0c2e919becc0bf9db24f85 Mon Sep 17 00:00:00 2001 From: sternenseemann Date: Mon, 29 May 2023 23:07:38 +0200 Subject: [PATCH] stdenv/setup.sh: deal with Nix < 2.4 structured attrs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 https://github.com/NixOS/nix/issues/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: - https://github.com/NixOS/nixpkgs/pull/214937#discussion_r1178101895 - https://github.com/nixos/nixpkgs/commit/afef6588e250 [documented]: https://nixos.org/manual/nix/stable/language/advanced-attributes.html#adv-attr-structuredAttrs --- pkgs/stdenv/generic/setup.sh | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/pkgs/stdenv/generic/setup.sh b/pkgs/stdenv/generic/setup.sh index 734abb890c24..d3009ae572a2 100644 --- a/pkgs/stdenv/generic/setup.sh +++ b/pkgs/stdenv/generic/setup.sh @@ -29,13 +29,23 @@ if [ -n "$__structuredAttrs" ]; then export "$outputName=${outputs[$outputName]}" done + # Before Nix 2.4, $NIX_ATTRS_*_FILE was named differently: + # https://github.com/NixOS/nix/commit/27ce722 + if [[ -n "${ATTRS_JSON_FILE:-}" ]]; then + export NIX_ATTRS_JSON_FILE="$ATTRS_JSON_FILE" + fi + + if [[ -n "${ATTRS_SH_FILE:-}" ]]; then + export NIX_ATTRS_SH_FILE="$ATTRS_SH_FILE" + fi + # $NIX_ATTRS_JSON_FILE pointed to the wrong location in sandbox # https://github.com/NixOS/nix/issues/6736; please keep around until the # fix reaches *every patch version* that's >= lib/minver.nix - if ! [[ -e "$NIX_ATTRS_JSON_FILE" ]]; then + if ! [[ -e "${NIX_ATTRS_JSON_FILE:-}" ]]; then export NIX_ATTRS_JSON_FILE="$NIX_BUILD_TOP/.attrs.json" fi - if ! [[ -e "$NIX_ATTRS_SH_FILE" ]]; then + if ! [[ -e "${NIX_ATTRS_SH_FILE:-}" ]]; then export NIX_ATTRS_SH_FILE="$NIX_BUILD_TOP/.attrs.sh" fi else