mirror of
https://github.com/NixOS/nix
synced 2025-07-07 14:21:48 +02:00
Merge remote-tracking branch 'upstream/master' into overlayfs-store
This commit is contained in:
commit
72bb9604f3
75 changed files with 1544 additions and 519 deletions
|
@ -57,6 +57,30 @@ nix build -f multiple-outputs.nix --json 'e^*' --no-link | jq --exit-status '
|
|||
(.outputs | keys == ["a_a", "b", "c"]))
|
||||
'
|
||||
|
||||
# test buidling from non-drv attr path
|
||||
|
||||
nix build -f multiple-outputs.nix --json 'e.a_a.outPath' --no-link | jq --exit-status '
|
||||
(.[0] |
|
||||
(.drvPath | match(".*multiple-outputs-e.drv")) and
|
||||
(.outputs | keys == ["a_a"]))
|
||||
'
|
||||
|
||||
# Illegal type of string context
|
||||
expectStderr 1 nix build -f multiple-outputs.nix 'e.a_a.drvPath' \
|
||||
| grepQuiet "has a context which refers to a complete source and binary closure."
|
||||
|
||||
# No string context
|
||||
expectStderr 1 nix build --expr '""' --no-link \
|
||||
| grepQuiet "has 0 entries in its context. It should only have exactly one entry"
|
||||
|
||||
# Too much string context
|
||||
expectStderr 1 nix build --impure --expr 'with (import ./multiple-outputs.nix).e.a_a; "${drvPath}${outPath}"' --no-link \
|
||||
| grepQuiet "has 2 entries in its context. It should only have exactly one entry"
|
||||
|
||||
nix build --impure --json --expr 'builtins.unsafeDiscardOutputDependency (import ./multiple-outputs.nix).e.a_a.drvPath' --no-link | jq --exit-status '
|
||||
(.[0] | .path | match(".*multiple-outputs-e.drv"))
|
||||
'
|
||||
|
||||
# Test building from raw store path to drv not expression.
|
||||
|
||||
drv=$(nix eval -f multiple-outputs.nix --raw a.drvPath)
|
||||
|
|
8
tests/dyn-drv/common.sh
Normal file
8
tests/dyn-drv/common.sh
Normal file
|
@ -0,0 +1,8 @@
|
|||
source ../common.sh
|
||||
|
||||
# Need backend to support text-hashing too
|
||||
requireDaemonNewerThan "2.16.0pre20230419"
|
||||
|
||||
enableFeatures "ca-derivations dynamic-derivations"
|
||||
|
||||
restartDaemon
|
1
tests/dyn-drv/config.nix.in
Symbolic link
1
tests/dyn-drv/config.nix.in
Symbolic link
|
@ -0,0 +1 @@
|
|||
../config.nix.in
|
33
tests/dyn-drv/recursive-mod-json.nix
Normal file
33
tests/dyn-drv/recursive-mod-json.nix
Normal file
|
@ -0,0 +1,33 @@
|
|||
with import ./config.nix;
|
||||
|
||||
let innerName = "foo"; in
|
||||
|
||||
mkDerivation rec {
|
||||
name = "${innerName}.drv";
|
||||
SHELL = shell;
|
||||
|
||||
requiredSystemFeatures = [ "recursive-nix" ];
|
||||
|
||||
drv = builtins.unsafeDiscardOutputDependency (import ./text-hashed-output.nix).hello.drvPath;
|
||||
|
||||
buildCommand = ''
|
||||
export NIX_CONFIG='experimental-features = nix-command ca-derivations'
|
||||
|
||||
PATH=${builtins.getEnv "EXTRA_PATH"}:$PATH
|
||||
|
||||
# JSON of pre-existing drv
|
||||
nix derivation show $drv | jq .[] > drv0.json
|
||||
|
||||
# Fix name
|
||||
jq < drv0.json '.name = "${innerName}"' > drv1.json
|
||||
|
||||
# Extend `buildCommand`
|
||||
jq < drv1.json '.env.buildCommand += "echo \"I am alive!\" >> $out/hello\n"' > drv0.json
|
||||
|
||||
# Used as our output
|
||||
cp $(nix derivation add < drv0.json) $out
|
||||
'';
|
||||
__contentAddressed = true;
|
||||
outputHashMode = "text";
|
||||
outputHashAlgo = "sha256";
|
||||
}
|
25
tests/dyn-drv/recursive-mod-json.sh
Normal file
25
tests/dyn-drv/recursive-mod-json.sh
Normal file
|
@ -0,0 +1,25 @@
|
|||
source common.sh
|
||||
|
||||
# FIXME
|
||||
if [[ $(uname) != Linux ]]; then skipTest "Not running Linux"; fi
|
||||
|
||||
enableFeatures 'recursive-nix'
|
||||
restartDaemon
|
||||
|
||||
clearStore
|
||||
|
||||
rm -f $TEST_ROOT/result
|
||||
|
||||
EXTRA_PATH=$(dirname $(type -p nix)):$(dirname $(type -p jq))
|
||||
export EXTRA_PATH
|
||||
|
||||
# Will produce a drv
|
||||
metaDrv=$(nix-instantiate ./recursive-mod-json.nix)
|
||||
|
||||
# computed "dynamic" derivation
|
||||
drv=$(nix-store -r $metaDrv)
|
||||
|
||||
# build that dyn drv
|
||||
res=$(nix-store -r $drv)
|
||||
|
||||
grep 'I am alive!' $res/hello
|
29
tests/dyn-drv/text-hashed-output.nix
Normal file
29
tests/dyn-drv/text-hashed-output.nix
Normal file
|
@ -0,0 +1,29 @@
|
|||
with import ./config.nix;
|
||||
|
||||
# A simple content-addressed derivation.
|
||||
# The derivation can be arbitrarily modified by passing a different `seed`,
|
||||
# but the output will always be the same
|
||||
rec {
|
||||
hello = mkDerivation {
|
||||
name = "hello";
|
||||
buildCommand = ''
|
||||
set -x
|
||||
echo "Building a CA derivation"
|
||||
mkdir -p $out
|
||||
echo "Hello World" > $out/hello
|
||||
'';
|
||||
__contentAddressed = true;
|
||||
outputHashMode = "recursive";
|
||||
outputHashAlgo = "sha256";
|
||||
};
|
||||
producingDrv = mkDerivation {
|
||||
name = "hello.drv";
|
||||
buildCommand = ''
|
||||
echo "Copying the derivation"
|
||||
cp ${builtins.unsafeDiscardOutputDependency hello.drvPath} $out
|
||||
'';
|
||||
__contentAddressed = true;
|
||||
outputHashMode = "text";
|
||||
outputHashAlgo = "sha256";
|
||||
};
|
||||
}
|
26
tests/dyn-drv/text-hashed-output.sh
Normal file
26
tests/dyn-drv/text-hashed-output.sh
Normal file
|
@ -0,0 +1,26 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
source common.sh
|
||||
|
||||
# In the corresponding nix file, we have two derivations: the first, named root,
|
||||
# is a normal recursive derivation, while the second, named dependent, has the
|
||||
# new outputHashMode "text". Note that in "dependent", we don't refer to the
|
||||
# build output of root, but only to the path of the drv file. For this reason,
|
||||
# we only need to:
|
||||
#
|
||||
# - instantiate the root derivation
|
||||
# - build the dependent derivation
|
||||
# - check that the path of the output coincides with that of the original derivation
|
||||
|
||||
drv=$(nix-instantiate ./text-hashed-output.nix -A hello)
|
||||
nix show-derivation "$drv"
|
||||
|
||||
drvProducingDrv=$(nix-instantiate ./text-hashed-output.nix -A producingDrv)
|
||||
nix show-derivation "$drvProducingDrv"
|
||||
|
||||
out1=$(nix-build ./text-hashed-output.nix -A producingDrv --no-out-link)
|
||||
|
||||
nix path-info $drv --derivation --json | jq
|
||||
nix path-info $out1 --derivation --json | jq
|
||||
|
||||
test $out1 == $drv
|
|
@ -16,9 +16,10 @@ nix eval --expr 'assert 1 + 2 == 3; true'
|
|||
[[ $(nix eval int -f "./eval.nix") == 123 ]]
|
||||
[[ $(nix eval str -f "./eval.nix") == '"foo"' ]]
|
||||
[[ $(nix eval str --raw -f "./eval.nix") == 'foo' ]]
|
||||
[[ $(nix eval attr -f "./eval.nix") == '{ foo = "bar"; }' ]]
|
||||
[[ "$(nix eval attr -f "./eval.nix")" == '{ foo = "bar"; }' ]]
|
||||
[[ $(nix eval attr --json -f "./eval.nix") == '{"foo":"bar"}' ]]
|
||||
[[ $(nix eval int -f - < "./eval.nix") == 123 ]]
|
||||
[[ "$(nix eval --expr '{"assert"=1;bar=2;}')" == '{ "assert" = 1; bar = 2; }' ]]
|
||||
|
||||
# Check if toFile can be utilized during restricted eval
|
||||
[[ $(nix eval --restrict-eval --expr 'import (builtins.toFile "source" "42")') == 42 ]]
|
||||
|
@ -26,9 +27,10 @@ nix eval --expr 'assert 1 + 2 == 3; true'
|
|||
nix-instantiate --eval -E 'assert 1 + 2 == 3; true'
|
||||
[[ $(nix-instantiate -A int --eval "./eval.nix") == 123 ]]
|
||||
[[ $(nix-instantiate -A str --eval "./eval.nix") == '"foo"' ]]
|
||||
[[ $(nix-instantiate -A attr --eval "./eval.nix") == '{ foo = "bar"; }' ]]
|
||||
[[ "$(nix-instantiate -A attr --eval "./eval.nix")" == '{ foo = "bar"; }' ]]
|
||||
[[ $(nix-instantiate -A attr --eval --json "./eval.nix") == '{"foo":"bar"}' ]]
|
||||
[[ $(nix-instantiate -A int --eval - < "./eval.nix") == 123 ]]
|
||||
[[ "$(nix-instantiate --eval -E '{"assert"=1;bar=2;}')" == '{ "assert" = 1; bar = 2; }' ]]
|
||||
|
||||
# Check that symlink cycles don't cause a hang.
|
||||
ln -sfn cycle.nix $TEST_ROOT/cycle.nix
|
||||
|
|
|
@ -41,10 +41,27 @@ cat > $flake1Dir/flake.nix <<EOF
|
|||
a8 = builtins.storePath $dep;
|
||||
|
||||
a9 = "$dep";
|
||||
|
||||
drvCall = with import ./config.nix; mkDerivation {
|
||||
name = "simple";
|
||||
builder = ./simple.builder.sh;
|
||||
PATH = "";
|
||||
goodPath = path;
|
||||
};
|
||||
|
||||
a10 = builtins.unsafeDiscardOutputDependency self.drvCall.drvPath;
|
||||
|
||||
a11 = self.drvCall.drvPath;
|
||||
|
||||
a12 = self.drvCall.outPath;
|
||||
|
||||
a13 = "\${self.drvCall.drvPath}\${self.drvCall.outPath}";
|
||||
};
|
||||
}
|
||||
EOF
|
||||
|
||||
cp ../simple.nix ../simple.builder.sh ../config.nix $flake1Dir/
|
||||
|
||||
echo bar > $flake1Dir/foo
|
||||
|
||||
nix build --json --out-link $TEST_ROOT/result $flake1Dir#a1
|
||||
|
@ -63,4 +80,17 @@ nix build --json --out-link $TEST_ROOT/result $flake1Dir#a6
|
|||
nix build --impure --json --out-link $TEST_ROOT/result $flake1Dir#a8
|
||||
diff common.sh $TEST_ROOT/result
|
||||
|
||||
(! nix build --impure --json --out-link $TEST_ROOT/result $flake1Dir#a9)
|
||||
expectStderr 1 nix build --impure --json --out-link $TEST_ROOT/result $flake1Dir#a9 \
|
||||
| grepQuiet "has 0 entries in its context. It should only have exactly one entry"
|
||||
|
||||
nix build --json --out-link $TEST_ROOT/result $flake1Dir#a10
|
||||
[[ $(readlink -e $TEST_ROOT/result) = *simple.drv ]]
|
||||
|
||||
expectStderr 1 nix build --json --out-link $TEST_ROOT/result $flake1Dir#a11 \
|
||||
| grepQuiet "has a context which refers to a complete source and binary closure"
|
||||
|
||||
nix build --json --out-link $TEST_ROOT/result $flake1Dir#a12
|
||||
[[ -e $TEST_ROOT/result/hello ]]
|
||||
|
||||
expectStderr 1 nix build --impure --json --out-link $TEST_ROOT/result $flake1Dir#a13 \
|
||||
| grepQuiet "has 2 entries in its context. It should only have exactly one entry"
|
||||
|
|
|
@ -111,6 +111,8 @@ nix_tests = \
|
|||
ca/derivation-json.sh \
|
||||
import-derivation.sh \
|
||||
ca/import-derivation.sh \
|
||||
dyn-drv/text-hashed-output.sh \
|
||||
dyn-drv/recursive-mod-json.sh \
|
||||
nix_path.sh \
|
||||
case-hack.sh \
|
||||
placeholders.sh \
|
||||
|
@ -140,11 +142,19 @@ ifeq ($(HAVE_LIBCPUID), 1)
|
|||
nix_tests += compute-levels.sh
|
||||
endif
|
||||
|
||||
install-tests += $(foreach x, $(nix_tests), tests/$(x))
|
||||
install-tests += $(foreach x, $(nix_tests), $(d)/$(x))
|
||||
|
||||
clean-files += $(d)/common/vars-and-functions.sh $(d)/config.nix $(d)/ca/config.nix
|
||||
clean-files += \
|
||||
$(d)/common/vars-and-functions.sh \
|
||||
$(d)/config.nix \
|
||||
$(d)/ca/config.nix \
|
||||
$(d)/dyn-drv/config.nix
|
||||
|
||||
test-deps += tests/common/vars-and-functions.sh tests/config.nix tests/ca/config.nix
|
||||
test-deps += \
|
||||
tests/common/vars-and-functions.sh \
|
||||
tests/config.nix \
|
||||
tests/ca/config.nix \
|
||||
tests/dyn-drv/config.nix
|
||||
|
||||
ifeq ($(BUILD_SHARED_LIBS), 1)
|
||||
test-deps += tests/plugins/libplugintest.$(SO_EXT)
|
||||
|
|
|
@ -98,6 +98,18 @@ nix develop -f "$shellDotNix" shellDrv -c echo foo |& grepQuiet foo
|
|||
nix print-dev-env -f "$shellDotNix" shellDrv > $TEST_ROOT/dev-env.sh
|
||||
nix print-dev-env -f "$shellDotNix" shellDrv --json > $TEST_ROOT/dev-env.json
|
||||
|
||||
# Test with raw drv
|
||||
|
||||
shellDrv=$(nix-instantiate "$shellDotNix" -A shellDrv.out)
|
||||
|
||||
nix develop $shellDrv -c bash -c '[[ -n $stdenv ]]'
|
||||
|
||||
nix print-dev-env $shellDrv > $TEST_ROOT/dev-env2.sh
|
||||
nix print-dev-env $shellDrv --json > $TEST_ROOT/dev-env2.json
|
||||
|
||||
diff $TEST_ROOT/dev-env{,2}.sh
|
||||
diff $TEST_ROOT/dev-env{,2}.json
|
||||
|
||||
# Ensure `nix print-dev-env --json` contains variable assignments.
|
||||
[[ $(jq -r .variables.arr1.value[2] $TEST_ROOT/dev-env.json) = '3 4' ]]
|
||||
|
||||
|
|
|
@ -17,6 +17,10 @@ fi
|
|||
|
||||
# Build the dependencies and push them to the remote store.
|
||||
nix-build -o $TEST_ROOT/result dependencies.nix --post-build-hook "$pushToStore"
|
||||
# See if all outputs are passed to the post-build hook by only specifying one
|
||||
# We're not able to test CA tests this way
|
||||
export BUILD_HOOK_ONLY_OUT_PATHS=$([ ! $NIX_TESTS_CA_BY_DEFAULT ])
|
||||
nix-build -o $TEST_ROOT/result-mult multiple-outputs.nix -A a.first --post-build-hook "$pushToStore"
|
||||
|
||||
clearStore
|
||||
|
||||
|
@ -24,3 +28,4 @@ clearStore
|
|||
# closure of what we've just built.
|
||||
nix copy --from "$REMOTE_STORE" --no-require-sigs -f dependencies.nix
|
||||
nix copy --from "$REMOTE_STORE" --no-require-sigs -f dependencies.nix input1_drv
|
||||
nix copy --from "$REMOTE_STORE" --no-require-sigs -f multiple-outputs.nix a^second
|
||||
|
|
|
@ -7,4 +7,8 @@ set -e
|
|||
[ -n "$DRV_PATH" ]
|
||||
|
||||
echo Pushing "$OUT_PATHS" to "$REMOTE_STORE"
|
||||
printf "%s" "$DRV_PATH" | xargs nix copy --to "$REMOTE_STORE" --no-require-sigs
|
||||
if [ -n "$BUILD_HOOK_ONLY_OUT_PATHS" ]; then
|
||||
printf "%s" "$OUT_PATHS" | xargs nix copy --to "$REMOTE_STORE" --no-require-sigs
|
||||
else
|
||||
printf "%s" "$DRV_PATH" | xargs nix copy --to "$REMOTE_STORE" --no-require-sigs
|
||||
fi
|
||||
|
|
|
@ -7,4 +7,8 @@ set -e
|
|||
[ -n "$DRV_PATH" ]
|
||||
|
||||
echo Pushing "$OUT_PATHS" to "$REMOTE_STORE"
|
||||
printf "%s" "$DRV_PATH"^'*' | xargs nix copy --to "$REMOTE_STORE" --no-require-sigs
|
||||
if [ -n "$BUILD_HOOK_ONLY_OUT_PATHS" ]; then
|
||||
printf "%s" "$OUT_PATHS" | xargs nix copy --to "$REMOTE_STORE" --no-require-sigs
|
||||
else
|
||||
printf "%s" "$DRV_PATH"^'*' | xargs nix copy --to "$REMOTE_STORE" --no-require-sigs
|
||||
fi
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
source common.sh
|
||||
|
||||
sed -i 's/experimental-features .*/& recursive-nix/' "$NIX_CONF_DIR"/nix.conf
|
||||
restartDaemon
|
||||
|
||||
# FIXME
|
||||
if [[ $(uname) != Linux ]]; then skipTest "Not running Linux"; fi
|
||||
|
||||
enableFeatures 'recursive-nix'
|
||||
restartDaemon
|
||||
|
||||
clearStore
|
||||
|
||||
rm -f $TEST_ROOT/result
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue