Skip to content

Commit 072a9c8

Browse files
committed
fix(home): reload session vars in current shell
hmvar-reload was clearing the zsh-specific guard instead of Home Manager's __HM_SESS_VARS_SOURCED guard, so re-sourcing hm-session-vars.sh could return early without refreshing the environment. The previous leading assignment also made the zsh alias compatibility layer wrap the command in bash -c, which meant source ran in a child process. Use unset so zsh sources in-place and keep fish on its dedicated hm-session-vars.fish function path.
1 parent 8ed500c commit 072a9c8

2 files changed

Lines changed: 16 additions & 7 deletions

File tree

modules/home/programs/terminal/shells/alias-compat.nix

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -195,14 +195,21 @@ let
195195
let
196196
trimmed = trim value;
197197
body = if hasWrappedFunction trimmed then unwrapFunctionBody trimmed else trimmed;
198+
sessionVarsPathMatch = builtins.match ".*source \"([^\"]*hm-session-vars\\.sh)\".*" trimmed;
198199
fishSessionVarsPath =
199-
lib.replaceStrings
200-
[ "__HM_ZSH_SESS_VARS_SOURCED=0 source " "hm-session-vars.sh" ]
201-
[ "" "hm-session-vars.fish" ]
202-
trimmed;
200+
if sessionVarsPathMatch != null then
201+
lib.replaceStrings [ "hm-session-vars.sh" ] [ "hm-session-vars.fish" ] (
202+
builtins.elemAt sessionVarsPathMatch 0
203+
)
204+
else
205+
lib.replaceStrings
206+
[ "__HM_ZSH_SESS_VARS_SOURCED=0 source " "hm-session-vars.sh" ]
207+
[ "" "hm-session-vars.fish" ]
208+
trimmed;
203209
in
204210
if name == "hmvar-reload" then
205211
''
212+
set -e __HM_SESS_VARS_SOURCED
206213
if test -f ${fishSessionVarsPath}
207214
source ${fishSessionVarsPath}
208215
end
@@ -220,13 +227,15 @@ in
220227
;
221228

222229
translateAliasMap = lib.mapAttrs (_: translatedAliasValue);
223-
translateFishAliasMap = aliases: lib.filterAttrs (_: value: !(isFishFunctionAlias value)) aliases;
230+
translateFishAliasMap =
231+
aliases:
232+
lib.filterAttrs (name: value: name != "hmvar-reload" && !(isFishFunctionAlias value)) aliases;
224233
translateFishFunctions =
225234
aliases:
226235
lib.mapAttrs' (
227236
name: value:
228237
lib.nameValuePair name {
229238
body = fishBodyForAlias name value;
230239
}
231-
) (lib.filterAttrs (_: isFishFunctionAlias) aliases);
240+
) (lib.filterAttrs (name: value: name == "hmvar-reload" || isFishFunctionAlias value) aliases);
232241
}

modules/home/user/default.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ in
130130
flake = "nix flake";
131131
nix = "nix -vL";
132132
gsed = "${getExe pkgs.gnused}";
133-
hmvar-reload = ''__HM_ZSH_SESS_VARS_SOURCED=0 source "/etc/profiles/per-user/${config.khanelinix.user.name}/etc/profile.d/hm-session-vars.sh"'';
133+
hmvar-reload = ''unset __HM_SESS_VARS_SOURCED; source "/etc/profiles/per-user/${config.khanelinix.user.name}/etc/profile.d/hm-session-vars.sh"'';
134134

135135
# File management
136136
rcp = "${getExe pkgs.rsync} -rahP --mkpath --modify-window=1"; # Rsync copy keeping all attributes,timestamps,permissions"

0 commit comments

Comments
 (0)