Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions modules/files.nix
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ in
if [[ -e "$targetPath" && ! -L "$targetPath" && -n "$HOME_MANAGER_BACKUP_EXT" ]] ; then
# The target exists, back it up
backup="$targetPath.$HOME_MANAGER_BACKUP_EXT"
if [[ -e "$backup" && -n "$HOME_MANAGER_BACKUP_OVERWRITE" ]]; then
run rm $VERBOSE_ARG "$backup"
fi
run mv $VERBOSE_ARG "$targetPath" "$backup" || errorEcho "Moving '$targetPath' failed!"
fi

Expand Down
4 changes: 3 additions & 1 deletion modules/files/check-link-targets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ for sourcePath in "$@" ; do
elif [[ ! -L "$targetPath" && -n "$HOME_MANAGER_BACKUP_EXT" ]] ; then
# Next, try to move the file to a backup location if configured and possible
backup="$targetPath.$HOME_MANAGER_BACKUP_EXT"
if [[ -e "$backup" ]]; then
if [[ -e "$backup" && -z "$HOME_MANAGER_BACKUP_OVERWRITE" ]] ; then
collisionErrors+=("Existing file '$backup' would be clobbered by backing up '$targetPath'")
elif [[ -e "$backup" && -n "$HOME_MANAGER_BACKUP_OVERWRITE" ]] ; then
warnEcho "Existing file '$targetPath' is in the way of '$sourcePath' and '$backup' exists. Backup will be clobbered due to HOME_MANAGER_BACKUP_OVERWRITE=1"
else
warnEcho "Existing file '$targetPath' is in the way of '$sourcePath', will be moved to '$backup'"
fi
Expand Down
1 change: 1 addition & 0 deletions nix-darwin/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ in
${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
''}
Expand Down
4 changes: 4 additions & 0 deletions nixos/common.nix
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ in
'';
};

overwriteBackup = mkEnableOption ''
forced overwriting of existing backup files when using `backupFileExtension`
'';

extraSpecialArgs = mkOption {
type = types.attrs;
default = { };
Expand Down
15 changes: 9 additions & 6 deletions nixos/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@
}:

let

inherit (lib) mkIf;
cfg = config.home-manager;

serviceEnvironment =
lib.optionalAttrs (cfg.backupFileExtension != null) {
serviceEnvironment = lib.mkMerge [
(mkIf cfg.verbose { VERBOSE = "1"; })

(mkIf (cfg.backupFileExtension != null) {
HOME_MANAGER_BACKUP_EXT = cfg.backupFileExtension;
}
// lib.optionalAttrs cfg.verbose { VERBOSE = "1"; };
})

(mkIf cfg.overwriteBackup { HOME_MANAGER_BACKUP_OVERWRITE = "1"; })
];
in
{
imports = [ ./common.nix ];
Expand All @@ -41,7 +44,7 @@ in
];
};
}
(lib.mkIf (cfg.users != { }) {
(mkIf (cfg.users != { }) {
systemd.services = lib.mapAttrs' (
_: usercfg:
let
Expand Down