1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-25 06:31:14 +02:00

nix-env: add a --priority flag to --install

nix-env can read priorities from a derivations meta attributes, but this
only works when installing a nix expression.

nix-env can also install bare store paths, however meta attributes are
not readable in that case. This means that a store path can not be
installed with a specific priority.

Some cases where it is advantageous to install a store path: a remote
host following a `nix copy`, or any time you want to save some
evaluation time and happen to already know the store path.

This PR addresses this shortcoming by adding a --priority flag to
nix-env --install.
This commit is contained in:
Andy Hamon 2025-01-16 00:24:47 -08:00
parent 0c101679b4
commit 3716ded8df
3 changed files with 37 additions and 14 deletions

View file

@ -173,13 +173,21 @@ nix-env -q '*' | grepQuiet bar-0.1.1
# 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.
# '-i --priority' and '--set-flag priority' to manually override the
# declared priorities.
nix-env -e '*'
nix-env -i foo-0.1 foo-1.0
[ "$($profiles/test/bin/foo)" = "foo-1.0" ]
nix-env --set-flag priority 1 foo-0.1
[ "$($profiles/test/bin/foo)" = "foo-0.1" ]
# Priorities can be overridden with the --priority flag
nix-env -e '*'
nix-env -i foo-1.0
[ "$($profiles/test/bin/foo)" = "foo-1.0" ]
nix-env -i --priority 1 foo-0.1
[ "$($profiles/test/bin/foo)" = "foo-0.1" ]
# Test nix-env --set.
nix-env --set $outPath10
[ "$(nix-store -q --resolve $profiles/test)" = $outPath10 ]