2.home-manager/nix-darwin/default.nix
saygo-png 004753ae6b
Some checks failed
/ triage (push) Has been cancelled
GitHub Pages / publish (ubuntu-latest) (push) Has been cancelled
home-manager: add backup overwrite option
When using the backupFileExtension option, if the backup file exists,
the activation process fails. This adds an option to instead overwrite
the old backup instead of failing.
2025-10-01 11:45:00 -05:00

40 lines
1.2 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
launchctl asuser "$(id -u ${usercfg.home.username})" sudo -u ${usercfg.home.username} --set-home ${pkgs.writeShellScript "activation-${usercfg.home.username}" ''
${lib.optionalString (
cfg.backupFileExtension != null
) "export HOME_MANAGER_BACKUP_EXT=${lib.escapeShellArg cfg.backupFileExtension}"}
${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
);
})
];
}