mirror of
https://github.com/nix-community/home-manager
synced 2024-11-23 05:03:09 +00:00
home-manager: handle profile list in Nix >2.17
Nix 2.17 changed the format of the `nix profile list` output. This commit adds support for parsing the new JSON profile list format. Fixes #4298
This commit is contained in:
parent
406d34d919
commit
c3ab5ea047
3 changed files with 36 additions and 10 deletions
|
@ -1,4 +1,4 @@
|
||||||
{ runCommand, lib, bash, callPackage, coreutils, findutils, gettext, gnused
|
{ runCommand, lib, bash, callPackage, coreutils, findutils, gettext, gnused, jq
|
||||||
, less, ncurses, unixtools
|
, less, ncurses, unixtools
|
||||||
# used for pkgs.path for nixos-option
|
# used for pkgs.path for nixos-option
|
||||||
, pkgs
|
, pkgs
|
||||||
|
@ -34,6 +34,7 @@ in runCommand "home-manager" {
|
||||||
findutils
|
findutils
|
||||||
gettext
|
gettext
|
||||||
gnused
|
gnused
|
||||||
|
jq
|
||||||
less
|
less
|
||||||
ncurses
|
ncurses
|
||||||
nixos-option
|
nixos-option
|
||||||
|
|
|
@ -11,11 +11,21 @@ export TEXTDOMAINDIR=@OUT@/share/locale
|
||||||
# shellcheck disable=1091
|
# shellcheck disable=1091
|
||||||
source @HOME_MANAGER_LIB@
|
source @HOME_MANAGER_LIB@
|
||||||
|
|
||||||
function removeByName() {
|
function nixProfileList() {
|
||||||
|
# We attempt to use `--json` first (added in Nix 2.17). Otherwise attempt to
|
||||||
|
# parse the legacy output format.
|
||||||
|
{
|
||||||
|
nix profile list --json 2>/dev/null \
|
||||||
|
| jq -r --arg name "$1" '.elements[].storePaths[] | select(endswith($name))'
|
||||||
|
} || {
|
||||||
nix profile list \
|
nix profile list \
|
||||||
| { grep "$1" || test $? = 1; } \
|
| { grep "$1\$" || test $? = 1; } \
|
||||||
| cut -d ' ' -f 4 \
|
| cut -d ' ' -f 4
|
||||||
| xargs -t $DRY_RUN_CMD nix profile remove $VERBOSE_ARG
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function removeByName() {
|
||||||
|
nixProfileList "$1" | xargs -t $DRY_RUN_CMD nix profile remove $VERBOSE_ARG
|
||||||
}
|
}
|
||||||
|
|
||||||
function setNixProfileCommands() {
|
function setNixProfileCommands() {
|
||||||
|
|
|
@ -598,13 +598,27 @@ in
|
||||||
''
|
''
|
||||||
else
|
else
|
||||||
''
|
''
|
||||||
|
function nixProfileList() {
|
||||||
|
# We attempt to use `--json` first (added in Nix 2.17). Otherwise attempt to
|
||||||
|
# parse the legacy output format.
|
||||||
|
{
|
||||||
|
nix profile list --json 2>/dev/null \
|
||||||
|
| jq -r --arg name "$1" '.elements[].storePaths[] | select(endswith($name))'
|
||||||
|
} || {
|
||||||
|
nix profile list \
|
||||||
|
| { grep "$1\$" || test $? = 1; } \
|
||||||
|
| cut -d ' ' -f 4
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function nixRemoveProfileByName() {
|
||||||
|
nixProfileList "$1" | xargs -t $DRY_RUN_CMD nix profile remove $VERBOSE_ARG
|
||||||
|
}
|
||||||
|
|
||||||
function nixReplaceProfile() {
|
function nixReplaceProfile() {
|
||||||
local oldNix="$(command -v nix)"
|
local oldNix="$(command -v nix)"
|
||||||
|
|
||||||
nix profile list \
|
nixRemoveProfileByName 'home-manager-path'
|
||||||
| { grep 'home-manager-path$' || test $? = 1; } \
|
|
||||||
| cut -d ' ' -f 4 \
|
|
||||||
| xargs -t $DRY_RUN_CMD nix profile remove $VERBOSE_ARG
|
|
||||||
|
|
||||||
$DRY_RUN_CMD $oldNix profile install $1
|
$DRY_RUN_CMD $oldNix profile install $1
|
||||||
}
|
}
|
||||||
|
@ -626,7 +640,7 @@ in
|
||||||
_iError $'Oops, Nix failed to install your new Home Manager profile!\n\nPerhaps there is a conflict with a package that was installed using\n"%s"? Try running\n\n %s\n\nand if there is a conflicting package you can remove it with\n\n %s\n\nThen try activating your Home Manager configuration again.' "$INSTALL_CMD" "$LIST_CMD" "$REMOVE_CMD_SYNTAX"
|
_iError $'Oops, Nix failed to install your new Home Manager profile!\n\nPerhaps there is a conflict with a package that was installed using\n"%s"? Try running\n\n %s\n\nand if there is a conflicting package you can remove it with\n\n %s\n\nThen try activating your Home Manager configuration again.' "$INSTALL_CMD" "$LIST_CMD" "$REMOVE_CMD_SYNTAX"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
unset -f nixReplaceProfile
|
unset -f nixProfileList nixRemoveProfileByName nixReplaceProfile
|
||||||
unset INSTALL_CMD INSTALL_CMD_ACTUAL LIST_CMD REMOVE_CMD_SYNTAX
|
unset INSTALL_CMD INSTALL_CMD_ACTUAL LIST_CMD REMOVE_CMD_SYNTAX
|
||||||
''
|
''
|
||||||
);
|
);
|
||||||
|
@ -678,6 +692,7 @@ in
|
||||||
gettext
|
gettext
|
||||||
gnugrep
|
gnugrep
|
||||||
gnused
|
gnused
|
||||||
|
jq
|
||||||
ncurses # For `tput`.
|
ncurses # For `tput`.
|
||||||
]
|
]
|
||||||
++ config.home.extraActivationPath
|
++ config.home.extraActivationPath
|
||||||
|
|
Loading…
Reference in a new issue