mirror of
https://github.com/NixOS/nix
synced 2025-06-25 06:31:14 +02:00
Merge remote-tracking branch 'origin/master' into relative-flakes
This commit is contained in:
commit
cd0127f957
112 changed files with 2268 additions and 434 deletions
|
@ -29,6 +29,47 @@ echo "$hash2"
|
|||
|
||||
test "$hash1" = "sha256:$hash2"
|
||||
|
||||
# The contents can be accessed through a symlink, and this symlink has no effect on the hash
|
||||
# https://github.com/NixOS/nix/issues/11941
|
||||
test_issue_11941() {
|
||||
local expected actual
|
||||
mkdir -p "$TEST_ROOT/foo/bar" && ln -s "$TEST_ROOT/foo" "$TEST_ROOT/foo-link"
|
||||
|
||||
# legacy
|
||||
expected=$(nix-store --add-fixed --recursive sha256 "$TEST_ROOT/foo/bar")
|
||||
actual=$(nix-store --add-fixed --recursive sha256 "$TEST_ROOT/foo-link/bar")
|
||||
[[ "$expected" == "$actual" ]]
|
||||
actual=$(nix-store --add "$TEST_ROOT/foo-link/bar")
|
||||
[[ "$expected" == "$actual" ]]
|
||||
|
||||
# nix store add
|
||||
actual=$(nix store add --hash-algo sha256 --mode nar "$TEST_ROOT/foo/bar")
|
||||
[[ "$expected" == "$actual" ]]
|
||||
|
||||
# cleanup
|
||||
rm -r "$TEST_ROOT/foo" "$TEST_ROOT/foo-link"
|
||||
}
|
||||
test_issue_11941
|
||||
|
||||
# A symlink is added to the store as a symlink, not as a copy of the target
|
||||
test_add_symlink() {
|
||||
ln -s /bin "$TEST_ROOT/my-bin"
|
||||
|
||||
# legacy
|
||||
path=$(nix-store --add-fixed --recursive sha256 "$TEST_ROOT/my-bin")
|
||||
[[ "$(readlink "$path")" == /bin ]]
|
||||
path=$(nix-store --add "$TEST_ROOT/my-bin")
|
||||
[[ "$(readlink "$path")" == /bin ]]
|
||||
|
||||
# nix store add
|
||||
path=$(nix store add --hash-algo sha256 --mode nar "$TEST_ROOT/my-bin")
|
||||
[[ "$(readlink "$path")" == /bin ]]
|
||||
|
||||
# cleanup
|
||||
rm "$TEST_ROOT/my-bin"
|
||||
}
|
||||
test_add_symlink
|
||||
|
||||
#### New style commands
|
||||
|
||||
clearStoreIfPossible
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
int = 123;
|
||||
str = "foo";
|
||||
str = "foo\nbar";
|
||||
attr.foo = "bar";
|
||||
}
|
||||
|
|
|
@ -16,8 +16,8 @@ EOF
|
|||
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 str -f "./eval.nix") == '"foo\nbar"' ]]
|
||||
[[ $(nix eval str --raw -f "./eval.nix") == $'foo\nbar' ]]
|
||||
[[ "$(nix eval attr -f "./eval.nix")" == '{ foo = "bar"; }' ]]
|
||||
[[ $(nix eval attr --json -f "./eval.nix") == '{"foo":"bar"}' ]]
|
||||
[[ $(nix eval int -f - < "./eval.nix") == 123 ]]
|
||||
|
@ -28,7 +28,8 @@ 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 str --eval "./eval.nix") == '"foo\nbar"' ]]
|
||||
[[ $(nix-instantiate -A str --raw --eval "./eval.nix") == $'foo\nbar' ]]
|
||||
[[ "$(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 ]]
|
||||
|
|
|
@ -63,3 +63,16 @@ flakeref=git+file://$rootRepo\?submodules=1\&dir=submodule
|
|||
echo '"foo"' > "$rootRepo"/submodule/sub.nix
|
||||
[[ $(nix eval --json "$flakeref#sub" ) = '"foo"' ]]
|
||||
[[ $(nix flake metadata --json "$flakeref" | jq -r .locked.rev) = null ]]
|
||||
|
||||
# Test that `nix flake metadata` parses `submodule` correctly.
|
||||
cat > "$rootRepo"/flake.nix <<EOF
|
||||
{
|
||||
outputs = { self }: {
|
||||
};
|
||||
}
|
||||
EOF
|
||||
git -C "$rootRepo" add flake.nix
|
||||
git -C "$rootRepo" commit -m "Add flake.nix"
|
||||
|
||||
storePath=$(nix flake metadata --json "$rootRepo?submodules=1" | jq -r .path)
|
||||
[[ -e "$storePath/submodule" ]]
|
||||
|
|
|
@ -92,3 +92,32 @@ try2 md5 "20f3ffe011d4cfa7d72bfabef7882836"
|
|||
rm "$TEST_ROOT/hash-path/hello"
|
||||
ln -s x "$TEST_ROOT/hash-path/hello"
|
||||
try2 md5 "f78b733a68f5edbdf9413899339eaa4a"
|
||||
|
||||
# Flat mode supports process substitution
|
||||
h=$(nix hash path --mode flat --type sha256 --base32 <(printf "SMASH THE STATE"))
|
||||
[[ 0d9n3r2i4m1zgy0wpqbsyabsfzgs952066bfp8gwvcg4mkr4r5g8 == "$h" ]]
|
||||
|
||||
# Flat mode supports process substitution (hash file)
|
||||
h=$(nix hash file --type sha256 --base32 <(printf "SMASH THE STATE"))
|
||||
[[ 0d9n3r2i4m1zgy0wpqbsyabsfzgs952066bfp8gwvcg4mkr4r5g8 == "$h" ]]
|
||||
|
||||
# Symlinks in the ancestry are ok and don't affect the result
|
||||
mkdir -p "$TEST_ROOT/simple" "$TEST_ROOT/try/to/mess/with/it"
|
||||
echo hi > "$TEST_ROOT/simple/hi"
|
||||
ln -s "$TEST_ROOT/simple" "$TEST_ROOT/try/to/mess/with/it/simple-link"
|
||||
h=$(nix hash path --type sha256 --base32 "$TEST_ROOT/simple/hi")
|
||||
[[ 1xmr8jicvzszfzpz46g37mlpvbzjl2wpwvl2b05psipssyp1sm8h == "$h" ]]
|
||||
h=$(nix hash path --type sha256 --base32 "$TEST_ROOT/try/to/mess/with/it/simple-link/hi")
|
||||
[[ 1xmr8jicvzszfzpz46g37mlpvbzjl2wpwvl2b05psipssyp1sm8h == "$h" ]]
|
||||
|
||||
# nix hash --mode nar does not canonicalize a symlink argument.
|
||||
# Otherwise it can't generate a NAR whose root is a symlink.
|
||||
# If you want to follow the symlink, pass $(realpath -s ...) instead.
|
||||
ln -s /non-existent-48cujwe8ndf4as0bne "$TEST_ROOT/symlink-to-nowhere"
|
||||
h=$(nix hash path --mode nar --type sha256 --base32 "$TEST_ROOT/symlink-to-nowhere")
|
||||
[[ 1bl5ry3x1fcbwgr5c2x50bn572iixh4j1p6ax5isxly2ddgn8pbp == "$h" ]] # manually verified hash
|
||||
if [[ -e /bin ]]; then
|
||||
ln -s /bin "$TEST_ROOT/symlink-to-bin"
|
||||
h=$(nix hash path --mode nar --type sha256 --base32 "$TEST_ROOT/symlink-to-bin")
|
||||
[[ 0z2mdmkd43l0ijdxfbj1y8vzli15yh9b09n3a3rrygmjshbyypsw == "$h" ]] # manually verified hash
|
||||
fi
|
||||
|
|
BIN
tests/functional/lang/eval-fail-string-nul-1.err.exp
Normal file
BIN
tests/functional/lang/eval-fail-string-nul-1.err.exp
Normal file
Binary file not shown.
BIN
tests/functional/lang/eval-fail-string-nul-1.nix
Normal file
BIN
tests/functional/lang/eval-fail-string-nul-1.nix
Normal file
Binary file not shown.
BIN
tests/functional/lang/eval-fail-string-nul-2.err.exp
Normal file
BIN
tests/functional/lang/eval-fail-string-nul-2.err.exp
Normal file
Binary file not shown.
BIN
tests/functional/lang/eval-fail-string-nul-2.nix
Normal file
BIN
tests/functional/lang/eval-fail-string-nul-2.nix
Normal file
Binary file not shown.
8
tests/functional/lang/eval-fail-toJSON-non-utf-8.err.exp
Normal file
8
tests/functional/lang/eval-fail-toJSON-non-utf-8.err.exp
Normal file
|
@ -0,0 +1,8 @@
|
|||
error:
|
||||
… while calling the 'toJSON' builtin
|
||||
at /pwd/lang/eval-fail-toJSON-non-utf-8.nix:1:1:
|
||||
1| builtins.toJSON "_invalid UTF-8: ÿ_"
|
||||
| ^
|
||||
2|
|
||||
|
||||
error: JSON serialization error: [json.exception.type_error.316] invalid UTF-8 byte at index 16: 0xFF
|
1
tests/functional/lang/eval-fail-toJSON-non-utf-8.nix
Normal file
1
tests/functional/lang/eval-fail-toJSON-non-utf-8.nix
Normal file
|
@ -0,0 +1 @@
|
|||
builtins.toJSON "_invalid UTF-8: ÿ_"
|
|
@ -4,8 +4,6 @@ project('nix-functional-tests',
|
|||
'cpp_std=c++2a',
|
||||
# TODO(Qyriad): increase the warning level
|
||||
'warning_level=1',
|
||||
'debug=true',
|
||||
'optimization=2',
|
||||
'errorlogs=true', # Please print logs for tests that fail
|
||||
],
|
||||
meson_version : '>= 1.3',
|
||||
|
|
|
@ -26,6 +26,8 @@ let
|
|||
|
||||
# Evaluate VMs faster
|
||||
documentation.enable = false;
|
||||
# this links against nix and might break with our git version.
|
||||
system.tools.nixos-option.enable = false;
|
||||
};
|
||||
_module.args.nixpkgs = nixpkgs;
|
||||
_module.args.system = system;
|
||||
|
@ -157,6 +159,8 @@ in
|
|||
|
||||
functional_root = runNixOSTestFor "x86_64-linux" ./functional/as-root.nix;
|
||||
|
||||
functional_symlinked-home = runNixOSTestFor "x86_64-linux" ./functional/symlinked-home.nix;
|
||||
|
||||
user-sandboxing = runNixOSTestFor "x86_64-linux" ./user-sandboxing;
|
||||
|
||||
s3-binary-cache-store = runNixOSTestFor "x86_64-linux" ./s3-binary-cache-store.nix;
|
||||
|
|
36
tests/nixos/functional/symlinked-home.nix
Normal file
36
tests/nixos/functional/symlinked-home.nix
Normal file
|
@ -0,0 +1,36 @@
|
|||
/**
|
||||
This test runs the functional tests on a NixOS system where the home directory
|
||||
is symlinked to another location.
|
||||
|
||||
The purpose of this test is to find cases where Nix uses low-level operations
|
||||
that don't support symlinks on paths that include them.
|
||||
|
||||
It is not a substitute for more intricate, use case-specific tests, but helps
|
||||
catch common issues.
|
||||
*/
|
||||
# TODO: add symlinked tmpdir
|
||||
{ ... }:
|
||||
{
|
||||
name = "functional-tests-on-nixos_user_symlinked-home";
|
||||
|
||||
imports = [ ./common.nix ];
|
||||
|
||||
nodes.machine = {
|
||||
users.users.alice = { isNormalUser = true; };
|
||||
};
|
||||
|
||||
testScript = ''
|
||||
machine.wait_for_unit("multi-user.target")
|
||||
with subtest("prepare symlinked home"):
|
||||
machine.succeed("""
|
||||
(
|
||||
set -x
|
||||
mv /home/alice /home/alice.real
|
||||
ln -s alice.real /home/alice
|
||||
) 1>&2
|
||||
""")
|
||||
machine.succeed("""
|
||||
su --login --command "run-test-suite" alice >&2
|
||||
""")
|
||||
'';
|
||||
}
|
|
@ -10,6 +10,7 @@ let
|
|||
env = "AWS_ACCESS_KEY_ID=${accessKey} AWS_SECRET_ACCESS_KEY=${secretKey}";
|
||||
|
||||
storeUrl = "s3://my-cache?endpoint=http://server:9000®ion=eu-west-1";
|
||||
objectThatDoesNotExist = "s3://my-cache/foo-that-does-not-exist?endpoint=http://server:9000®ion=eu-west-1";
|
||||
|
||||
in {
|
||||
name = "s3-binary-cache-store";
|
||||
|
@ -20,7 +21,10 @@ in {
|
|||
{ virtualisation.writableStore = true;
|
||||
virtualisation.additionalPaths = [ pkgA ];
|
||||
environment.systemPackages = [ pkgs.minio-client ];
|
||||
nix.extraOptions = "experimental-features = nix-command";
|
||||
nix.extraOptions = ''
|
||||
experimental-features = nix-command
|
||||
substituters =
|
||||
'';
|
||||
services.minio = {
|
||||
enable = true;
|
||||
region = "eu-west-1";
|
||||
|
@ -35,7 +39,10 @@ in {
|
|||
client =
|
||||
{ config, pkgs, ... }:
|
||||
{ virtualisation.writableStore = true;
|
||||
nix.extraOptions = "experimental-features = nix-command";
|
||||
nix.extraOptions = ''
|
||||
experimental-features = nix-command
|
||||
substituters =
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -54,6 +61,12 @@ in {
|
|||
# Test fetchurl on s3:// URLs while we're at it.
|
||||
client.succeed("${env} nix eval --impure --expr 'builtins.fetchurl { name = \"foo\"; url = \"s3://my-cache/nix-cache-info?endpoint=http://server:9000®ion=eu-west-1\"; }'")
|
||||
|
||||
# Test that the format string in the error message is properly setup and won't display `%s` instead of the failed URI
|
||||
msg = client.fail("${env} nix eval --impure --expr 'builtins.fetchurl { name = \"foo\"; url = \"${objectThatDoesNotExist}\"; }' 2>&1")
|
||||
if "S3 object '${objectThatDoesNotExist}' does not exist" not in msg:
|
||||
print(msg) # So that you can see the message that was improperly formatted
|
||||
raise Exception("Error message formatting didn't work")
|
||||
|
||||
# Copy a package from the binary cache.
|
||||
client.fail("nix path-info ${pkgA}")
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue