mirror of
https://github.com/nix-community/home-manager.git
synced 2026-06-05 21:02:51 +00:00
Ensure nix-darwin Home Manager activation preserves DRY_RUN when invoking per-user activation through sudo. Closes #7344
49 lines
1.7 KiB
Nix
49 lines
1.7 KiB
Nix
{
|
|
config,
|
|
lib,
|
|
pkgs,
|
|
...
|
|
}:
|
|
|
|
let
|
|
|
|
cfg = config.home-manager;
|
|
|
|
in
|
|
{
|
|
imports = [ ../nixos/common.nix ];
|
|
|
|
config = lib.mkMerge [
|
|
{ home-manager.extraSpecialArgs.darwinConfig = config; }
|
|
(lib.mkIf (cfg.users != { }) {
|
|
system.activationScripts.postActivation.text = lib.concatStringsSep "\n" (
|
|
lib.mapAttrsToList (
|
|
_username: usercfg:
|
|
let
|
|
driverVersion = if cfg.enableLegacyProfileManagement then "0" else "1";
|
|
in
|
|
''
|
|
echo Activating home-manager configuration for ${usercfg.home.username} >&2
|
|
hmDryRunArgs=()
|
|
hmParentArgs="$(ps -p "$PPID" -ww -o args= || true)"
|
|
if [[ -v DRY_RUN || "$hmParentArgs" == *" --dry-run"* ]]; then
|
|
hmDryRunArgs=(env DRY_RUN=1)
|
|
fi
|
|
launchctl asuser "$(id -u ${usercfg.home.username})" sudo -u ${usercfg.home.username} --set-home "''${hmDryRunArgs[@]}" ${pkgs.writeShellScript "activation-${usercfg.home.username}" ''
|
|
${lib.optionalString (
|
|
cfg.backupFileExtension != null
|
|
) "export HOME_MANAGER_BACKUP_EXT=${lib.escapeShellArg cfg.backupFileExtension}"}
|
|
${lib.optionalString (
|
|
cfg.backupCommand != null
|
|
) "export HOME_MANAGER_BACKUP_COMMAND=${lib.escapeShellArg cfg.backupCommand}"}
|
|
${lib.optionalString cfg.overwriteBackup "export HOME_MANAGER_BACKUP_OVERWRITE=1"}
|
|
${lib.optionalString cfg.verbose "export VERBOSE=1"}
|
|
exec ${usercfg.home.activationPackage}/activate --driver-version ${driverVersion} >&2
|
|
''}
|
|
''
|
|
) cfg.users
|
|
);
|
|
})
|
|
];
|
|
}
|