mirror of
https://github.com/NixOS/nix.git
synced 2025-11-08 19:46:02 +01:00
shellcheck fix: tests/functional/nix-profile.sh
This commit is contained in:
parent
cf206ef61e
commit
78833ca8d0
2 changed files with 76 additions and 70 deletions
|
|
@ -106,7 +106,6 @@
|
||||||
enable = true;
|
enable = true;
|
||||||
excludes = [
|
excludes = [
|
||||||
# We haven't linted these files yet
|
# We haven't linted these files yet
|
||||||
''^tests/functional/nix-profile\.sh$''
|
|
||||||
''^tests/functional/nix-shell\.sh$''
|
''^tests/functional/nix-shell\.sh$''
|
||||||
''^tests/functional/nix_path\.sh$''
|
''^tests/functional/nix_path\.sh$''
|
||||||
''^tests/functional/optimise-store\.sh$''
|
''^tests/functional/optimise-store\.sh$''
|
||||||
|
|
|
||||||
|
|
@ -12,9 +12,10 @@ restartDaemon
|
||||||
|
|
||||||
# Make a flake.
|
# Make a flake.
|
||||||
flake1Dir=$TEST_ROOT/flake1
|
flake1Dir=$TEST_ROOT/flake1
|
||||||
mkdir -p $flake1Dir
|
mkdir -p "$flake1Dir"
|
||||||
|
|
||||||
cat > $flake1Dir/flake.nix <<EOF
|
# shellcheck disable=SC2154,SC1039
|
||||||
|
cat > "$flake1Dir"/flake.nix <<EOF
|
||||||
{
|
{
|
||||||
description = "Bla bla";
|
description = "Bla bla";
|
||||||
|
|
||||||
|
|
@ -43,20 +44,21 @@ cat > $flake1Dir/flake.nix <<EOF
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
printf World > $flake1Dir/who
|
printf World > "$flake1Dir"/who
|
||||||
printf 1.0 > $flake1Dir/version
|
printf 1.0 > "$flake1Dir"/version
|
||||||
printf false > $flake1Dir/ca.nix
|
printf false > "$flake1Dir"/ca.nix
|
||||||
|
|
||||||
cp "${config_nix}" $flake1Dir/
|
cp "${config_nix}" "$flake1Dir"/
|
||||||
|
|
||||||
# Test upgrading from nix-env.
|
# Test upgrading from nix-env.
|
||||||
nix-env -f ./user-envs.nix -i foo-1.0
|
nix-env -f ./user-envs.nix -i foo-1.0
|
||||||
nix profile list | grep -A2 'Name:.*foo' | grep 'Store paths:.*foo-1.0'
|
nix profile list | grep -A2 'Name:.*foo' | grep 'Store paths:.*foo-1.0'
|
||||||
nix profile add $flake1Dir -L
|
nix profile add "$flake1Dir" -L
|
||||||
nix profile list | grep -A4 'Name:.*flake1' | grep 'Locked flake URL:.*narHash'
|
nix profile list | grep -A4 'Name:.*flake1' | grep 'Locked flake URL:.*narHash'
|
||||||
[[ $($TEST_HOME/.nix-profile/bin/hello) = "Hello World" ]]
|
[[ $("$TEST_HOME"/.nix-profile/bin/hello) = "Hello World" ]]
|
||||||
[ -e $TEST_HOME/.nix-profile/share/man ]
|
[ -e "$TEST_HOME"/.nix-profile/share/man ]
|
||||||
(! [ -e $TEST_HOME/.nix-profile/include ])
|
# shellcheck disable=SC2235
|
||||||
|
(! [ -e "$TEST_HOME"/.nix-profile/include ])
|
||||||
nix profile history
|
nix profile history
|
||||||
nix profile history | grep "packages.$system.default: ∅ -> 1.0"
|
nix profile history | grep "packages.$system.default: ∅ -> 1.0"
|
||||||
nix profile diff-closures | grep 'env-manifest.nix: ε → ∅'
|
nix profile diff-closures | grep 'env-manifest.nix: ε → ∅'
|
||||||
|
|
@ -64,32 +66,32 @@ nix profile diff-closures | grep 'env-manifest.nix: ε → ∅'
|
||||||
# Test XDG Base Directories support
|
# Test XDG Base Directories support
|
||||||
export NIX_CONFIG="use-xdg-base-directories = true"
|
export NIX_CONFIG="use-xdg-base-directories = true"
|
||||||
nix profile remove flake1 2>&1 | grep 'removed 1 packages'
|
nix profile remove flake1 2>&1 | grep 'removed 1 packages'
|
||||||
nix profile add $flake1Dir
|
nix profile add "$flake1Dir"
|
||||||
[[ $($TEST_HOME/.local/state/nix/profile/bin/hello) = "Hello World" ]]
|
[[ $("$TEST_HOME"/.local/state/nix/profile/bin/hello) = "Hello World" ]]
|
||||||
unset NIX_CONFIG
|
unset NIX_CONFIG
|
||||||
|
|
||||||
# Test conflicting package add.
|
# Test conflicting package add.
|
||||||
nix profile add $flake1Dir 2>&1 | grep "warning: 'flake1' is already added"
|
nix profile add "$flake1Dir" 2>&1 | grep "warning: 'flake1' is already added"
|
||||||
|
|
||||||
# Test upgrading a package.
|
# Test upgrading a package.
|
||||||
printf NixOS > $flake1Dir/who
|
printf NixOS > "$flake1Dir"/who
|
||||||
printf 2.0 > $flake1Dir/version
|
printf 2.0 > "$flake1Dir"/version
|
||||||
nix profile upgrade flake1
|
nix profile upgrade flake1
|
||||||
[[ $($TEST_HOME/.nix-profile/bin/hello) = "Hello NixOS" ]]
|
[[ $("$TEST_HOME"/.nix-profile/bin/hello) = "Hello NixOS" ]]
|
||||||
nix profile history | grep "packages.$system.default: 1.0, 1.0-man -> 2.0, 2.0-man"
|
nix profile history | grep "packages.$system.default: 1.0, 1.0-man -> 2.0, 2.0-man"
|
||||||
|
|
||||||
# Test upgrading package using regular expression.
|
# Test upgrading package using regular expression.
|
||||||
printf 2.1 > $flake1Dir/version
|
printf 2.1 > "$flake1Dir"/version
|
||||||
nix profile upgrade --regex '.*'
|
nix profile upgrade --regex '.*'
|
||||||
[[ $(readlink $TEST_HOME/.nix-profile/bin/hello) =~ .*-profile-test-2\.1/bin/hello ]]
|
[[ $(readlink "$TEST_HOME"/.nix-profile/bin/hello) =~ .*-profile-test-2\.1/bin/hello ]]
|
||||||
nix profile rollback
|
nix profile rollback
|
||||||
|
|
||||||
# Test upgrading all packages
|
# Test upgrading all packages
|
||||||
printf 2.2 > $flake1Dir/version
|
printf 2.2 > "$flake1Dir"/version
|
||||||
nix profile upgrade --all
|
nix profile upgrade --all
|
||||||
[[ $(readlink $TEST_HOME/.nix-profile/bin/hello) =~ .*-profile-test-2\.2/bin/hello ]]
|
[[ $(readlink "$TEST_HOME"/.nix-profile/bin/hello) =~ .*-profile-test-2\.2/bin/hello ]]
|
||||||
nix profile rollback
|
nix profile rollback
|
||||||
printf 1.0 > $flake1Dir/version
|
printf 1.0 > "$flake1Dir"/version
|
||||||
|
|
||||||
# Test --all exclusivity.
|
# Test --all exclusivity.
|
||||||
assertStderr nix --offline profile upgrade --all foo << EOF
|
assertStderr nix --offline profile upgrade --all foo << EOF
|
||||||
|
|
@ -117,98 +119,102 @@ nix profile rollback
|
||||||
nix profile diff-closures
|
nix profile diff-closures
|
||||||
|
|
||||||
# Test rollback.
|
# Test rollback.
|
||||||
printf World > $flake1Dir/who
|
printf World > "$flake1Dir"/who
|
||||||
nix profile upgrade flake1
|
nix profile upgrade flake1
|
||||||
printf NixOS > $flake1Dir/who
|
printf NixOS > "$flake1Dir"/who
|
||||||
nix profile upgrade flake1
|
nix profile upgrade flake1
|
||||||
nix profile rollback
|
nix profile rollback
|
||||||
[[ $($TEST_HOME/.nix-profile/bin/hello) = "Hello World" ]]
|
[[ $("$TEST_HOME"/.nix-profile/bin/hello) = "Hello World" ]]
|
||||||
|
|
||||||
# Test uninstall.
|
# Test uninstall.
|
||||||
[ -e $TEST_HOME/.nix-profile/bin/foo ]
|
[ -e "$TEST_HOME"/.nix-profile/bin/foo ]
|
||||||
|
# shellcheck disable=SC2235
|
||||||
nix profile remove foo 2>&1 | grep 'removed 1 packages'
|
nix profile remove foo 2>&1 | grep 'removed 1 packages'
|
||||||
(! [ -e $TEST_HOME/.nix-profile/bin/foo ])
|
# shellcheck disable=SC2235
|
||||||
|
(! [ -e "$TEST_HOME"/.nix-profile/bin/foo ])
|
||||||
nix profile history | grep 'foo: 1.0 -> ∅'
|
nix profile history | grep 'foo: 1.0 -> ∅'
|
||||||
nix profile diff-closures | grep 'Version 3 -> 4'
|
nix profile diff-closures | grep 'Version 3 -> 4'
|
||||||
|
|
||||||
# Test installing a non-flake package.
|
# Test installing a non-flake package.
|
||||||
nix profile add --file ./simple.nix ''
|
nix profile add --file ./simple.nix ''
|
||||||
[[ $(cat $TEST_HOME/.nix-profile/hello) = "Hello World!" ]]
|
[[ $(cat "$TEST_HOME"/.nix-profile/hello) = "Hello World!" ]]
|
||||||
nix profile remove simple 2>&1 | grep 'removed 1 packages'
|
nix profile remove simple 2>&1 | grep 'removed 1 packages'
|
||||||
nix profile add $(nix-build --no-out-link ./simple.nix)
|
nix profile add "$(nix-build --no-out-link ./simple.nix)"
|
||||||
[[ $(cat $TEST_HOME/.nix-profile/hello) = "Hello World!" ]]
|
[[ $(cat "$TEST_HOME"/.nix-profile/hello) = "Hello World!" ]]
|
||||||
|
|
||||||
# Test packages with same name from different sources
|
# Test packages with same name from different sources
|
||||||
mkdir $TEST_ROOT/simple-too
|
mkdir "$TEST_ROOT"/simple-too
|
||||||
cp ./simple.nix "${config_nix}" simple.builder.sh $TEST_ROOT/simple-too
|
cp ./simple.nix "${config_nix}" simple.builder.sh "$TEST_ROOT"/simple-too
|
||||||
nix profile add --file $TEST_ROOT/simple-too/simple.nix ''
|
nix profile add --file "$TEST_ROOT"/simple-too/simple.nix ''
|
||||||
nix profile list | grep -A4 'Name:.*simple' | grep 'Name:.*simple-1'
|
nix profile list | grep -A4 'Name:.*simple' | grep 'Name:.*simple-1'
|
||||||
nix profile remove simple 2>&1 | grep 'removed 1 packages'
|
nix profile remove simple 2>&1 | grep 'removed 1 packages'
|
||||||
nix profile remove simple-1 2>&1 | grep 'removed 1 packages'
|
nix profile remove simple-1 2>&1 | grep 'removed 1 packages'
|
||||||
|
|
||||||
# Test wipe-history.
|
# Test wipe-history.
|
||||||
nix profile wipe-history
|
nix profile wipe-history
|
||||||
[[ $(nix profile history | grep Version | wc -l) -eq 1 ]]
|
[[ $(nix profile history | grep -c Version) -eq 1 ]]
|
||||||
|
|
||||||
# Test upgrade to CA package.
|
# Test upgrade to CA package.
|
||||||
printf true > $flake1Dir/ca.nix
|
printf true > "$flake1Dir"/ca.nix
|
||||||
printf 3.0 > $flake1Dir/version
|
printf 3.0 > "$flake1Dir"/version
|
||||||
nix profile upgrade flake1
|
nix profile upgrade flake1
|
||||||
nix profile history | grep "packages.$system.default: 1.0, 1.0-man -> 3.0, 3.0-man"
|
nix profile history | grep "packages.$system.default: 1.0, 1.0-man -> 3.0, 3.0-man"
|
||||||
|
|
||||||
# Test new install of CA package.
|
# Test new install of CA package.
|
||||||
nix profile remove flake1 2>&1 | grep 'removed 1 packages'
|
nix profile remove flake1 2>&1 | grep 'removed 1 packages'
|
||||||
printf 4.0 > $flake1Dir/version
|
printf 4.0 > "$flake1Dir"/version
|
||||||
printf Utrecht > $flake1Dir/who
|
printf Utrecht > "$flake1Dir"/who
|
||||||
nix profile add $flake1Dir
|
nix profile add "$flake1Dir"
|
||||||
[[ $($TEST_HOME/.nix-profile/bin/hello) = "Hello Utrecht" ]]
|
[[ $("$TEST_HOME"/.nix-profile/bin/hello) = "Hello Utrecht" ]]
|
||||||
[[ $(nix path-info --json $(realpath $TEST_HOME/.nix-profile/bin/hello) | jq -r .[].ca) =~ fixed:r:sha256: ]]
|
[[ $(nix path-info --json "$(realpath "$TEST_HOME"/.nix-profile/bin/hello)" | jq -r .[].ca) =~ fixed:r:sha256: ]]
|
||||||
|
|
||||||
# Override the outputs.
|
# Override the outputs.
|
||||||
nix profile remove simple flake1
|
nix profile remove simple flake1
|
||||||
nix profile add "$flake1Dir^*"
|
nix profile add "$flake1Dir^*"
|
||||||
[[ $($TEST_HOME/.nix-profile/bin/hello) = "Hello Utrecht" ]]
|
[[ $("$TEST_HOME"/.nix-profile/bin/hello) = "Hello Utrecht" ]]
|
||||||
[ -e $TEST_HOME/.nix-profile/share/man ]
|
[ -e "$TEST_HOME"/.nix-profile/share/man ]
|
||||||
[ -e $TEST_HOME/.nix-profile/include ]
|
[ -e "$TEST_HOME"/.nix-profile/include ]
|
||||||
|
|
||||||
printf Nix > $flake1Dir/who
|
printf Nix > "$flake1Dir"/who
|
||||||
nix profile list
|
nix profile list
|
||||||
nix profile upgrade flake1
|
nix profile upgrade flake1
|
||||||
[[ $($TEST_HOME/.nix-profile/bin/hello) = "Hello Nix" ]]
|
[[ $("$TEST_HOME"/.nix-profile/bin/hello) = "Hello Nix" ]]
|
||||||
[ -e $TEST_HOME/.nix-profile/share/man ]
|
[ -e "$TEST_HOME"/.nix-profile/share/man ]
|
||||||
[ -e $TEST_HOME/.nix-profile/include ]
|
[ -e "$TEST_HOME"/.nix-profile/include ]
|
||||||
|
|
||||||
nix profile remove flake1 2>&1 | grep 'removed 1 packages'
|
nix profile remove flake1 2>&1 | grep 'removed 1 packages'
|
||||||
nix profile add "$flake1Dir^man"
|
nix profile add "$flake1Dir^man"
|
||||||
(! [ -e $TEST_HOME/.nix-profile/bin/hello ])
|
# shellcheck disable=SC2235
|
||||||
[ -e $TEST_HOME/.nix-profile/share/man ]
|
(! [ -e "$TEST_HOME"/.nix-profile/bin/hello ])
|
||||||
(! [ -e $TEST_HOME/.nix-profile/include ])
|
[ -e "$TEST_HOME"/.nix-profile/share/man ]
|
||||||
|
# shellcheck disable=SC2235
|
||||||
|
(! [ -e "$TEST_HOME"/.nix-profile/include ])
|
||||||
|
|
||||||
# test priority
|
# test priority
|
||||||
nix profile remove flake1 2>&1 | grep 'removed 1 packages'
|
nix profile remove flake1 2>&1 | grep 'removed 1 packages'
|
||||||
|
|
||||||
# Make another flake.
|
# Make another flake.
|
||||||
flake2Dir=$TEST_ROOT/flake2
|
flake2Dir=$TEST_ROOT/flake2
|
||||||
printf World > $flake1Dir/who
|
printf World > "$flake1Dir"/who
|
||||||
cp -r $flake1Dir $flake2Dir
|
cp -r "$flake1Dir" "$flake2Dir"
|
||||||
printf World2 > $flake2Dir/who
|
printf World2 > "$flake2Dir"/who
|
||||||
|
|
||||||
nix profile add $flake1Dir
|
nix profile add "$flake1Dir"
|
||||||
[[ $($TEST_HOME/.nix-profile/bin/hello) = "Hello World" ]]
|
[[ $("$TEST_HOME"/.nix-profile/bin/hello) = "Hello World" ]]
|
||||||
expect 1 nix profile add $flake2Dir
|
expect 1 nix profile add "$flake2Dir"
|
||||||
diff -u <(
|
diff -u <(
|
||||||
nix --offline profile install $flake2Dir 2>&1 1> /dev/null \
|
nix --offline profile install "$flake2Dir" 2>&1 1> /dev/null \
|
||||||
| grep -vE "^warning: " \
|
| grep -vE "^warning: " \
|
||||||
| grep -vE "^error \(ignored\): " \
|
| grep -vE "^error \(ignored\): " \
|
||||||
|| true
|
|| true
|
||||||
) <(cat << EOF
|
) <(cat << EOF
|
||||||
error: An existing package already provides the following file:
|
error: An existing package already provides the following file:
|
||||||
|
|
||||||
$(nix build --no-link --print-out-paths ${flake1Dir}"#default.out")/bin/hello
|
$(nix build --no-link --print-out-paths "${flake1Dir}""#default.out")/bin/hello
|
||||||
|
|
||||||
This is the conflicting file from the new package:
|
This is the conflicting file from the new package:
|
||||||
|
|
||||||
$(nix build --no-link --print-out-paths ${flake2Dir}"#default.out")/bin/hello
|
$(nix build --no-link --print-out-paths "${flake2Dir}""#default.out")/bin/hello
|
||||||
|
|
||||||
To remove the existing package:
|
To remove the existing package:
|
||||||
|
|
||||||
|
|
@ -225,11 +231,11 @@ error: An existing package already provides the following file:
|
||||||
nix profile add path:${flake2Dir}#packages.${system}.default --priority 6
|
nix profile add path:${flake2Dir}#packages.${system}.default --priority 6
|
||||||
EOF
|
EOF
|
||||||
)
|
)
|
||||||
[[ $($TEST_HOME/.nix-profile/bin/hello) = "Hello World" ]]
|
[[ $("$TEST_HOME"/.nix-profile/bin/hello) = "Hello World" ]]
|
||||||
nix profile add $flake2Dir --priority 100
|
nix profile add "$flake2Dir" --priority 100
|
||||||
[[ $($TEST_HOME/.nix-profile/bin/hello) = "Hello World" ]]
|
[[ $("$TEST_HOME"/.nix-profile/bin/hello) = "Hello World" ]]
|
||||||
nix profile add $flake2Dir --priority 0
|
nix profile add "$flake2Dir" --priority 0
|
||||||
[[ $($TEST_HOME/.nix-profile/bin/hello) = "Hello World2" ]]
|
[[ $("$TEST_HOME"/.nix-profile/bin/hello) = "Hello World2" ]]
|
||||||
# nix profile add $flake1Dir --priority 100
|
# nix profile add $flake1Dir --priority 100
|
||||||
# [[ $($TEST_HOME/.nix-profile/bin/hello) = "Hello World" ]]
|
# [[ $($TEST_HOME/.nix-profile/bin/hello) = "Hello World" ]]
|
||||||
|
|
||||||
|
|
@ -237,14 +243,15 @@ nix profile add $flake2Dir --priority 0
|
||||||
# flake references.
|
# flake references.
|
||||||
# Regression test for https://github.com/NixOS/nix/issues/8284
|
# Regression test for https://github.com/NixOS/nix/issues/8284
|
||||||
clearProfiles
|
clearProfiles
|
||||||
nix profile add $(nix build $flake1Dir --no-link --print-out-paths)
|
# shellcheck disable=SC2046
|
||||||
|
nix profile add $(nix build "$flake1Dir" --no-link --print-out-paths)
|
||||||
expect 1 nix profile add --impure --expr "(builtins.getFlake ''$flake2Dir'').packages.$system.default"
|
expect 1 nix profile add --impure --expr "(builtins.getFlake ''$flake2Dir'').packages.$system.default"
|
||||||
|
|
||||||
# Test upgrading from profile version 2.
|
# Test upgrading from profile version 2.
|
||||||
clearProfiles
|
clearProfiles
|
||||||
mkdir -p $TEST_ROOT/import-profile
|
mkdir -p "$TEST_ROOT"/import-profile
|
||||||
outPath=$(nix build --no-link --print-out-paths $flake1Dir/flake.nix^out)
|
outPath=$(nix build --no-link --print-out-paths "$flake1Dir"/flake.nix^out)
|
||||||
printf '{ "version": 2, "elements": [ { "active": true, "attrPath": "legacyPackages.x86_64-linux.hello", "originalUrl": "flake:nixpkgs", "outputs": null, "priority": 5, "storePaths": [ "%s" ], "url": "github:NixOS/nixpkgs/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" } ] }' "$outPath" > $TEST_ROOT/import-profile/manifest.json
|
printf '{ "version": 2, "elements": [ { "active": true, "attrPath": "legacyPackages.x86_64-linux.hello", "originalUrl": "flake:nixpkgs", "outputs": null, "priority": 5, "storePaths": [ "%s" ], "url": "github:NixOS/nixpkgs/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" } ] }' "$outPath" > "$TEST_ROOT"/import-profile/manifest.json
|
||||||
nix build --profile $TEST_HOME/.nix-profile $(nix store add-path $TEST_ROOT/import-profile) --no-link
|
nix build --profile "$TEST_HOME"/.nix-profile "$(nix store add-path "$TEST_ROOT"/import-profile)" --no-link
|
||||||
nix profile list | grep -A4 'Name:.*hello' | grep "Store paths:.*$outPath"
|
nix profile list | grep -A4 'Name:.*hello' | grep "Store paths:.*$outPath"
|
||||||
nix profile remove hello 2>&1 | grep 'removed 1 packages, kept 0 packages'
|
nix profile remove hello 2>&1 | grep 'removed 1 packages, kept 0 packages'
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue