diff --git a/modules/home-environment.nix b/modules/home-environment.nix index 29474339..e5b6cc3a 100644 --- a/modules/home-environment.nix +++ b/modules/home-environment.nix @@ -264,6 +264,17 @@ in ''; }; + home.sessionPath = mkOption { + type = with types; listOf str; + default = [ ]; + example = [ + ".git/safe/../../bin" + "\${xdg.configHome}/emacs/bin" + "~/.local/bin" + ]; + description = "Extra directories to add to PATH."; + }; + home.sessionVariablesExtra = mkOption { type = types.lines; default = ""; @@ -446,6 +457,8 @@ in export __HM_SESS_VARS_SOURCED=1 ${config.lib.shell.exportAll cfg.sessionVariables} + '' + lib.optionalString (cfg.sessionPath != [ ]) '' + export PATH="$PATH''${PATH:+:}${concatStringsSep ":" cfg.sessionPath}" '' + cfg.sessionVariablesExtra; } ) diff --git a/tests/modules/home-environment/default.nix b/tests/modules/home-environment/default.nix index 2a1201a2..e76e248a 100644 --- a/tests/modules/home-environment/default.nix +++ b/tests/modules/home-environment/default.nix @@ -1,3 +1,4 @@ { home-session-variables = ./session-variables.nix; + home-session-path = ./session-path.nix; } diff --git a/tests/modules/home-environment/session-path.nix b/tests/modules/home-environment/session-path.nix new file mode 100644 index 00000000..3b40059e --- /dev/null +++ b/tests/modules/home-environment/session-path.nix @@ -0,0 +1,27 @@ +{ config, lib, pkgs, ... }: + +{ + imports = [ + ({ ... }: { config.home.sessionPath = [ "foo" ]; }) + ({ ... }: { config.home.sessionPath = [ "bar" "baz" ]; }) + ]; + + nmt.script = '' + assertFileExists home-path/etc/profile.d/hm-session-vars.sh + assertFileContent \ + home-path/etc/profile.d/hm-session-vars.sh \ + ${ + pkgs.writeText "session-path-expected.txt" '' + # Only source this once. + if [ -n "$__HM_SESS_VARS_SOURCED" ]; then return; fi + export __HM_SESS_VARS_SOURCED=1 + + export XDG_CACHE_HOME="/home/hm-user/.cache" + export XDG_CONFIG_HOME="/home/hm-user/.config" + export XDG_DATA_HOME="/home/hm-user/.local/share" + export PATH="$PATH''${PATH:+:}bar:baz:foo" + '' + } + ''; + +}