2022-03-02 10:46:24 +00:00
|
|
|
source common.sh
|
|
|
|
|
|
|
|
clearStore
|
|
|
|
clearProfiles
|
|
|
|
|
2022-03-26 16:35:06 +00:00
|
|
|
enableFeatures "ca-derivations"
|
2022-03-02 22:08:49 +00:00
|
|
|
restartDaemon
|
2022-03-02 20:48:25 +00:00
|
|
|
|
2022-03-02 10:46:24 +00:00
|
|
|
# Make a flake.
|
|
|
|
flake1Dir=$TEST_ROOT/flake1
|
|
|
|
mkdir -p $flake1Dir
|
|
|
|
|
|
|
|
cat > $flake1Dir/flake.nix <<EOF
|
|
|
|
{
|
|
|
|
description = "Bla bla";
|
|
|
|
|
|
|
|
outputs = { self }: with import ./config.nix; rec {
|
|
|
|
packages.$system.default = mkDerivation {
|
2022-03-02 19:56:40 +00:00
|
|
|
name = "profile-test-\${builtins.readFile ./version}";
|
2022-04-20 14:50:24 +00:00
|
|
|
outputs = [ "out" "man" "dev" ];
|
2022-03-02 10:46:24 +00:00
|
|
|
builder = builtins.toFile "builder.sh"
|
|
|
|
''
|
|
|
|
mkdir -p \$out/bin
|
|
|
|
cat > \$out/bin/hello <<EOF
|
|
|
|
#! ${shell}
|
|
|
|
echo Hello \${builtins.readFile ./who}
|
|
|
|
EOF
|
|
|
|
chmod +x \$out/bin/hello
|
2022-03-02 19:37:46 +00:00
|
|
|
echo DONE
|
2022-04-20 14:50:24 +00:00
|
|
|
mkdir -p \$man/share/man
|
|
|
|
mkdir -p \$dev/include
|
2022-03-02 10:46:24 +00:00
|
|
|
'';
|
2022-03-02 19:37:46 +00:00
|
|
|
__contentAddressed = import ./ca.nix;
|
|
|
|
outputHashMode = "recursive";
|
|
|
|
outputHashAlgo = "sha256";
|
2022-04-20 14:50:24 +00:00
|
|
|
meta.outputsToInstall = [ "out" "man" ];
|
2022-03-02 10:46:24 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
EOF
|
|
|
|
|
|
|
|
printf World > $flake1Dir/who
|
|
|
|
printf 1.0 > $flake1Dir/version
|
2022-03-02 19:37:46 +00:00
|
|
|
printf false > $flake1Dir/ca.nix
|
2022-03-02 10:46:24 +00:00
|
|
|
|
|
|
|
cp ./config.nix $flake1Dir/
|
|
|
|
|
|
|
|
# Test upgrading from nix-env.
|
|
|
|
nix-env -f ./user-envs.nix -i foo-1.0
|
2024-05-02 00:51:16 +00:00
|
|
|
nix profile list | grep -A2 'Name:.*foo' | grep 'Store paths:.*foo-1.0'
|
2022-03-02 10:46:24 +00:00
|
|
|
nix profile install $flake1Dir -L
|
2024-05-02 01:12:04 +00:00
|
|
|
nix profile list | grep -A4 'Name:.*flake1' | grep 'Locked flake URL:.*narHash'
|
2022-03-02 10:46:24 +00:00
|
|
|
[[ $($TEST_HOME/.nix-profile/bin/hello) = "Hello World" ]]
|
2022-04-20 14:50:24 +00:00
|
|
|
[ -e $TEST_HOME/.nix-profile/share/man ]
|
|
|
|
(! [ -e $TEST_HOME/.nix-profile/include ])
|
2022-03-02 10:46:24 +00:00
|
|
|
nix profile history
|
|
|
|
nix profile history | grep "packages.$system.default: ∅ -> 1.0"
|
|
|
|
nix profile diff-closures | grep 'env-manifest.nix: ε → ∅'
|
|
|
|
|
2021-11-17 20:35:21 +00:00
|
|
|
# Test XDG Base Directories support
|
|
|
|
|
|
|
|
export NIX_CONFIG="use-xdg-base-directories = true"
|
2024-05-02 01:55:26 +00:00
|
|
|
nix profile remove flake1 2>&1 | grep 'removed 1 packages'
|
2021-11-17 20:35:21 +00:00
|
|
|
nix profile install $flake1Dir
|
|
|
|
[[ $($TEST_HOME/.local/state/nix/profile/bin/hello) = "Hello World" ]]
|
|
|
|
unset NIX_CONFIG
|
|
|
|
|
2022-03-02 10:46:24 +00:00
|
|
|
# Test upgrading a package.
|
|
|
|
printf NixOS > $flake1Dir/who
|
|
|
|
printf 2.0 > $flake1Dir/version
|
2024-05-02 01:12:04 +00:00
|
|
|
nix profile upgrade flake1
|
2022-03-02 10:46:24 +00:00
|
|
|
[[ $($TEST_HOME/.nix-profile/bin/hello) = "Hello NixOS" ]]
|
2022-04-20 14:50:24 +00:00
|
|
|
nix profile history | grep "packages.$system.default: 1.0, 1.0-man -> 2.0, 2.0-man"
|
2022-03-02 10:46:24 +00:00
|
|
|
|
|
|
|
# Test 'history', 'diff-closures'.
|
|
|
|
nix profile diff-closures
|
|
|
|
|
|
|
|
# Test rollback.
|
|
|
|
nix profile rollback
|
|
|
|
[[ $($TEST_HOME/.nix-profile/bin/hello) = "Hello World" ]]
|
|
|
|
|
|
|
|
# Test uninstall.
|
|
|
|
[ -e $TEST_HOME/.nix-profile/bin/foo ]
|
2024-05-02 01:55:26 +00:00
|
|
|
nix profile remove "foo" 2>&1 | grep 'removed 1 packages'
|
2022-03-02 10:46:24 +00:00
|
|
|
(! [ -e $TEST_HOME/.nix-profile/bin/foo ])
|
|
|
|
nix profile history | grep 'foo: 1.0 -> ∅'
|
|
|
|
nix profile diff-closures | grep 'Version 3 -> 4'
|
|
|
|
|
2022-03-02 19:56:40 +00:00
|
|
|
# Test installing a non-flake package.
|
|
|
|
nix profile install --file ./simple.nix ''
|
|
|
|
[[ $(cat $TEST_HOME/.nix-profile/hello) = "Hello World!" ]]
|
2024-05-02 01:55:26 +00:00
|
|
|
nix profile remove simple 2>&1 | grep 'removed 1 packages'
|
2022-03-02 19:56:40 +00:00
|
|
|
nix profile install $(nix-build --no-out-link ./simple.nix)
|
|
|
|
[[ $(cat $TEST_HOME/.nix-profile/hello) = "Hello World!" ]]
|
|
|
|
|
2024-05-02 00:51:16 +00:00
|
|
|
# Test packages with same name from different sources
|
|
|
|
mkdir $TEST_ROOT/simple-too
|
|
|
|
cp ./simple.nix ./config.nix simple.builder.sh $TEST_ROOT/simple-too
|
|
|
|
nix profile install --file $TEST_ROOT/simple-too/simple.nix ''
|
2024-05-02 01:55:26 +00:00
|
|
|
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-1 2>&1 | grep 'removed 1 packages'
|
2024-05-02 00:51:16 +00:00
|
|
|
|
2022-03-02 10:46:24 +00:00
|
|
|
# Test wipe-history.
|
|
|
|
nix profile wipe-history
|
|
|
|
[[ $(nix profile history | grep Version | wc -l) -eq 1 ]]
|
2022-03-02 19:37:46 +00:00
|
|
|
|
|
|
|
# Test upgrade to CA package.
|
|
|
|
printf true > $flake1Dir/ca.nix
|
|
|
|
printf 3.0 > $flake1Dir/version
|
2024-05-02 01:12:04 +00:00
|
|
|
nix profile upgrade flake1
|
2022-04-20 14:50:24 +00:00
|
|
|
nix profile history | grep "packages.$system.default: 1.0, 1.0-man -> 3.0, 3.0-man"
|
2022-03-02 19:37:46 +00:00
|
|
|
|
|
|
|
# Test new install of CA package.
|
2024-05-02 01:55:26 +00:00
|
|
|
nix profile remove flake1 2>&1 | grep 'removed 1 packages'
|
2022-03-02 19:37:46 +00:00
|
|
|
printf 4.0 > $flake1Dir/version
|
|
|
|
printf Utrecht > $flake1Dir/who
|
2022-03-02 20:48:25 +00:00
|
|
|
nix profile install $flake1Dir
|
2022-03-02 19:37:46 +00:00
|
|
|
[[ $($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: ]]
|
2022-05-03 12:37:28 +00:00
|
|
|
|
|
|
|
# Override the outputs.
|
2024-05-02 00:51:16 +00:00
|
|
|
nix profile remove simple flake1
|
2022-05-03 12:37:28 +00:00
|
|
|
nix profile install "$flake1Dir^*"
|
|
|
|
[[ $($TEST_HOME/.nix-profile/bin/hello) = "Hello Utrecht" ]]
|
|
|
|
[ -e $TEST_HOME/.nix-profile/share/man ]
|
|
|
|
[ -e $TEST_HOME/.nix-profile/include ]
|
|
|
|
|
|
|
|
printf Nix > $flake1Dir/who
|
2024-05-02 00:51:16 +00:00
|
|
|
nix profile list
|
|
|
|
nix profile upgrade flake1
|
2022-05-03 12:37:28 +00:00
|
|
|
[[ $($TEST_HOME/.nix-profile/bin/hello) = "Hello Nix" ]]
|
|
|
|
[ -e $TEST_HOME/.nix-profile/share/man ]
|
|
|
|
[ -e $TEST_HOME/.nix-profile/include ]
|
|
|
|
|
2024-05-02 01:55:26 +00:00
|
|
|
nix profile remove flake1 2>&1 | grep 'removed 1 packages'
|
2022-05-03 12:37:28 +00:00
|
|
|
nix profile install "$flake1Dir^man"
|
|
|
|
(! [ -e $TEST_HOME/.nix-profile/bin/hello ])
|
|
|
|
[ -e $TEST_HOME/.nix-profile/share/man ]
|
|
|
|
(! [ -e $TEST_HOME/.nix-profile/include ])
|
2022-05-11 10:15:08 +00:00
|
|
|
|
|
|
|
# test priority
|
2024-05-02 01:12:04 +00:00
|
|
|
nix profile remove flake1
|
2022-05-11 10:15:08 +00:00
|
|
|
|
|
|
|
# Make another flake.
|
|
|
|
flake2Dir=$TEST_ROOT/flake2
|
|
|
|
printf World > $flake1Dir/who
|
|
|
|
cp -r $flake1Dir $flake2Dir
|
|
|
|
printf World2 > $flake2Dir/who
|
|
|
|
|
|
|
|
nix profile install $flake1Dir
|
|
|
|
[[ $($TEST_HOME/.nix-profile/bin/hello) = "Hello World" ]]
|
2023-02-24 20:26:36 +00:00
|
|
|
expect 1 nix profile install $flake2Dir
|
2023-02-28 09:53:42 +00:00
|
|
|
diff -u <(
|
|
|
|
nix --offline profile install $flake2Dir 2>&1 1> /dev/null \
|
|
|
|
| grep -vE "^warning: " \
|
2023-04-03 18:47:21 +00:00
|
|
|
| grep -vE "^error \(ignored\): " \
|
2024-05-24 04:48:36 +00:00
|
|
|
| grep -vE "^fetching .+ input" \
|
2023-02-28 09:53:42 +00:00
|
|
|
|| true
|
|
|
|
) <(cat << EOF
|
2023-02-24 20:26:36 +00:00
|
|
|
error: An existing package already provides the following file:
|
|
|
|
|
|
|
|
$(nix build --no-link --print-out-paths ${flake1Dir}"#default.out")/bin/hello
|
|
|
|
|
|
|
|
This is the conflicting file from the new package:
|
|
|
|
|
|
|
|
$(nix build --no-link --print-out-paths ${flake2Dir}"#default.out")/bin/hello
|
|
|
|
|
|
|
|
To remove the existing package:
|
|
|
|
|
2023-05-16 09:37:45 +00:00
|
|
|
nix profile remove path:${flake1Dir}#packages.${system}.default
|
2023-02-24 20:26:36 +00:00
|
|
|
|
|
|
|
The new package can also be installed next to the existing one by assigning a different priority.
|
|
|
|
The conflicting packages have a priority of 5.
|
|
|
|
To prioritise the new package:
|
|
|
|
|
2023-05-16 09:37:45 +00:00
|
|
|
nix profile install path:${flake2Dir}#packages.${system}.default --priority 4
|
2023-02-24 20:26:36 +00:00
|
|
|
|
|
|
|
To prioritise the existing package:
|
|
|
|
|
2023-05-16 09:37:45 +00:00
|
|
|
nix profile install path:${flake2Dir}#packages.${system}.default --priority 6
|
2023-02-24 20:26:36 +00:00
|
|
|
EOF
|
|
|
|
)
|
|
|
|
[[ $($TEST_HOME/.nix-profile/bin/hello) = "Hello World" ]]
|
2022-05-11 10:15:08 +00:00
|
|
|
nix profile install $flake2Dir --priority 100
|
|
|
|
[[ $($TEST_HOME/.nix-profile/bin/hello) = "Hello World" ]]
|
|
|
|
nix profile install $flake2Dir --priority 0
|
|
|
|
[[ $($TEST_HOME/.nix-profile/bin/hello) = "Hello World2" ]]
|
2022-05-13 20:02:28 +00:00
|
|
|
# nix profile install $flake1Dir --priority 100
|
|
|
|
# [[ $($TEST_HOME/.nix-profile/bin/hello) = "Hello World" ]]
|
2023-05-16 09:37:45 +00:00
|
|
|
|
|
|
|
# Ensure that conflicts are handled properly even when the installables aren't
|
|
|
|
# flake references.
|
|
|
|
# Regression test for https://github.com/NixOS/nix/issues/8284
|
|
|
|
clearProfiles
|
|
|
|
nix profile install $(nix build $flake1Dir --no-link --print-out-paths)
|
|
|
|
expect 1 nix profile install --impure --expr "(builtins.getFlake ''$flake2Dir'').packages.$system.default"
|
2024-01-12 15:33:15 +00:00
|
|
|
|
|
|
|
# Test upgrading from profile version 2.
|
|
|
|
clearProfiles
|
|
|
|
mkdir -p $TEST_ROOT/import-profile
|
|
|
|
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
|
|
|
|
nix build --profile $TEST_HOME/.nix-profile $(nix store add-path $TEST_ROOT/import-profile)
|
|
|
|
nix profile list | grep -A4 'Name:.*hello' | grep "Store paths:.*$outPath"
|
|
|
|
nix profile remove hello 2>&1 | grep 'removed 1 packages, kept 0 packages'
|