Skip to content

Conversation

@saygo-png
Copy link
Contributor

Description

Closes #4199.

When using the backupFileExtension option, if the backup file exists, the activation process fails. This adds an opt in option to instead overwrite the old backup instead of failing.

This feature is highly requested, the issue above is the 6th most liked issue on the tracker.

I have not added a help text mentioning this option on collision to be conservative. This setting removes data, so I don't think suggesting it for any collision is responsible.

There was a previous attempt at implementing this here #4971 but the contributor gave up due to opposition to overwriting data. Since then Hjem (A minimal home-manager alternative) has implemented a very similar feature https://hjem.feel-co.org/options.html#option-hjem-clobberByDefault.

With Hjem setting the precedent, and it being one of the most requested features (judging by reactions) I hope this change can receive more favorable second look.

Checklist

  • Change is backwards compatible.

  • Code formatted with nix fmt or
    nix-shell -p treefmt nixfmt deadnix keep-sorted --run treefmt.

  • Code tested through nix run .#tests -- test-all or
    nix-shell --pure tests -A run.all.
    (It was taking too long due to my slow connection)

  • Test cases updated/added. See example.

  • Commit messages are formatted like

    {component}: {description}
    
    {long description}
    

    See CONTRIBUTING for more information and recent commit messages for examples.

  • If this PR adds a new module

    • Added myself as module maintainer. See example.
    • Generate a news entry. See News
    • Basic tests added. See Tests
  • If this PR adds an exciting new feature or contains a breaking change.

    • Generate a news entry. See News

@khaneliman
Copy link
Collaborator

I did have pretty much the exact same change earlier this year, too. #6491

@saygo-png
Copy link
Contributor Author

I did have pretty much the exact same change earlier this year,

I missed that! Looks like the objection was to this overwriting backups. I would be okay with just overwriting the files directly — this is what Hjem does but I'm guessing @teto would object to this too. If we really don't want this I can compromise on generating multiple backups (though i'd rather not) but Teto seems to be against this too... #6243 (comment)

I know about force and it is not an adequate solution. It only allows you to set that per file which still allows for random programs to break home manager activation unless you force every file.

To put this into perspective, many NixOS users wipe most of their $HOME on reboot with impermanence (including me). Overwriting config files that are mostly autogenerated (its unlikely a user causes multiple backups by hand) is really not a big deal. Once again this is opt in with a clear name — anyone turning this option on will be aware of potential data loss.

@khaneliman
Copy link
Collaborator

Yeah, I'm leaning towards an opt in feature makes sense. It harms no one unexpectedly since you have to choose to do so.

Copy link
Member

@rycee rycee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough, I think it's worth trying and see if it fulfills peoples' needs.

When using the backupFileExtension option, if the backup file exists,
the activation process fails. This adds an option to instead overwrite
the old backup instead of failing.
@khaneliman khaneliman merged commit 004753a into nix-community:master Oct 1, 2025
7 checks passed
@saygo-png
Copy link
Contributor Author

Thank you so much!!!

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.

Add option to replace existing files

3 participants