home-manager icon indicating copy to clipboard operation
home-manager copied to clipboard

home-manager: add support for custom backup command (#6424)

Open cdo256 opened this issue 11 months ago • 1 comments

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 backupCommand option to NixOS and nix-darwin modules.
  • Exports HOME_MANAGER_BACKUP_COMMAND environment 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 variable HOME_MANAGER_BACKUP_COMMAND is used.
  • [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

cdo256 avatar May 28 '25 20:05 cdo256

That looks very good! I think this should have been done a long time ago.

aguirre-matteo avatar Jun 08 '25 00:06 aguirre-matteo

I've rebased my commit onto master. Please let me know if there are any blockers to merging this.

cdo256 avatar Sep 01 '25 21:09 cdo256

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.

aguirre-matteo avatar Sep 01 '25 21:09 aguirre-matteo

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.

cdo256 avatar Oct 08 '25 15:10 cdo256

I've resolved the most recent conflicts. Is there anything left to do before this can be merged?

cdo256 avatar Oct 20 '25 11:10 cdo256

Sorry, forgot to ask if you could add a news entry for the new option.

khaneliman avatar Oct 29 '25 02:10 khaneliman

Thank you very much for merging this!

cdo256 avatar Oct 30 '25 20:10 cdo256