home-manager: add support for custom backup command (#6424)
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 existing backupFileExtension mechanism.
- Adds
backupCommandoption to NixOS and nix-darwin modules. - Exports
HOME_MANAGER_BACKUP_COMMANDenvironment variable when set. - Updates activation logic to invoke the custom backup command if provided.
- Updates collision checking and user-facing instructions to document the new option.
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
-
[x] Change is backwards compatible.
- Behaviour is only changed if the new option
backupCommand, or the new environment variableHOME_MANAGER_BACKUP_COMMANDis used.
- Behaviour is only changed if the new option
-
[x] Code formatted.
-
[x] Code tested.
-
[ ] Test cases updated/added. See example.
- Requires additional integration test for backing up files generally.
-
[x] Commit messages formatted.
-
If this PR adds a new module... . N/A
Maintainer CC
N/A
That looks very good! I think this should have been done a long time ago.
I've rebased my commit onto master. Please let me know if there are any blockers to merging this.
To me, it seems like you merged the master instead of rebasing, since the commit history says there are two commits.
EDIT: What I mean is, that in a rebase you HAVE TO force push and the commit history would show only one commit.
EDIT2: Maybe just squash the commits last two commits so they are seen as a single one.
Apoligies for the long delay, I've been focussing on my dissertation and neglected to check my GitHub notifications. I've pushed a new version that should address all of those points.
I've resolved the most recent conflicts. Is there anything left to do before this can be merged?
Sorry, forgot to ask if you could add a news entry for the new option.
Thank you very much for merging this!