Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

cdo256
Copy link

@cdo256 cdo256 commented May 28, 2025

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

  • Change is backwards compatible.

    • Behaviour is only changed if the new option backupCommand, or the new environment variable HOME_MANAGER_BACKUP_COMMAND is used.
  • Code formatted.

  • Code tested.

  • Test cases updated/added. See example.

    • Requires additional integration test for backing up files generally.
  • Commit messages formatted.

  • If this PR adds a new module...
    . N/A

Maintainer CC

N/A

This adds a new backupCommand option to allow users to specify a
custom command to run on existing files during activation, as an
alternative to the existing backupFileExtension mechanism.

Adds backupCommand option to NixOS and nix-darwin modules.

Exports HOME_MANAGER_BACKUP_COMMAND environment variable when set.

Updates file activation logic to use the custom backup command if
provided, falling back to the existing backup extension logic.

Updates collision checking and user-facing instructions to
mention the new option.

This enables advanced backup workflows, such as moving files to
trash or archiving with custom tools, before managing them with
Home Manager.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Optional user defined script for error handling in case of home-manager backup file already existing
1 participant