File tree Expand file tree Collapse file tree 5 files changed +19
-7
lines changed Expand file tree Collapse file tree 5 files changed +19
-7
lines changed Original file line number Diff line number Diff line change 149149 if [[ -e "$targetPath" && ! -L "$targetPath" && -n "$HOME_MANAGER_BACKUP_EXT" ]] ; then
150150 # The target exists, back it up
151151 backup="$targetPath.$HOME_MANAGER_BACKUP_EXT"
152+ if [[ -e "$backup" && -n "$HOME_MANAGER_BACKUP_OVERWRITE" ]]; then
153+ run rm $VERBOSE_ARG "$backup"
154+ fi
152155 run mv $VERBOSE_ARG "$targetPath" "$backup" || errorEcho "Moving '$targetPath' failed!"
153156 fi
154157
Original file line number Diff line number Diff line change @@ -33,8 +33,10 @@ for sourcePath in "$@" ; do
3333 elif [[ ! -L " $targetPath " && -n " $HOME_MANAGER_BACKUP_EXT " ]] ; then
3434 # Next, try to move the file to a backup location if configured and possible
3535 backup=" $targetPath .$HOME_MANAGER_BACKUP_EXT "
36- if [[ -e " $backup " ]] ; then
36+ if [[ -e " $backup " && -z " $HOME_MANAGER_BACKUP_OVERWRITE " ]] ; then
3737 collisionErrors+=(" Existing file '$backup ' would be clobbered by backing up '$targetPath '" )
38+ elif [[ -e " $backup " && -n " $HOME_MANAGER_BACKUP_OVERWRITE " ]] ; then
39+ warnEcho " Existing file '$targetPath ' is in the way of '$sourcePath ' and '$backup ' exists. Backup will be clobbered due to HOME_MANAGER_BACKUP_OVERWRITE=1"
3840 else
3941 warnEcho " Existing file '$targetPath ' is in the way of '$sourcePath ', will be moved to '$backup '"
4042 fi
Original file line number Diff line number Diff line change 2828 ${ lib . optionalString (
2929 cfg . backupFileExtension != null
3030 ) "export HOME_MANAGER_BACKUP_EXT=${ lib . escapeShellArg cfg . backupFileExtension } " }
31+ ${ lib . optionalString cfg . overwriteBackup "export HOME_MANAGER_BACKUP_OVERWRITE=1" }
3132 ${ lib . optionalString cfg . verbose "export VERBOSE=1" }
3233 exec ${ usercfg . home . activationPackage } /activate --driver-version ${ driverVersion } >&2
3334 '' }
Original file line number Diff line number Diff line change 9191 '' ;
9292 } ;
9393
94+ overwriteBackup = mkEnableOption ''
95+ forced overwriting of existing backup files when using `backupFileExtension`'' ;
96+
9497 extraSpecialArgs = mkOption {
9598 type = types . attrs ;
9699 default = { } ;
Original file line number Diff line number Diff line change 77} :
88
99let
10-
10+ inherit ( lib ) mkIf ;
1111 cfg = config . home-manager ;
1212
13- serviceEnvironment =
14- lib . optionalAttrs ( cfg . backupFileExtension != null ) {
13+ serviceEnvironment = lib . mkMerge [
14+ ( mkIf cfg . verbose { VERBOSE = "1" ; } )
15+
16+ ( mkIf ( cfg . backupFileExtension != null ) {
1517 HOME_MANAGER_BACKUP_EXT = cfg . backupFileExtension ;
16- }
17- // lib . optionalAttrs cfg . verbose { VERBOSE = "1" ; } ;
18+ } )
1819
20+ ( mkIf cfg . overwriteBackup { HOME_MANAGER_BACKUP_OVERWRITE = "1" ; } )
21+ ] ;
1922in
2023{
2124 imports = [ ./common.nix ] ;
4144 ] ;
4245 } ;
4346 }
44- ( lib . mkIf ( cfg . users != { } ) {
47+ ( mkIf ( cfg . users != { } ) {
4548 systemd . services = lib . mapAttrs' (
4649 _ : usercfg :
4750 let
You can’t perform that action at this time.
0 commit comments