mirror of
https://github.com/nix-community/home-manager
synced 2024-11-23 03:29:45 +01:00
nixos: import existing environment during activation
If the user has a running systemd session, source their environment from the systemd manager and export a few variables in order to allow activation scripts to reload applications on the fly. The list of variables to export is arbitrary and could be extended in the future. Fixes #1399, fixes #2112.
This commit is contained in:
parent
eee807560b
commit
b0651cc217
1 changed files with 29 additions and 4 deletions
|
@ -144,10 +144,35 @@ in {
|
|||
TimeoutStartSec = 90;
|
||||
SyslogIdentifier = "hm-activate-${username}";
|
||||
|
||||
# The activation script is run by a login shell to make sure
|
||||
# that the user is given a sane Nix environment.
|
||||
ExecStart =
|
||||
"${pkgs.runtimeShell} -l ${usercfg.home.activationPackage}/activate";
|
||||
ExecStart = let
|
||||
systemctl =
|
||||
"XDG_RUNTIME_DIR=\${XDG_RUNTIME_DIR:-/run/user/$UID} systemctl";
|
||||
|
||||
sed = "${pkgs.gnused}/bin/sed";
|
||||
|
||||
exportedSystemdVariables = concatStringsSep "|" [
|
||||
"DBUS_SESSION_BUS_ADDRESS"
|
||||
"DISPLAY"
|
||||
"WAYLAND_DISPLAY"
|
||||
"XAUTHORITY"
|
||||
"XDG_RUNTIME_DIR"
|
||||
];
|
||||
|
||||
setupEnv = pkgs.writeScript "hm-setup-env" ''
|
||||
#! ${pkgs.runtimeShell} -el
|
||||
|
||||
# The activation script is run by a login shell to make sure
|
||||
# that the user is given a sane environment.
|
||||
# If the user is logged in, import variables from their current
|
||||
# session environment.
|
||||
eval "$(
|
||||
${systemctl} --user show-environment 2> /dev/null \
|
||||
| ${sed} -En '/^(${exportedSystemdVariables})=/s/^/export /p'
|
||||
)"
|
||||
|
||||
exec "$1/activate"
|
||||
'';
|
||||
in "${setupEnv} ${usercfg.home.activationPackage}";
|
||||
};
|
||||
}) cfg.users;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue