home-manager: add support for custom backup command (#6424) #7153
+38
−7
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR adds support for a custom backup command in Home Manager.
A new
backupCommand
option is introduced, allowing users to specify a shell command to run on existing files that would otherwise block activation (e.g., moving files to trash, archiving, or custom backup logic). If set, this command is used in preference to the existingbackupFileExtension
mechanism.backupCommand
option to NixOS and nix-darwin modules.HOME_MANAGER_BACKUP_COMMAND
environment variable when set.This enables more flexible and user-defined backup workflows during Home Manager activations.
This resolves Optional user defined script for error handling in case of home-manager backup file already existing #6424.
Checklist
Change is backwards compatible.
backupCommand
, or the new environment variableHOME_MANAGER_BACKUP_COMMAND
is used.Code formatted.
Code tested.
Test cases updated/added. See example.
Commit messages formatted.
If this PR adds a new module...
. N/A
Maintainer CC
N/A