nix-gh/tests/user-envs.sh

145 lines
4.2 KiB
Bash
Raw Normal View History

source common.sh
clearProfiles
2006-02-08 15:32:06 +01:00
set -x
2006-02-08 15:32:06 +01:00
# Query installed: should be empty.
test "$(nix-env -p $profiles/test -q '*' | wc -l)" -eq 0
2006-02-08 15:32:06 +01:00
export HOME=$TEST_ROOT/home
mkdir -p $HOME
nix-env --switch-profile $profiles/test
2006-02-08 15:32:06 +01:00
# Query available: should contain several.
test "$(nix-env -f ./user-envs.nix -qa '*' | wc -l)" -eq 6
outPath10=$(nix-env -f ./user-envs.nix -qa --out-path --no-name '*' | grep foo-1.0)
drvPath10=$(nix-env -f ./user-envs.nix -qa --drv-path --no-name '*' | grep foo-1.0)
[ -n "$outPath10" -a -n "$drvPath10" ]
2006-02-08 15:32:06 +01:00
# Query descriptions.
2014-02-26 18:33:13 +01:00
nix-env -f ./user-envs.nix -qa '*' --description | grep -q silly
rm -f $HOME/.nix-defexpr
ln -s $(pwd)/user-envs.nix $HOME/.nix-defexpr
nix-env -qa '*' --description | grep -q silly
2006-02-08 15:32:06 +01:00
# Install "foo-1.0".
2014-02-26 18:33:13 +01:00
nix-env -i foo-1.0
2006-02-08 15:32:06 +01:00
# Query installed: should contain foo-1.0 now (which should be
# executable).
test "$(nix-env -q '*' | wc -l)" -eq 1
nix-env -q '*' | grep -q foo-1.0
2006-02-08 15:32:06 +01:00
test "$($profiles/test/bin/foo)" = "foo-1.0"
# Disable foo.
nix-env --set-flag active false foo
! [ -e "$profiles/test/bin/foo" ]
# Enable foo.
nix-env --set-flag active true foo
[ -e "$profiles/test/bin/foo" ]
2006-02-08 15:32:06 +01:00
# Store the path of foo-1.0.
outPath10_=$(nix-env -q --out-path --no-name '*' | grep foo-1.0)
2006-02-08 15:32:06 +01:00
echo "foo-1.0 = $outPath10"
[ "$outPath10" = "$outPath10_" ]
2006-02-08 15:32:06 +01:00
# Install "foo-2.0pre1": should remove foo-1.0.
2014-02-26 18:33:13 +01:00
nix-env -i foo-2.0pre1
2006-02-08 15:32:06 +01:00
# Query installed: should contain foo-2.0pre1 now.
test "$(nix-env -q '*' | wc -l)" -eq 1
nix-env -q '*' | grep -q foo-2.0pre1
2006-02-08 15:32:06 +01:00
test "$($profiles/test/bin/foo)" = "foo-2.0pre1"
# Upgrade "foo": should install foo-2.0.
NIX_PATH=nixpkgs=./user-envs.nix:$NIX_PATH nix-env -f '<nixpkgs>' -u foo
2006-02-08 15:32:06 +01:00
# Query installed: should contain foo-2.0 now.
test "$(nix-env -q '*' | wc -l)" -eq 1
nix-env -q '*' | grep -q foo-2.0
2006-02-08 15:32:06 +01:00
test "$($profiles/test/bin/foo)" = "foo-2.0"
# Store the path of foo-2.0.
outPath20=$(nix-env -q --out-path --no-name '*' | grep foo-2.0)
2006-02-08 15:32:06 +01:00
test -n "$outPath20"
# Install bar-0.1, uninstall foo.
2014-02-26 18:33:13 +01:00
nix-env -i bar-0.1
nix-env -e foo
2006-02-08 15:32:06 +01:00
# Query installed: should only contain bar-0.1 now.
if nix-env -q '*' | grep -q foo; then false; fi
nix-env -q '*' | grep -q bar
2006-02-08 15:32:06 +01:00
# Rollback: should bring "foo" back.
nix-env --rollback
nix-env -q '*' | grep -q foo-2.0
nix-env -q '*' | grep -q bar
2006-02-08 15:32:06 +01:00
# Rollback again: should remove "bar".
nix-env --rollback
nix-env -q '*' | grep -q foo-2.0
if nix-env -q '*' | grep -q bar; then false; fi
2006-02-08 15:32:06 +01:00
# Count generations.
nix-env --list-generations
test "$(nix-env --list-generations | wc -l)" -eq 7
2006-02-08 15:32:06 +01:00
# Install foo-1.0, now using its store path.
nix-env -i "$outPath10"
nix-env -q '*' | grep -q foo-1.0
nix-store -qR $profiles/test | grep "$outPath10"
nix-store -q --referrers-closure $profiles/test | grep "$(nix-store -q --resolve $profiles/test)"
[ "$(nix-store -q --deriver "$outPath10")" = $drvPath10 ]
2006-02-08 15:32:06 +01:00
# Uninstall foo-1.0, using a symlink to its store path.
ln -sfn $outPath10/bin/foo $TEST_ROOT/symlink
nix-env -e $TEST_ROOT/symlink
if nix-env -q '*' | grep -q foo; then false; fi
! nix-store -qR $profiles/test | grep "$outPath10"
# Install foo-1.0, now using a symlink to its store path.
nix-env -i $TEST_ROOT/symlink
nix-env -q '*' | grep -q foo
2006-02-08 15:32:06 +01:00
# Delete all old generations.
nix-env --delete-generations old
2006-02-08 15:32:06 +01:00
# Run the garbage collector. This should get rid of foo-2.0 but not
# foo-1.0.
nix-collect-garbage
2006-02-08 15:32:06 +01:00
test -e "$outPath10"
2012-12-04 14:47:50 +01:00
! [ -e "$outPath20" ]
2006-02-17 18:03:19 +01:00
# Uninstall everything
2014-02-26 18:33:13 +01:00
nix-env -e '*'
test "$(nix-env -q '*' | wc -l)" -eq 0
2006-02-17 18:03:19 +01:00
# Installing "foo" should only install the newest foo.
2014-02-26 18:33:13 +01:00
nix-env -i foo
test "$(nix-env -q '*' | grep foo- | wc -l)" -eq 1
nix-env -q '*' | grep -q foo-2.0
2006-02-17 18:03:19 +01:00
2006-02-17 18:05:34 +01:00
# On the other hand, this should install both (and should fail due to
# a collision).
2014-02-26 18:33:13 +01:00
nix-env -e '*'
! nix-env -i foo-1.0 foo-2.0
2006-02-17 18:05:34 +01:00
2006-02-17 18:03:19 +01:00
# Installing "*" should install one foo and one bar.
2014-02-26 18:33:13 +01:00
nix-env -e '*'
nix-env -i '*'
test "$(nix-env -q '*' | wc -l)" -eq 2
nix-env -q '*' | grep -q foo-2.0
nix-env -q '*' | grep -q bar-0.1.1
2012-12-04 14:47:50 +01:00
# Test priorities: foo-0.1 has a lower priority than foo-1.0, so it
# should be possible to install both without a collision. Also test
# --set-flag priority to manually override the declared priorities.
2014-02-26 18:33:13 +01:00
nix-env -e '*'
nix-env -i foo-0.1 foo-1.0
2012-12-04 14:47:50 +01:00
[ "$($profiles/test/bin/foo)" = "foo-1.0" ]
2014-02-26 18:33:13 +01:00
nix-env --set-flag priority 1 foo-0.1
2012-12-04 14:47:50 +01:00
[ "$($profiles/test/bin/foo)" = "foo-0.1" ]