1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2025-11-08 11:36:05 +01:00

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.
This commit is contained in:
saygo-png 2025-09-24 22:11:51 +02:00 committed by Austin Horstman
parent 7500458e85
commit 004753ae6b
5 changed files with 21 additions and 8 deletions

View file

@ -91,6 +91,10 @@ in
'';
};
overwriteBackup = mkEnableOption ''
forced overwriting of existing backup files when using `backupFileExtension`
'';
extraSpecialArgs = mkOption {
type = types.attrs;
default = { };

View file

@ -7,15 +7,18 @@
}:
let
inherit (lib) mkIf;
cfg = config.home-manager;
serviceEnvironment =
lib.optionalAttrs (cfg.backupFileExtension != null) {
HOME_MANAGER_BACKUP_EXT = cfg.backupFileExtension;
}
// lib.optionalAttrs cfg.verbose { VERBOSE = "1"; };
serviceEnvironment = lib.mkMerge [
(mkIf cfg.verbose { VERBOSE = "1"; })
(mkIf (cfg.backupFileExtension != null) {
HOME_MANAGER_BACKUP_EXT = cfg.backupFileExtension;
})
(mkIf cfg.overwriteBackup { HOME_MANAGER_BACKUP_OVERWRITE = "1"; })
];
in
{
imports = [ ./common.nix ];
@ -41,7 +44,7 @@ in
];
};
}
(lib.mkIf (cfg.users != { }) {
(mkIf (cfg.users != { }) {
systemd.services = lib.mapAttrs' (
_: usercfg:
let