"Existing file ... is in the way of ..." issue with home-manager when used in a configuration

I use home-manager in a NixOS configuration. When I do nixos-rebuild switch --flake, I frequently get these:

Existing file '/home/icyrockcom/.config/gtk-4.0/gtk.css' is in the way of '/nix/store/rxcgimxlbcn1ngyl86v1ylsyzmpd21fk-home-manager-files/.config/gtk-4.0/gtk.css'

Doing rm /home/icyrockcom/.config/gtk-4.0/gtk.css and re-doing nixos-rebuild switch --flake fixes.

Is there a way to tell home-manager to overwrite a certain file (or anything under a certain folder) always?

1 Like

You can tell it to always use the -b flag: Appendix B. NixOS Configuration Options

A more proper solution would be to find out which application is overwriting this file after installation and making it not do that.

1 Like

Ah, got it, that’s the equivalent of the suggested -b command line option.

There’s no way to apply this on a per-file basis? I.e. if there are two files that home-manager manages, I may care about one file not being changed (and the rebuild failing in this case) and not care about the other file (and the rebuild making a backup and putting the new file there instead).

For example, I may care about my ~/.bashrc and not want that silently backed up + overwritten if it gets changed for whatever reason. On the other hand, I don’t really care about the above ~/.config/gtk-4.0/gtk.css.

Not really to my knowledge. Maybe there’s appetite for adding that as a feature upstream?

Alternatives are fixing the problem, or perhaps deleting that file in an activation snippet.

1 Like

Certain home manager modules do have an effectively per-file “force” flag, like programs.firefox.profiles.<name>.containersForce and programs.firefox.profiles.<name>.search.force.

It’s important to note that the control here is inverted – it’s coming from the program and not the file.

Per-file implementation could theoretically be done like in this commit that implements Firefox container file overwriting.

3 Likes