home-environment: add option `home.sessionPath`

This option allows adding additional entries to `PATH`.
This commit is contained in:
Andrew Fontaine 2020-05-30 17:16:54 -04:00 committed by Robert Helgesson
parent 9ff2188c5d
commit 0006da1381
No known key found for this signature in database
GPG Key ID: 36BDAA14C2797E89
3 changed files with 41 additions and 0 deletions

View File

@ -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 <envar>PATH</envar>.";
};
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;
}
)

View File

@ -1,3 +1,4 @@
{
home-session-variables = ./session-variables.nix;
home-session-path = ./session-path.nix;
}

View File

@ -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"
''
}
'';
}