darwin: Set launchd.user.envVariables from home.sessionVariables

This allows to have consistent environment for both (gui) apps started
by launchd and shell programs.

Closes: https://github.com/LnL7/nix-darwin/issues/1056
Signed-off-by: Ihar Hrachyshka <ihar.hrachyshka@gmail.com>
This commit is contained in:
Ihar Hrachyshka 2024-09-05 21:01:13 -04:00
parent 471e3eb0a1
commit 130f429bf4

View file

@ -11,21 +11,28 @@ in {
config = mkMerge [
{ home-manager.extraSpecialArgs.darwinConfig = config; }
(mkIf (cfg.users != { }) {
system.activationScripts.postActivation.text = concatStringsSep "\n"
(mapAttrsToList (username: usercfg: ''
echo Activating home-manager configuration for ${username}
sudo -u ${username} --set-home ${
pkgs.writeShellScript "activation-${username}" ''
${lib.optionalString (cfg.backupFileExtension != null)
"export HOME_MANAGER_BACKUP_EXT=${
lib.escapeShellArg cfg.backupFileExtension
}"}
${lib.optionalString cfg.verbose "export VERBOSE=1"}
exec ${usercfg.home.activationPackage}/activate
''
}
'') cfg.users);
})
(mkIf (cfg.users != { }) (mkMerge [
{
system.activationScripts.postActivation.text = concatStringsSep "\n"
(mapAttrsToList (username: usercfg: ''
echo Activating home-manager configuration for ${username}
sudo -u ${username} --set-home ${
pkgs.writeShellScript "activation-${username}" ''
${lib.optionalString (cfg.backupFileExtension != null)
"export HOME_MANAGER_BACKUP_EXT=${
lib.escapeShellArg cfg.backupFileExtension
}"}
${lib.optionalString cfg.verbose "export VERBOSE=1"}
exec ${usercfg.home.activationPackage}/activate
''
}
'') cfg.users);
}
{
launchd.user.envVariables = mkMerge (map (usercfg:
mapAttrs (name: value: toString value) usercfg.home.sessionVariables)
(attrValues cfg.users));
}
]))
];
}