2006-03-01 12:15:33 +00:00
|
|
|
|
source common.sh
|
|
|
|
|
|
2021-12-09 15:26:46 +00:00
|
|
|
|
if [ -z "${storeCleared-}" ]; then
|
2016-07-27 15:14:41 +00:00
|
|
|
|
clearStore
|
|
|
|
|
fi
|
|
|
|
|
|
2006-09-21 18:54:08 +00:00
|
|
|
|
clearProfiles
|
2006-02-08 14:32:06 +00:00
|
|
|
|
|
|
|
|
|
# Query installed: should be empty.
|
2011-10-10 21:32:34 +00:00
|
|
|
|
test "$(nix-env -p $profiles/test -q '*' | wc -l)" -eq 0
|
2006-02-08 14:32:06 +00:00
|
|
|
|
|
2014-02-26 17:28:55 +00:00
|
|
|
|
nix-env --switch-profile $profiles/test
|
|
|
|
|
|
2006-02-08 14:32:06 +00:00
|
|
|
|
# Query available: should contain several.
|
2014-02-26 17:28:55 +00:00
|
|
|
|
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 14:32:06 +00:00
|
|
|
|
|
2022-03-16 17:39:46 +00:00
|
|
|
|
# Query with json
|
|
|
|
|
nix-env -f ./user-envs.nix -qa --json | jq -e '.[] | select(.name == "bar-0.1") | [
|
|
|
|
|
.outputName == "out",
|
|
|
|
|
.outputs.out == null
|
|
|
|
|
] | all'
|
|
|
|
|
nix-env -f ./user-envs.nix -qa --json --out-path | jq -e '.[] | select(.name == "bar-0.1") | [
|
|
|
|
|
.outputName == "out",
|
|
|
|
|
(.outputs.out | test("'$NIX_STORE_DIR'.*-0\\.1"))
|
|
|
|
|
] | all'
|
`nix-env --query`: fix `--json` ignoring `--drv-path`
```json
{
"AMB-plugins": {
"drvPath": "/nix/store/l99cb7h2hy8dg005arsjbd9kx0w05d3h-AMB-plugins-0.8.1.drv",
"name": "AMB-plugins-0.8.1",
"outputName": "out",
"outputs": {
"out": null
},
"pname": "AMB-plugins",
"system": "x86_64-linux",
"version": "0.8.1"
},
"ArchiSteamFarm": {
"drvPath": "/nix/store/nhplgyjj34fz6hjmnyih25gxscfh8s7b-ArchiSteamFarm-5.4.12.5.drv",
"name": "ArchiSteamFarm-5.4.12.5",
"outputName": "out",
"outputs": {
"out": null
},
"pname": "ArchiSteamFarm",
"system": "x86_64-linux",
"version": "5.4.12.5"
},
...
```
2023-10-30 23:36:13 +00:00
|
|
|
|
nix-env -f ./user-envs.nix -qa --json --drv-path | jq -e '.[] | select(.name == "bar-0.1") | (.drvPath | test("'$NIX_STORE_DIR'.*-0\\.1\\.drv"))'
|
2022-03-16 17:39:46 +00:00
|
|
|
|
|
2006-03-10 16:20:42 +00:00
|
|
|
|
# Query descriptions.
|
2021-12-09 15:26:46 +00:00
|
|
|
|
nix-env -f ./user-envs.nix -qa '*' --description | grepQuiet silly
|
2019-10-09 16:01:21 +00:00
|
|
|
|
rm -rf $HOME/.nix-defexpr
|
2014-02-26 17:33:13 +00:00
|
|
|
|
ln -s $(pwd)/user-envs.nix $HOME/.nix-defexpr
|
2021-12-09 15:26:46 +00:00
|
|
|
|
nix-env -qa '*' --description | grepQuiet silly
|
2006-03-10 16:20:42 +00:00
|
|
|
|
|
2018-02-08 14:25:03 +00:00
|
|
|
|
# Query the system.
|
2021-12-09 15:26:46 +00:00
|
|
|
|
nix-env -qa '*' --system | grepQuiet $system
|
2018-02-08 14:25:03 +00:00
|
|
|
|
|
2006-02-08 14:32:06 +00:00
|
|
|
|
# Install "foo-1.0".
|
2014-02-26 17:33:13 +00:00
|
|
|
|
nix-env -i foo-1.0
|
2006-02-08 14:32:06 +00:00
|
|
|
|
|
|
|
|
|
# Query installed: should contain foo-1.0 now (which should be
|
|
|
|
|
# executable).
|
2014-02-26 17:28:55 +00:00
|
|
|
|
test "$(nix-env -q '*' | wc -l)" -eq 1
|
2021-12-09 15:26:46 +00:00
|
|
|
|
nix-env -q '*' | grepQuiet foo-1.0
|
2006-02-08 14:32:06 +00:00
|
|
|
|
test "$($profiles/test/bin/foo)" = "foo-1.0"
|
|
|
|
|
|
2014-02-26 17:40:08 +00:00
|
|
|
|
# Test nix-env -qc to compare installed against available packages, and vice versa.
|
2021-12-09 15:26:46 +00:00
|
|
|
|
nix-env -qc '*' | grepQuiet '< 2.0'
|
|
|
|
|
nix-env -qac '*' | grepQuiet '> 1.0'
|
2014-02-26 17:40:08 +00:00
|
|
|
|
|
|
|
|
|
# Test the -b flag to filter out source-only packages.
|
|
|
|
|
[ "$(nix-env -qab | wc -l)" -eq 1 ]
|
|
|
|
|
|
|
|
|
|
# Test the -s flag to get package status.
|
2021-12-09 15:26:46 +00:00
|
|
|
|
nix-env -qas | grepQuiet 'IP- foo-1.0'
|
|
|
|
|
nix-env -qas | grepQuiet -- '--- bar-0.1'
|
2014-02-26 17:40:08 +00:00
|
|
|
|
|
2012-12-04 13:30:34 +00:00
|
|
|
|
# Disable foo.
|
2014-02-26 17:28:55 +00:00
|
|
|
|
nix-env --set-flag active false foo
|
2014-08-21 19:50:19 +00:00
|
|
|
|
(! [ -e "$profiles/test/bin/foo" ])
|
2012-12-04 13:30:34 +00:00
|
|
|
|
|
|
|
|
|
# Enable foo.
|
2014-02-26 17:28:55 +00:00
|
|
|
|
nix-env --set-flag active true foo
|
2012-12-04 13:30:34 +00:00
|
|
|
|
[ -e "$profiles/test/bin/foo" ]
|
|
|
|
|
|
2006-02-08 14:32:06 +00:00
|
|
|
|
# Store the path of foo-1.0.
|
2014-02-26 17:28:55 +00:00
|
|
|
|
outPath10_=$(nix-env -q --out-path --no-name '*' | grep foo-1.0)
|
2006-02-08 14:32:06 +00:00
|
|
|
|
echo "foo-1.0 = $outPath10"
|
2014-02-26 17:28:55 +00:00
|
|
|
|
[ "$outPath10" = "$outPath10_" ]
|
2006-02-08 14:32:06 +00:00
|
|
|
|
|
|
|
|
|
# Install "foo-2.0pre1": should remove foo-1.0.
|
2014-02-26 17:33:13 +00:00
|
|
|
|
nix-env -i foo-2.0pre1
|
2006-02-08 14:32:06 +00:00
|
|
|
|
|
|
|
|
|
# Query installed: should contain foo-2.0pre1 now.
|
2014-02-26 17:28:55 +00:00
|
|
|
|
test "$(nix-env -q '*' | wc -l)" -eq 1
|
2021-12-09 15:26:46 +00:00
|
|
|
|
nix-env -q '*' | grepQuiet foo-2.0pre1
|
2006-02-08 14:32:06 +00:00
|
|
|
|
test "$($profiles/test/bin/foo)" = "foo-2.0pre1"
|
|
|
|
|
|
|
|
|
|
# Upgrade "foo": should install foo-2.0.
|
2021-12-09 15:26:46 +00:00
|
|
|
|
NIX_PATH=nixpkgs=./user-envs.nix:${NIX_PATH-} nix-env -f '<nixpkgs>' -u foo
|
2006-02-08 14:32:06 +00:00
|
|
|
|
|
|
|
|
|
# Query installed: should contain foo-2.0 now.
|
2014-02-26 17:28:55 +00:00
|
|
|
|
test "$(nix-env -q '*' | wc -l)" -eq 1
|
2021-12-09 15:26:46 +00:00
|
|
|
|
nix-env -q '*' | grepQuiet foo-2.0
|
2006-02-08 14:32:06 +00:00
|
|
|
|
test "$($profiles/test/bin/foo)" = "foo-2.0"
|
|
|
|
|
|
|
|
|
|
# Store the path of foo-2.0.
|
2014-02-26 17:28:55 +00:00
|
|
|
|
outPath20=$(nix-env -q --out-path --no-name '*' | grep foo-2.0)
|
2006-02-08 14:32:06 +00:00
|
|
|
|
test -n "$outPath20"
|
|
|
|
|
|
|
|
|
|
# Install bar-0.1, uninstall foo.
|
2014-02-26 17:33:13 +00:00
|
|
|
|
nix-env -i bar-0.1
|
|
|
|
|
nix-env -e foo
|
2006-02-08 14:32:06 +00:00
|
|
|
|
|
|
|
|
|
# Query installed: should only contain bar-0.1 now.
|
2021-12-09 15:26:46 +00:00
|
|
|
|
if nix-env -q '*' | grepQuiet foo; then false; fi
|
|
|
|
|
nix-env -q '*' | grepQuiet bar
|
2006-02-08 14:32:06 +00:00
|
|
|
|
|
|
|
|
|
# Rollback: should bring "foo" back.
|
2014-02-26 17:45:26 +00:00
|
|
|
|
oldGen="$(nix-store -q --resolve $profiles/test)"
|
2014-02-26 17:28:55 +00:00
|
|
|
|
nix-env --rollback
|
2014-02-26 17:45:26 +00:00
|
|
|
|
[ "$(nix-store -q --resolve $profiles/test)" != "$oldGen" ]
|
2021-12-09 15:26:46 +00:00
|
|
|
|
nix-env -q '*' | grepQuiet foo-2.0
|
|
|
|
|
nix-env -q '*' | grepQuiet bar
|
2006-02-08 14:32:06 +00:00
|
|
|
|
|
|
|
|
|
# Rollback again: should remove "bar".
|
2014-02-26 17:28:55 +00:00
|
|
|
|
nix-env --rollback
|
2021-12-09 15:26:46 +00:00
|
|
|
|
nix-env -q '*' | grepQuiet foo-2.0
|
|
|
|
|
if nix-env -q '*' | grepQuiet bar; then false; fi
|
2006-02-08 14:32:06 +00:00
|
|
|
|
|
|
|
|
|
# Count generations.
|
2014-02-26 17:28:55 +00:00
|
|
|
|
nix-env --list-generations
|
|
|
|
|
test "$(nix-env --list-generations | wc -l)" -eq 7
|
2006-02-08 14:32:06 +00:00
|
|
|
|
|
2015-05-20 15:29:52 +00:00
|
|
|
|
# Doing the same operation twice results in the same generation, which triggers
|
|
|
|
|
# "lazy" behaviour and does not create a new symlink.
|
2015-05-19 18:03:36 +00:00
|
|
|
|
|
2015-05-20 15:29:52 +00:00
|
|
|
|
nix-env -i foo
|
2015-05-18 06:38:49 +00:00
|
|
|
|
nix-env -i foo
|
|
|
|
|
|
|
|
|
|
# Count generations.
|
|
|
|
|
nix-env --list-generations
|
2015-05-19 18:03:36 +00:00
|
|
|
|
test "$(nix-env --list-generations | wc -l)" -eq 8
|
|
|
|
|
|
2014-02-26 17:45:26 +00:00
|
|
|
|
# Switch to a specified generation.
|
|
|
|
|
nix-env --switch-generation 7
|
|
|
|
|
[ "$(nix-store -q --resolve $profiles/test)" = "$oldGen" ]
|
|
|
|
|
|
2006-02-08 14:32:06 +00:00
|
|
|
|
# Install foo-1.0, now using its store path.
|
2014-02-26 17:28:55 +00:00
|
|
|
|
nix-env -i "$outPath10"
|
2021-12-09 15:26:46 +00:00
|
|
|
|
nix-env -q '*' | grepQuiet foo-1.0
|
2014-02-26 17:28:55 +00:00
|
|
|
|
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 14:32:06 +00:00
|
|
|
|
|
2007-11-29 16:18:24 +00:00
|
|
|
|
# Uninstall foo-1.0, using a symlink to its store path.
|
|
|
|
|
ln -sfn $outPath10/bin/foo $TEST_ROOT/symlink
|
2014-02-26 17:28:55 +00:00
|
|
|
|
nix-env -e $TEST_ROOT/symlink
|
2021-12-09 15:26:46 +00:00
|
|
|
|
if nix-env -q '*' | grepQuiet foo; then false; fi
|
|
|
|
|
nix-store -qR $profiles/test | grepInverse "$outPath10"
|
2007-11-29 16:18:24 +00:00
|
|
|
|
|
|
|
|
|
# Install foo-1.0, now using a symlink to its store path.
|
2014-02-26 17:28:55 +00:00
|
|
|
|
nix-env -i $TEST_ROOT/symlink
|
2021-12-09 15:26:46 +00:00
|
|
|
|
nix-env -q '*' | grepQuiet foo
|
2007-11-29 16:18:24 +00:00
|
|
|
|
|
2006-02-08 14:32:06 +00:00
|
|
|
|
# Delete all old generations.
|
2014-02-26 17:28:55 +00:00
|
|
|
|
nix-env --delete-generations old
|
2006-02-08 14:32:06 +00:00
|
|
|
|
|
|
|
|
|
# Run the garbage collector. This should get rid of foo-2.0 but not
|
|
|
|
|
# foo-1.0.
|
2011-10-10 21:32:34 +00:00
|
|
|
|
nix-collect-garbage
|
2006-02-08 14:32:06 +00:00
|
|
|
|
test -e "$outPath10"
|
2014-08-21 19:50:19 +00:00
|
|
|
|
(! [ -e "$outPath20" ])
|
2006-02-17 17:03:19 +00:00
|
|
|
|
|
|
|
|
|
# Uninstall everything
|
2014-02-26 17:33:13 +00:00
|
|
|
|
nix-env -e '*'
|
2014-02-26 17:28:55 +00:00
|
|
|
|
test "$(nix-env -q '*' | wc -l)" -eq 0
|
2006-02-17 17:03:19 +00:00
|
|
|
|
|
|
|
|
|
# Installing "foo" should only install the newest foo.
|
2014-02-26 17:33:13 +00:00
|
|
|
|
nix-env -i foo
|
2014-02-26 17:28:55 +00:00
|
|
|
|
test "$(nix-env -q '*' | grep foo- | wc -l)" -eq 1
|
2021-12-09 15:26:46 +00:00
|
|
|
|
nix-env -q '*' | grepQuiet foo-2.0
|
2006-02-17 17:03:19 +00:00
|
|
|
|
|
2006-02-17 17:05:34 +00:00
|
|
|
|
# On the other hand, this should install both (and should fail due to
|
|
|
|
|
# a collision).
|
2014-02-26 17:33:13 +00:00
|
|
|
|
nix-env -e '*'
|
2014-08-21 19:50:19 +00:00
|
|
|
|
(! nix-env -i foo-1.0 foo-2.0)
|
2006-02-17 17:05:34 +00:00
|
|
|
|
|
2006-02-17 17:03:19 +00:00
|
|
|
|
# Installing "*" should install one foo and one bar.
|
2014-02-26 17:33:13 +00:00
|
|
|
|
nix-env -e '*'
|
|
|
|
|
nix-env -i '*'
|
2014-02-26 17:28:55 +00:00
|
|
|
|
test "$(nix-env -q '*' | wc -l)" -eq 2
|
2021-12-09 15:26:46 +00:00
|
|
|
|
nix-env -q '*' | grepQuiet foo-2.0
|
|
|
|
|
nix-env -q '*' | grepQuiet bar-0.1.1
|
2012-12-04 13:47:50 +00: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
|
2016-11-25 23:37:43 +00:00
|
|
|
|
# ‘--set-flag priority’ to manually override the declared priorities.
|
2014-02-26 17:33:13 +00:00
|
|
|
|
nix-env -e '*'
|
|
|
|
|
nix-env -i foo-0.1 foo-1.0
|
2012-12-04 13:47:50 +00:00
|
|
|
|
[ "$($profiles/test/bin/foo)" = "foo-1.0" ]
|
2014-02-26 17:33:13 +00:00
|
|
|
|
nix-env --set-flag priority 1 foo-0.1
|
2012-12-04 13:47:50 +00:00
|
|
|
|
[ "$($profiles/test/bin/foo)" = "foo-0.1" ]
|
2014-02-26 17:42:19 +00:00
|
|
|
|
|
|
|
|
|
# Test nix-env --set.
|
|
|
|
|
nix-env --set $outPath10
|
|
|
|
|
[ "$(nix-store -q --resolve $profiles/test)" = $outPath10 ]
|
|
|
|
|
nix-env --set $drvPath10
|
|
|
|
|
[ "$(nix-store -q --resolve $profiles/test)" = $outPath10 ]
|