mirror of
https://github.com/NixOS/nix
synced 2025-07-07 10:11:47 +02:00
Merge branch 'master' into nixenvjsondrvpath
This commit is contained in:
commit
87ac33f29a
293 changed files with 7443 additions and 3977 deletions
|
@ -26,3 +26,20 @@ hash2=$(nix-hash --type sha256 --base32 ./dummy)
|
|||
echo $hash2
|
||||
|
||||
test "$hash1" = "sha256:$hash2"
|
||||
|
||||
#### New style commands
|
||||
|
||||
clearStore
|
||||
|
||||
(
|
||||
path1=$(nix store add ./dummy)
|
||||
path2=$(nix store add --mode nar ./dummy)
|
||||
path3=$(nix store add-path ./dummy)
|
||||
[[ "$path1" == "$path2" ]]
|
||||
[[ "$path1" == "$path3" ]]
|
||||
)
|
||||
(
|
||||
path1=$(nix store add --mode flat ./dummy)
|
||||
path2=$(nix store add-file ./dummy)
|
||||
[[ "$path1" == "$path2" ]]
|
||||
)
|
||||
|
|
|
@ -4,7 +4,7 @@ if [[ -z "${COMMON_VARS_AND_FUNCTIONS_SH_SOURCED-}" ]]; then
|
|||
|
||||
COMMON_VARS_AND_FUNCTIONS_SH_SOURCED=1
|
||||
|
||||
export PS4='+(${BASH_SOURCE[0]-$0}:$LINENO) '
|
||||
set +x
|
||||
|
||||
export TEST_ROOT=$(realpath ${TMPDIR:-/tmp}/nix-test)/${TEST_NAME:-default/tests\/functional//}
|
||||
export NIX_STORE_DIR
|
||||
|
|
|
@ -44,15 +44,18 @@ EOF
|
|||
# Input override completion
|
||||
[[ "$(NIX_GET_COMPLETIONS=4 nix build ./foo --override-input '')" == $'normal\na\t' ]]
|
||||
[[ "$(NIX_GET_COMPLETIONS=5 nix flake show ./foo --override-input '')" == $'normal\na\t' ]]
|
||||
cd ./foo
|
||||
[[ "$(NIX_GET_COMPLETIONS=3 nix flake update '')" == $'normal\na\t' ]]
|
||||
cd ..
|
||||
[[ "$(NIX_GET_COMPLETIONS=5 nix flake update --flake './foo' '')" == $'normal\na\t' ]]
|
||||
## With multiple input flakes
|
||||
[[ "$(NIX_GET_COMPLETIONS=5 nix build ./foo ./bar --override-input '')" == $'normal\na\t\nb\t' ]]
|
||||
## With tilde expansion
|
||||
[[ "$(HOME=$PWD NIX_GET_COMPLETIONS=4 nix build '~/foo' --override-input '')" == $'normal\na\t' ]]
|
||||
[[ "$(HOME=$PWD NIX_GET_COMPLETIONS=5 nix flake show '~/foo' --update-input '')" == $'normal\na\t' ]]
|
||||
[[ "$(HOME=$PWD NIX_GET_COMPLETIONS=4 nix run '~/foo' --update-input '')" == $'normal\na\t' ]]
|
||||
[[ "$(HOME=$PWD NIX_GET_COMPLETIONS=5 nix flake update --flake '~/foo' '')" == $'normal\na\t' ]]
|
||||
## Out of order
|
||||
[[ "$(NIX_GET_COMPLETIONS=3 nix build --update-input '' ./foo)" == $'normal\na\t' ]]
|
||||
[[ "$(NIX_GET_COMPLETIONS=4 nix build ./foo --update-input '' ./bar)" == $'normal\na\t\nb\t' ]]
|
||||
[[ "$(NIX_GET_COMPLETIONS=3 nix build --override-input '' '' ./foo)" == $'normal\na\t' ]]
|
||||
[[ "$(NIX_GET_COMPLETIONS=4 nix build ./foo --override-input '' '' ./bar)" == $'normal\na\t\nb\t' ]]
|
||||
|
||||
# Cli flag completion
|
||||
NIX_GET_COMPLETIONS=2 nix build --log-form | grep -- "--log-format"
|
||||
|
|
|
@ -50,7 +50,8 @@ exp_cores=$(nix show-config | grep '^cores' | cut -d '=' -f 2 | xargs)
|
|||
exp_features=$(nix show-config | grep '^experimental-features' | cut -d '=' -f 2 | xargs)
|
||||
[[ $prev != $exp_cores ]]
|
||||
[[ $exp_cores == "4242" ]]
|
||||
[[ $exp_features == "flakes nix-command" ]]
|
||||
# flakes implies fetch-tree
|
||||
[[ $exp_features == "fetch-tree flakes nix-command" ]]
|
||||
|
||||
# Test that it's possible to retrieve a single setting's value
|
||||
val=$(nix show-config | grep '^warn-dirty' | cut -d '=' -f 2 | xargs)
|
||||
|
|
76
tests/functional/fetchGitVerification.sh
Normal file
76
tests/functional/fetchGitVerification.sh
Normal file
|
@ -0,0 +1,76 @@
|
|||
source common.sh
|
||||
|
||||
requireGit
|
||||
[[ $(type -p ssh-keygen) ]] || skipTest "ssh-keygen not installed" # require ssh-keygen
|
||||
|
||||
enableFeatures "verified-fetches"
|
||||
|
||||
clearStore
|
||||
|
||||
repo="$TEST_ROOT/git"
|
||||
|
||||
# generate signing keys
|
||||
keysDir=$TEST_ROOT/.ssh
|
||||
mkdir -p "$keysDir"
|
||||
ssh-keygen -f "$keysDir/testkey1" -t ed25519 -P "" -C "test key 1"
|
||||
key1File="$keysDir/testkey1.pub"
|
||||
publicKey1=$(awk '{print $2}' "$key1File")
|
||||
ssh-keygen -f "$keysDir/testkey2" -t rsa -P "" -C "test key 2"
|
||||
key2File="$keysDir/testkey2.pub"
|
||||
publicKey2=$(awk '{print $2}' "$key2File")
|
||||
|
||||
git init $repo
|
||||
git -C $repo config user.email "foobar@example.com"
|
||||
git -C $repo config user.name "Foobar"
|
||||
git -C $repo config gpg.format ssh
|
||||
|
||||
echo 'hello' > $repo/text
|
||||
git -C $repo add text
|
||||
git -C $repo -c "user.signingkey=$key1File" commit -S -m 'initial commit'
|
||||
|
||||
out=$(nix eval --impure --raw --expr "builtins.fetchGit { url = \"file://$repo\"; keytype = \"ssh-rsa\"; publicKey = \"$publicKey2\"; }" 2>&1) || status=$?
|
||||
[[ $status == 1 ]]
|
||||
[[ $out =~ 'No principal matched.' ]]
|
||||
[[ $(nix eval --impure --raw --expr "builtins.readFile (builtins.fetchGit { url = \"file://$repo\"; publicKey = \"$publicKey1\"; } + \"/text\")") = 'hello' ]]
|
||||
|
||||
echo 'hello world' > $repo/text
|
||||
git -C $repo add text
|
||||
git -C $repo -c "user.signingkey=$key2File" commit -S -m 'second commit'
|
||||
|
||||
[[ $(nix eval --impure --raw --expr "builtins.readFile (builtins.fetchGit { url = \"file://$repo\"; publicKeys = [{key = \"$publicKey1\";} {type = \"ssh-rsa\"; key = \"$publicKey2\";}]; } + \"/text\")") = 'hello world' ]]
|
||||
|
||||
# Flake input test
|
||||
flakeDir="$TEST_ROOT/flake"
|
||||
mkdir -p "$flakeDir"
|
||||
cat > "$flakeDir/flake.nix" <<EOF
|
||||
{
|
||||
inputs.test = {
|
||||
type = "git";
|
||||
url = "file://$repo";
|
||||
flake = false;
|
||||
publicKeys = [
|
||||
{ type = "ssh-rsa"; key = "$publicKey2"; }
|
||||
];
|
||||
};
|
||||
|
||||
outputs = { test, ... }: { test = test.outPath; };
|
||||
}
|
||||
EOF
|
||||
nix build --out-link "$flakeDir/result" "$flakeDir#test"
|
||||
[[ $(cat "$flakeDir/result/text") = 'hello world' ]]
|
||||
|
||||
cat > "$flakeDir/flake.nix" <<EOF
|
||||
{
|
||||
inputs.test = {
|
||||
type = "git";
|
||||
url = "file://$repo";
|
||||
flake = false;
|
||||
publicKey= "$publicKey1";
|
||||
};
|
||||
|
||||
outputs = { test, ... }: { test = test.outPath; };
|
||||
}
|
||||
EOF
|
||||
out=$(nix build "$flakeDir#test" 2>&1) || status=$?
|
||||
[[ $status == 1 ]]
|
||||
[[ $out =~ 'No principal matched.' ]]
|
|
@ -42,7 +42,8 @@ git -C $flakeB commit -a -m 'Foo'
|
|||
sed -i $flakeB/flake.nix -e 's/456/789/'
|
||||
git -C $flakeB commit -a -m 'Foo'
|
||||
|
||||
[[ $(nix eval --update-input b $flakeA#foo) = 1912 ]]
|
||||
nix flake update b --flake $flakeA
|
||||
[[ $(nix eval $flakeA#foo) = 1912 ]]
|
||||
|
||||
# Test list-inputs with circular dependencies
|
||||
nix flake metadata $flakeA
|
||||
|
|
|
@ -11,6 +11,7 @@ writeSimpleFlake() {
|
|||
outputs = inputs: rec {
|
||||
packages.$system = rec {
|
||||
foo = import ./simple.nix;
|
||||
fooScript = (import ./shell.nix {}).foo;
|
||||
default = foo;
|
||||
};
|
||||
packages.someOtherSystem = rec {
|
||||
|
@ -24,13 +25,13 @@ writeSimpleFlake() {
|
|||
}
|
||||
EOF
|
||||
|
||||
cp ../simple.nix ../simple.builder.sh ../config.nix $flakeDir/
|
||||
cp ../simple.nix ../shell.nix ../simple.builder.sh ../config.nix $flakeDir/
|
||||
}
|
||||
|
||||
createSimpleGitFlake() {
|
||||
local flakeDir="$1"
|
||||
writeSimpleFlake $flakeDir
|
||||
git -C $flakeDir add flake.nix simple.nix simple.builder.sh config.nix
|
||||
git -C $flakeDir add flake.nix simple.nix shell.nix simple.builder.sh config.nix
|
||||
git -C $flakeDir commit -m 'Initial'
|
||||
}
|
||||
|
||||
|
|
|
@ -66,9 +66,82 @@ cat > "$nonFlakeDir/README.md" <<EOF
|
|||
FNORD
|
||||
EOF
|
||||
|
||||
git -C "$nonFlakeDir" add README.md
|
||||
cat > "$nonFlakeDir/shebang.sh" <<EOF
|
||||
#! $(type -P env) nix
|
||||
#! nix --offline shell
|
||||
#! nix flake1#fooScript
|
||||
#! nix --no-write-lock-file --command bash
|
||||
set -ex
|
||||
foo
|
||||
echo "\$@"
|
||||
EOF
|
||||
chmod +x "$nonFlakeDir/shebang.sh"
|
||||
|
||||
git -C "$nonFlakeDir" add README.md shebang.sh
|
||||
git -C "$nonFlakeDir" commit -m 'Initial'
|
||||
|
||||
# this also tests a fairly trivial double backtick quoted string, ``--command``
|
||||
cat > $nonFlakeDir/shebang-comments.sh <<EOF
|
||||
#! $(type -P env) nix
|
||||
# some comments
|
||||
# some comments
|
||||
# some comments
|
||||
#! nix --offline shell
|
||||
#! nix flake1#fooScript
|
||||
#! nix --no-write-lock-file ``--command`` bash
|
||||
foo
|
||||
EOF
|
||||
chmod +x $nonFlakeDir/shebang-comments.sh
|
||||
|
||||
cat > $nonFlakeDir/shebang-reject.sh <<EOF
|
||||
#! $(type -P env) nix
|
||||
# some comments
|
||||
# some comments
|
||||
# some comments
|
||||
#! nix --offline shell *
|
||||
#! nix flake1#fooScript
|
||||
#! nix --no-write-lock-file --command bash
|
||||
foo
|
||||
EOF
|
||||
chmod +x $nonFlakeDir/shebang-reject.sh
|
||||
|
||||
cat > $nonFlakeDir/shebang-inline-expr.sh <<EOF
|
||||
#! $(type -P env) nix
|
||||
EOF
|
||||
cat >> $nonFlakeDir/shebang-inline-expr.sh <<"EOF"
|
||||
#! nix --offline shell
|
||||
#! nix --impure --expr ``
|
||||
#! nix let flake = (builtins.getFlake (toString ../flake1)).packages;
|
||||
#! nix fooScript = flake.${builtins.currentSystem}.fooScript;
|
||||
#! nix /* just a comment !@#$%^&*()__+ # */
|
||||
#! nix in fooScript
|
||||
#! nix ``
|
||||
#! nix --no-write-lock-file --command bash
|
||||
set -ex
|
||||
foo
|
||||
echo "$@"
|
||||
EOF
|
||||
chmod +x $nonFlakeDir/shebang-inline-expr.sh
|
||||
|
||||
cat > $nonFlakeDir/fooScript.nix <<"EOF"
|
||||
let flake = (builtins.getFlake (toString ../flake1)).packages;
|
||||
fooScript = flake.${builtins.currentSystem}.fooScript;
|
||||
in fooScript
|
||||
EOF
|
||||
|
||||
cat > $nonFlakeDir/shebang-file.sh <<EOF
|
||||
#! $(type -P env) nix
|
||||
EOF
|
||||
cat >> $nonFlakeDir/shebang-file.sh <<"EOF"
|
||||
#! nix --offline shell
|
||||
#! nix --impure --file ./fooScript.nix
|
||||
#! nix --no-write-lock-file --command bash
|
||||
set -ex
|
||||
foo
|
||||
echo "$@"
|
||||
EOF
|
||||
chmod +x $nonFlakeDir/shebang-file.sh
|
||||
|
||||
# Construct a custom registry, additionally test the --registry flag
|
||||
nix registry add --registry "$registry" flake1 "git+file://$flake1Dir"
|
||||
nix registry add --registry "$registry" flake2 "git+file://$percentEncodedFlake2Dir"
|
||||
|
@ -300,7 +373,7 @@ nix build -o "$TEST_ROOT/result" flake4#xyzzy
|
|||
nix flake lock "$flake3Dir"
|
||||
[[ -z $(git -C "$flake3Dir" diff master || echo failed) ]]
|
||||
|
||||
nix flake update "$flake3Dir" --override-flake flake2 nixpkgs
|
||||
nix flake update --flake "$flake3Dir" --override-flake flake2 nixpkgs
|
||||
[[ ! -z $(git -C "$flake3Dir" diff master || echo failed) ]]
|
||||
|
||||
# Make branch "removeXyzzy" where flake3 doesn't have xyzzy anymore
|
||||
|
@ -437,7 +510,7 @@ cat > "$flake3Dir/flake.nix" <<EOF
|
|||
}
|
||||
EOF
|
||||
|
||||
nix flake update "$flake3Dir"
|
||||
nix flake update --flake "$flake3Dir"
|
||||
[[ $(jq -c .nodes.flake2.inputs.flake1 "$flake3Dir/flake.lock") =~ '["foo"]' ]]
|
||||
[[ $(jq .nodes.foo.locked.url "$flake3Dir/flake.lock") =~ flake7 ]]
|
||||
|
||||
|
@ -480,7 +553,7 @@ nix flake lock "$flake3Dir" --override-input flake2/flake1 flake1/master/$hash1
|
|||
nix flake lock "$flake3Dir"
|
||||
[[ $(jq -r .nodes.flake1_2.locked.rev "$flake3Dir/flake.lock") = $hash1 ]]
|
||||
|
||||
nix flake lock "$flake3Dir" --update-input flake2/flake1
|
||||
nix flake update flake2/flake1 --flake "$flake3Dir"
|
||||
[[ $(jq -r .nodes.flake1_2.locked.rev "$flake3Dir/flake.lock") =~ $hash2 ]]
|
||||
|
||||
# Test 'nix flake metadata --json'.
|
||||
|
@ -511,3 +584,11 @@ nix flake metadata "$flake2Dir" --reference-lock-file $TEST_ROOT/flake2-overridd
|
|||
|
||||
# reference-lock-file can only be used if allow-dirty is set.
|
||||
expectStderr 1 nix flake metadata "$flake2Dir" --no-allow-dirty --reference-lock-file $TEST_ROOT/flake2-overridden.lock
|
||||
|
||||
# Test shebang
|
||||
[[ $($nonFlakeDir/shebang.sh) = "foo" ]]
|
||||
[[ $($nonFlakeDir/shebang.sh "bar") = "foo"$'\n'"bar" ]]
|
||||
[[ $($nonFlakeDir/shebang-comments.sh ) = "foo" ]]
|
||||
[[ $($nonFlakeDir/shebang-inline-expr.sh baz) = "foo"$'\n'"baz" ]]
|
||||
[[ $($nonFlakeDir/shebang-file.sh baz) = "foo"$'\n'"baz" ]]
|
||||
expect 1 $nonFlakeDir/shebang-reject.sh 2>&1 | grepQuiet -F 'error: unsupported unquoted character in nix shebang: *. Use double backticks to escape?'
|
||||
|
|
|
@ -77,7 +77,7 @@ git -C $flakeFollowsA add flake.nix flakeB/flake.nix \
|
|||
|
||||
nix flake metadata $flakeFollowsA
|
||||
|
||||
nix flake update $flakeFollowsA
|
||||
nix flake update --flake $flakeFollowsA
|
||||
|
||||
nix flake lock $flakeFollowsA
|
||||
|
||||
|
@ -228,7 +228,7 @@ git -C "$flakeFollowsOverloadA" add flake.nix flakeB/flake.nix \
|
|||
flakeB/flakeC/flake.nix flakeB/flakeC/flakeD/flake.nix
|
||||
|
||||
nix flake metadata "$flakeFollowsOverloadA"
|
||||
nix flake update "$flakeFollowsOverloadA"
|
||||
nix flake update --flake "$flakeFollowsOverloadA"
|
||||
nix flake lock "$flakeFollowsOverloadA"
|
||||
|
||||
# Now test follow cycle detection
|
||||
|
|
|
@ -23,6 +23,7 @@ nix-instantiate --trace-verbose --eval -E 'builtins.traceVerbose "Hello" 123' 2>
|
|||
nix-instantiate --eval -E 'builtins.traceVerbose "Hello" 123' 2>&1 | grepQuietInverse Hello
|
||||
nix-instantiate --show-trace --eval -E 'builtins.addErrorContext "Hello" 123' 2>&1 | grepQuietInverse Hello
|
||||
expectStderr 1 nix-instantiate --show-trace --eval -E 'builtins.addErrorContext "Hello" (throw "Foo")' | grepQuiet Hello
|
||||
expectStderr 1 nix-instantiate --show-trace --eval -E 'builtins.addErrorContext "Hello %" (throw "Foo")' | grepQuiet 'Hello %'
|
||||
|
||||
nix-instantiate --eval -E 'let x = builtins.trace { x = x; } true; in x' \
|
||||
2>&1 | grepQuiet -E 'trace: { x = «potential infinite recursion»; }'
|
||||
|
|
|
@ -1 +1 @@
|
|||
error: getting status of '/pwd/lang/fnord': No such file or directory
|
||||
error: path '/pwd/lang/fnord' does not exist
|
||||
|
|
|
@ -1 +1 @@
|
|||
error: getting status of '/pwd/lang/fnord': No such file or directory
|
||||
error: path '/pwd/lang/fnord' does not exist
|
||||
|
|
1
tests/functional/lang/eval-okay-symlink-resolution.exp
Normal file
1
tests/functional/lang/eval-okay-symlink-resolution.exp
Normal file
|
@ -0,0 +1 @@
|
|||
"test"
|
1
tests/functional/lang/eval-okay-symlink-resolution.nix
Normal file
1
tests/functional/lang/eval-okay-symlink-resolution.nix
Normal file
|
@ -0,0 +1 @@
|
|||
import symlink-resolution/foo/overlays/overlay.nix
|
|
@ -0,0 +1 @@
|
|||
"test"
|
1
tests/functional/lang/symlink-resolution/foo/overlays
Symbolic link
1
tests/functional/lang/symlink-resolution/foo/overlays
Symbolic link
|
@ -0,0 +1 @@
|
|||
../overlays
|
|
@ -0,0 +1 @@
|
|||
import ../lib
|
|
@ -55,6 +55,7 @@ nix_tests = \
|
|||
secure-drv-outputs.sh \
|
||||
restricted.sh \
|
||||
fetchGitSubmodules.sh \
|
||||
fetchGitVerification.sh \
|
||||
flakes/search-root.sh \
|
||||
readfile-context.sh \
|
||||
nix-channel.sh \
|
||||
|
@ -119,6 +120,7 @@ nix_tests = \
|
|||
flakes/show.sh \
|
||||
impure-derivations.sh \
|
||||
path-from-hash-part.sh \
|
||||
path-info.sh \
|
||||
toString-path.sh \
|
||||
read-only-store.sh \
|
||||
nested-sandboxing.sh \
|
||||
|
|
|
@ -25,6 +25,11 @@ diff -u baz.cat-nar $storePath/foo/baz
|
|||
nix store cat $storePath/foo/baz > baz.cat-nar
|
||||
diff -u baz.cat-nar $storePath/foo/baz
|
||||
|
||||
# Check that 'nix store cat' fails on invalid store paths.
|
||||
invalidPath="$(dirname $storePath)/99999999999999999999999999999999-foo"
|
||||
cp -r $storePath $invalidPath
|
||||
expect 1 nix store cat $invalidPath/foo/baz
|
||||
|
||||
# Test --json.
|
||||
diff -u \
|
||||
<(nix nar ls --json $narFile / | jq -S) \
|
||||
|
@ -46,7 +51,7 @@ diff -u \
|
|||
<(echo '{"type":"regular","size":0}' | jq -S)
|
||||
|
||||
# Test missing files.
|
||||
expect 1 nix store ls --json -R $storePath/xyzzy 2>&1 | grep 'does not exist in NAR'
|
||||
expect 1 nix store ls --json -R $storePath/xyzzy 2>&1 | grep 'does not exist'
|
||||
expect 1 nix store ls $storePath/xyzzy 2>&1 | grep 'does not exist'
|
||||
|
||||
# Test failure to dump.
|
||||
|
|
23
tests/functional/path-info.sh
Normal file
23
tests/functional/path-info.sh
Normal file
|
@ -0,0 +1,23 @@
|
|||
source common.sh
|
||||
|
||||
echo foo > $TEST_ROOT/foo
|
||||
foo=$(nix store add-file $TEST_ROOT/foo)
|
||||
|
||||
echo bar > $TEST_ROOT/bar
|
||||
bar=$(nix store add-file $TEST_ROOT/bar)
|
||||
|
||||
echo baz > $TEST_ROOT/baz
|
||||
baz=$(nix store add-file $TEST_ROOT/baz)
|
||||
nix-store --delete "$baz"
|
||||
|
||||
diff --unified --color=always \
|
||||
<(nix path-info --json "$foo" "$bar" "$baz" |
|
||||
jq --sort-keys 'map_values(.narHash)') \
|
||||
<(jq --sort-keys <<-EOF
|
||||
{
|
||||
"$foo": "sha256-QvtAMbUl/uvi+LCObmqOhvNOapHdA2raiI4xG5zI5pA=",
|
||||
"$bar": "sha256-9fhYGu9fqxcQC2Kc81qh2RMo1QcLBUBo8U+pPn+jthQ=",
|
||||
"$baz": null
|
||||
}
|
||||
EOF
|
||||
)
|
|
@ -18,7 +18,7 @@ test_tarball() {
|
|||
local compressor="$2"
|
||||
|
||||
tarball=$TEST_ROOT/tarball.tar$ext
|
||||
(cd $TEST_ROOT && tar cf - tarball) | $compressor > $tarball
|
||||
(cd $TEST_ROOT && GNUTAR_REPRODUCIBLE= tar --mtime=$tarroot/default.nix --owner=0 --group=0 --numeric-owner --sort=name -c -f - tarball) | $compressor > $tarball
|
||||
|
||||
nix-env -f file://$tarball -qa --out-path | grepQuiet dependencies
|
||||
|
||||
|
|
|
@ -21,6 +21,8 @@ in
|
|||
|
||||
remoteBuilds = runNixOSTestFor "x86_64-linux" ./remote-builds.nix;
|
||||
|
||||
remoteBuildsSshNg = runNixOSTestFor "x86_64-linux" ./remote-builds-ssh-ng.nix;
|
||||
|
||||
nix-copy-closure = runNixOSTestFor "x86_64-linux" ./nix-copy-closure.nix;
|
||||
|
||||
nix-copy = runNixOSTestFor "x86_64-linux" ./nix-copy.nix;
|
||||
|
|
108
tests/nixos/remote-builds-ssh-ng.nix
Normal file
108
tests/nixos/remote-builds-ssh-ng.nix
Normal file
|
@ -0,0 +1,108 @@
|
|||
{ config, lib, hostPkgs, ... }:
|
||||
|
||||
let
|
||||
pkgs = config.nodes.client.nixpkgs.pkgs;
|
||||
|
||||
# Trivial Nix expression to build remotely.
|
||||
expr = config: nr: pkgs.writeText "expr.nix"
|
||||
''
|
||||
let utils = builtins.storePath ${config.system.build.extraUtils}; in
|
||||
derivation {
|
||||
name = "hello-${toString nr}";
|
||||
system = "i686-linux";
|
||||
PATH = "''${utils}/bin";
|
||||
builder = "''${utils}/bin/sh";
|
||||
args = [ "-c" "${
|
||||
lib.concatStringsSep "; " [
|
||||
''if [[ -n $NIX_LOG_FD ]]''
|
||||
''then echo '@nix {\"action\":\"setPhase\",\"phase\":\"buildPhase\"}' >&''$NIX_LOG_FD''
|
||||
"fi"
|
||||
"echo Hello"
|
||||
"mkdir $out"
|
||||
"cat /proc/sys/kernel/hostname > $out/host"
|
||||
]
|
||||
}" ];
|
||||
outputs = [ "out" ];
|
||||
}
|
||||
'';
|
||||
in
|
||||
|
||||
{
|
||||
name = "remote-builds-ssh-ng";
|
||||
|
||||
nodes =
|
||||
{ builder =
|
||||
{ config, pkgs, ... }:
|
||||
{ services.openssh.enable = true;
|
||||
virtualisation.writableStore = true;
|
||||
nix.settings.sandbox = true;
|
||||
nix.settings.substituters = lib.mkForce [ ];
|
||||
};
|
||||
|
||||
client =
|
||||
{ config, lib, pkgs, ... }:
|
||||
{ nix.settings.max-jobs = 0; # force remote building
|
||||
nix.distributedBuilds = true;
|
||||
nix.buildMachines =
|
||||
[ { hostName = "builder";
|
||||
sshUser = "root";
|
||||
sshKey = "/root/.ssh/id_ed25519";
|
||||
system = "i686-linux";
|
||||
maxJobs = 1;
|
||||
protocol = "ssh-ng";
|
||||
}
|
||||
];
|
||||
virtualisation.writableStore = true;
|
||||
virtualisation.additionalPaths = [ config.system.build.extraUtils ];
|
||||
nix.settings.substituters = lib.mkForce [ ];
|
||||
programs.ssh.extraConfig = "ConnectTimeout 30";
|
||||
};
|
||||
};
|
||||
|
||||
testScript = { nodes }: ''
|
||||
# fmt: off
|
||||
import subprocess
|
||||
|
||||
start_all()
|
||||
|
||||
# Create an SSH key on the client.
|
||||
subprocess.run([
|
||||
"${hostPkgs.openssh}/bin/ssh-keygen", "-t", "ed25519", "-f", "key", "-N", ""
|
||||
], capture_output=True, check=True)
|
||||
client.succeed("mkdir -p -m 700 /root/.ssh")
|
||||
client.copy_from_host("key", "/root/.ssh/id_ed25519")
|
||||
client.succeed("chmod 600 /root/.ssh/id_ed25519")
|
||||
|
||||
# Install the SSH key on the builder.
|
||||
client.wait_for_unit("network.target")
|
||||
builder.succeed("mkdir -p -m 700 /root/.ssh")
|
||||
builder.copy_from_host("key.pub", "/root/.ssh/authorized_keys")
|
||||
builder.wait_for_unit("sshd")
|
||||
client.succeed(f"ssh -o StrictHostKeyChecking=no {builder.name} 'echo hello world'")
|
||||
|
||||
# Perform a build
|
||||
out = client.succeed("nix-build ${expr nodes.client.config 1} 2> build-output")
|
||||
|
||||
# Verify that the build was done on the builder
|
||||
builder.succeed(f"test -e {out.strip()}")
|
||||
|
||||
# Print the build log, prefix the log lines to avoid nix intercepting lines starting with @nix
|
||||
buildOutput = client.succeed("sed -e 's/^/build-output:/' build-output")
|
||||
print(buildOutput)
|
||||
|
||||
# Make sure that we get the expected build output
|
||||
client.succeed("grep -qF Hello build-output")
|
||||
|
||||
# We don't want phase reporting in the build output
|
||||
client.fail("grep -qF '@nix' build-output")
|
||||
|
||||
# Get the log file
|
||||
client.succeed(f"nix-store --read-log {out.strip()} > log-output")
|
||||
# Prefix the log lines to avoid nix intercepting lines starting with @nix
|
||||
logOutput = client.succeed("sed -e 's/^/log-file:/' log-output")
|
||||
print(logOutput)
|
||||
|
||||
# Check that we get phase reporting in the log file
|
||||
client.succeed("grep -q '@nix {\"action\":\"setPhase\",\"phase\":\"buildPhase\"}' log-output")
|
||||
'';
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue