Merge pull request #257919 from Ma27/structured-attrs-env-vars
structured attrs: prefer `NIX_ATTRS_*_FILE` over `.attrs.*`
This commit is contained in:
commit
81f6dc0864
@ -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() {
|
||||
|
@ -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
|
||||
|
@ -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..."
|
||||
|
@ -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}
|
||||
|
||||
|
@ -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"])
|
||||
|
@ -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
|
||||
'';
|
||||
}
|
||||
|
@ -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'"
|
||||
|
@ -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"; \
|
||||
|
@ -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=""
|
||||
|
@ -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}"
|
||||
|
@ -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"
|
||||
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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
|
||||
|
@ -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]}
|
||||
''
|
||||
|
@ -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";
|
||||
|
@ -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
|
||||
|
@ -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"
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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"
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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"
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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() {
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user