From b8c7947a7aeaf473fce5f9d2d9dc04b4df907515 Mon Sep 17 00:00:00 2001 From: e-nikolov Date: Fri, 8 Sep 2023 07:02:56 +0200 Subject: [PATCH] home-manager: improve nix profile detection If `nix.settings.use-xdg-base-directories` is true, the `~/.nix-profile` directory may not exist, and `home.profileDirectory` should be checked instead. Co-authored-by: Bruno BELANYI --- home-manager/home-manager | 8 +++++++- modules/home-environment.nix | 6 +++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/home-manager/home-manager b/home-manager/home-manager index 6f2ba38b6..2549cc57d 100644 --- a/home-manager/home-manager +++ b/home-manager/home-manager @@ -29,7 +29,9 @@ function removeByName() { } function setNixProfileCommands() { - if [[ -e $HOME/.nix-profile/manifest.json ]] ; then + if [[ -e $HOME/.nix-profile/manifest.json \ + || -e ${XDG_STATE_HOME:-$HOME/.local/state}/nix/profile/manifest.json ]] ; then + LIST_OUTPATH_CMD="nix profile list" REMOVE_CMD="removeByName" else @@ -406,6 +408,10 @@ $xdgVars # # or # + # ~/.local/state/nix/profiles/profile/etc/profile.d/hm-session-vars.sh + # + # or + # # /etc/profiles/per-user/$USER/etc/profile.d/hm-session-vars.sh # home.sessionVariables = { diff --git a/modules/home-environment.nix b/modules/home-environment.nix index 870464608..03e32c087 100644 --- a/modules/home-environment.nix +++ b/modules/home-environment.nix @@ -175,7 +175,7 @@ in done automatically if the shell configuration is managed by Home Manager. If not, then you must source the - ~/.nix-profile/etc/profile.d/hm-session-vars.sh + ${cfg.profileDirectory}/etc/profile.d/hm-session-vars.sh file yourself. '') @@ -585,7 +585,7 @@ in if config.submoduleSupport.externalPackageInstall then '' - if [[ -e $HOME/.nix-profile/manifest.json ]] ; then + if [[ -e ${cfg.profileDirectory}/manifest.json ]] ; then nix profile list \ | { grep 'home-manager-path$' || test $? = 1; } \ | cut -d ' ' -f 4 \ @@ -623,7 +623,7 @@ in $DRY_RUN_CMD $oldNix profile install $1 } - if [[ -e $HOME/.nix-profile/manifest.json ]] ; then + if [[ -e ${cfg.profileDirectory}/manifest.json ]] ; then INSTALL_CMD="nix profile install" INSTALL_CMD_ACTUAL="nixReplaceProfile" LIST_CMD="nix profile list"