Merge pull request #257919 from Ma27/structured-attrs-env-vars

structured attrs: prefer `NIX_ATTRS_*_FILE` over `.attrs.*`
This commit is contained in:
Linus Heckemann 2023-10-05 12:48:00 +02:00 committed by GitHub
commit 81f6dc0864
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
41 changed files with 54 additions and 79 deletions

View File

@ -1,4 +1,4 @@
if [ -e .attrs.sh ]; then source .attrs.sh; fi
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
source $stdenv/setup
doSub() {

View File

@ -1,6 +1,6 @@
set -e
if [ -e .attrs.sh ]; then source .attrs.sh; fi
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
source $stdenv/setup
mkdir -p $out/bin

View File

@ -1,4 +1,4 @@
if [ -e .attrs.sh ]; then source .attrs.sh; fi
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
source $stdenv/setup
echo "unpacking $src..."

View File

@ -1,4 +1,4 @@
{ lib, stdenv, buildPackages }:
{ lib, stdenv, coreutils, jq, python3, nix, xz }:
# This function is for creating a flat-file binary cache, i.e. the kind created by
# nix copy --to file:///some/path and usable as a substituter (with the file:// prefix).
@ -19,15 +19,10 @@ stdenv.mkDerivation {
preferLocalBuild = true;
PATH = lib.makeBinPath (with buildPackages; [ coreutils jq python3 nix xz ]);
nativeBuildInputs = [ coreutils jq python3 nix xz ];
builder = builtins.toFile "builder" ''
. .attrs.sh
export out=''${outputs[out]}
mkdir $out
mkdir $out/nar
buildCommand = ''
mkdir -p $out/nar
python ${./make-binary-cache.py}

View File

@ -3,7 +3,7 @@ import json
import os
import subprocess
with open(".attrs.json", "r") as f:
with open(os.environ["NIX_ATTRS_JSON_FILE"], "r") as f:
closures = json.load(f)["closure"]
os.chdir(os.environ["out"])

View File

@ -4,7 +4,7 @@
# "nix-store --load-db" and "nix-store --register-validity
# --hash-given".
{ stdenv, buildPackages }:
{ stdenv, coreutils, jq }:
{ rootPaths }:
@ -19,18 +19,16 @@ stdenv.mkDerivation {
preferLocalBuild = true;
PATH = "${buildPackages.coreutils}/bin:${buildPackages.jq}/bin";
nativeBuildInputs = [ coreutils jq ];
builder = builtins.toFile "builder"
buildCommand =
''
. .attrs.sh
out=''${outputs[out]}
mkdir $out
jq -r ".closure | map(.narSize) | add" < .attrs.json > $out/total-nar-size
jq -r '.closure | map([.path, .narHash, .narSize, "", (.references | length)] + .references) | add | map("\(.)\n") | add' < .attrs.json | head -n -1 > $out/registration
jq -r .closure[].path < .attrs.json > $out/store-paths
jq -r ".closure | map(.narSize) | add" < "$NIX_ATTRS_JSON_FILE" > $out/total-nar-size
jq -r '.closure | map([.path, .narHash, .narSize, "", (.references | length)] + .references) | add | map("\(.)\n") | add' < "$NIX_ATTRS_JSON_FILE" | head -n -1 > $out/registration
jq -r '.closure[].path' < "$NIX_ATTRS_JSON_FILE" > $out/store-paths
'';
}

View File

@ -1,4 +1,4 @@
if [ -e .attrs.sh ]; then source .attrs.sh; fi
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
source "$stdenv/setup"
echo "exporting \`$url' (revision $rev) into \`$out'"

View File

@ -1,4 +1,4 @@
if [ -e .attrs.sh ]; then source .attrs.sh; fi
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
source $stdenv/setup
(echo "#!$SHELL"; \

View File

@ -1,4 +1,4 @@
if [ -e .attrs.sh ]; then source .attrs.sh; fi
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
source $stdenv/setup
tagtext=""

View File

@ -1,4 +1,4 @@
if [ -e .attrs.sh ]; then source .attrs.sh; fi
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
source "${stdenv}/setup"
echo "exporting ${repository}/${imageName} (tag: ${tag}) into ${out}"
mkdir -p "${out}"

View File

@ -1,4 +1,4 @@
if [ -e .attrs.sh ]; then source .attrs.sh; fi
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
source $stdenv/setup
echo "Cloning Fossil $url [$rev] into $out"

View File

@ -3,7 +3,7 @@
# - revision specified and remote has a HEAD
# - revision specified and remote without HEAD
#
if [ -e .attrs.sh ]; then source .attrs.sh; fi
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
source $stdenv/setup
echo "exporting $url (rev $rev) into $out"

View File

@ -1,4 +1,4 @@
if [ -e .attrs.sh ]; then source .attrs.sh; fi
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
source $stdenv/setup
echo "getting $url${rev:+ ($rev)} into $out"

View File

@ -1,4 +1,4 @@
if [ -e .attrs.sh ]; then source .attrs.sh; fi
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
source $stdenv/setup
# Curl flags to handle redirects, not use EPSV, handle cookies for

View File

@ -1,4 +1,4 @@
if [ -e .attrs.sh ]; then source .attrs.sh; fi
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
source $stdenv/setup
set -x

View File

@ -1,4 +1,4 @@
if [ -e .attrs.sh ]; then source .attrs.sh; fi
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
source $stdenv/setup
echo "exporting $url (r$rev) into $out"

View File

@ -1,4 +1,4 @@
if [ -e .attrs.sh ]; then source .attrs.sh; fi
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
source $stdenv/setup
echo "exporting $url (r$rev) into $out"

View File

@ -1,4 +1,4 @@
if [ -e .attrs.sh ]; then source .attrs.sh; fi
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
source $stdenv/setup
source $mirrorsFile

View File

@ -6,11 +6,8 @@ path: runCommand "closure-paths"
exportReferencesGraph.graph = path;
__structuredAttrs = true;
preferLocalBuild = true;
PATH = "${coreutils}/bin:${python3}/bin";
builder = builtins.toFile "builder"
''
. .attrs.sh
python3 ${./closure-graph.py} .attrs.json graph > ''${outputs[out]}
'';
}
""
nativeBuildInputs = [ coreutils python3 ];
}
''
python3 ${./closure-graph.py} "$NIX_ATTRS_JSON_FILE" graph > ''${outputs[out]}
''

View File

@ -1,4 +1,4 @@
if [ -e .attrs.sh ]; then source .attrs.sh; fi
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
source $stdenv/setup
providedPreConfigure="$preConfigure";

View File

@ -1,4 +1,4 @@
if [ -e .attrs.sh ]; then source .attrs.sh; fi
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
source $stdenv/setup
export JAVA_HOME=$jre

View File

@ -1,4 +1,4 @@
if [ -e .attrs.sh ]; then source .attrs.sh; fi
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
source $stdenv/setup
echo "exporting egg ${eggName} (version $version) into $out"

View File

@ -1,4 +1,4 @@
if [ -e .attrs.sh ]; then source .attrs.sh; fi
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
source $stdenv/setup
pkgdir=$(pwd)/pkg

View File

@ -1,4 +1,4 @@
if [ -e .attrs.sh ]; then source .attrs.sh; fi
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
source $stdenv/setup
tar xf $src

View File

@ -1,5 +1,5 @@
# -*- shell-script -*-
if [ -e .attrs.sh ]; then source .attrs.sh; fi
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
source $stdenv/setup
function extract

View File

@ -1,4 +1,4 @@
if [ -e .attrs.sh ]; then source .attrs.sh; fi
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
source $stdenv/setup
configureFlags="-prefix $out $configureFlags"

View File

@ -1,4 +1,4 @@
if [ -e .attrs.sh ]; then source .attrs.sh; fi
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
# Glibc cannot have itself in its RPATH.
export NIX_NO_SELF_RPATH=1

View File

@ -1,4 +1,4 @@
if [ -e .attrs.sh ]; then source .attrs.sh; fi
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
source $stdenv/setup
genericBuild

View File

@ -1,4 +1,4 @@
if [ -e .attrs.sh ]; then source .attrs.sh; fi
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
source $stdenv/setup
mkdir unzipped

View File

@ -1,4 +1,4 @@
if [ -e .attrs.sh ]; then source .attrs.sh; fi
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
source $stdenv/setup
PERL5LIB="$PERL5LIB${PERL5LIB:+:}$out/lib/perl5/site_perl"

View File

@ -1,4 +1,4 @@
if [ -e .attrs.sh ]; then source .attrs.sh; fi
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
source $stdenv/setup
boot_bin=$out/bin/boot

View File

@ -1,4 +1,4 @@
if [ -e .attrs.sh ]; then source .attrs.sh; fi
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
source $stdenv/setup
# Wrap the given `aclocal' program, appending extra `-I' flags

View File

@ -1,4 +1,4 @@
if [ -e .attrs.sh ]; then source .attrs.sh; fi
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
source $stdenv/setup
tar zxvf $src

View File

@ -1,4 +1,4 @@
if [ -e .attrs.sh ]; then source .attrs.sh; fi
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
source $stdenv/setup
arch=$(uname -m)

View File

@ -1,4 +1,4 @@
if [ -e .attrs.sh ]; then source .attrs.sh; fi
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
source $stdenv/setup
unpackManually() {

View File

@ -1,4 +1,4 @@
if [ -e .attrs.sh ]; then source .attrs.sh; fi
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
source $stdenv/setup
mkdir -p $out/lib

View File

@ -1,4 +1,4 @@
if [ -e .attrs.sh ]; then source .attrs.sh; fi
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
source $stdenv/setup
unzip $src

View File

@ -1,4 +1,4 @@
if [ -e .attrs.sh ]; then source .attrs.sh; fi
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
# This is the builder for all X.org components.
source $stdenv/setup

View File

@ -1,6 +1,4 @@
if [ -f .attrs.sh ]; then
. .attrs.sh
fi
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
source $stdenv/setup
genericBuild

View File

@ -16,29 +16,15 @@ if (( "${NIX_DEBUG:-0}" >= 6 )); then
set -x
fi
if [ -f .attrs.sh ]; then
if [ -f .attrs.sh ] || [[ -n "${NIX_ATTRS_JSON_FILE:-}" ]]; then
__structuredAttrs=1
echo "structuredAttrs is enabled"
else
__structuredAttrs=
fi
if [ -n "$__structuredAttrs" ]; then
for outputName in "${!outputs[@]}"; do
# ex: out=/nix/store/...
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
@ -49,6 +35,7 @@ if [ -n "$__structuredAttrs" ]; then
export NIX_ATTRS_SH_FILE="$NIX_BUILD_TOP/.attrs.sh"
fi
else
__structuredAttrs=
: "${outputs:=out}"
fi

View File

@ -1,4 +1,4 @@
if [ -e .attrs.sh ]; then source .attrs.sh; fi
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
set -x
export NIX_DEBUG=1