mirror of
https://github.com/nix-community/home-manager.git
synced 2026-01-11 17:39:37 +08:00
home-environment: add option home.sessionPath
This option allows adding additional entries to `PATH`.
This commit is contained in:
committed by
Robert Helgesson
parent
9ff2188c5d
commit
0006da1381
@@ -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;
|
||||
}
|
||||
)
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
{
|
||||
home-session-variables = ./session-variables.nix;
|
||||
home-session-path = ./session-path.nix;
|
||||
}
|
||||
|
||||
27
tests/modules/home-environment/session-path.nix
Normal file
27
tests/modules/home-environment/session-path.nix
Normal 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"
|
||||
''
|
||||
}
|
||||
'';
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user