nix-community / home-manager

Manage a user environment using Nix [maintainer=@rycee]
https://nix-community.github.io/home-manager/
MIT License
6.68k stars 1.75k forks source link

HM target conflict using `home.file.<target>.source = <source_path>;` #5539

Closed trya2l closed 2 months ago

trya2l commented 3 months ago

Are you following the right branch?

Is there an existing issue for this?

Issue description

Hi,

I am new to Nixos, and I am trying to find a way to manage my dotfiles using HM.

For the time being, I'd like to link my config files instead of writing everything with HM options.

However, it is more difficult than I thought.

I was planning to set my sway config like this:

home.file = {
  "~/.config/sway/config".source = ~/dotfiles/sway/config;
};

but this brings a conflict with an (idk how) autogenerated sway config file: .config/sway/config -> /nix/store/gwi1bip1vm74g01a8f62r73yhlps1vpk-home-manager-files/.config/sway/config

Hence, I get this error during home-manager switch

       error:
       Failed assertions:
       - Conflicting managed target files: .config/sway/config

       This may happen, for example, if you have a configuration similar to

           home.file = {
             conflict1 = { source = ./foo.nix; target = "baz"; };
             conflict2 = { source = ./bar.nix; target = "baz"; };
           }

Also, sway is enable in HM with this line wayland.windowManager.sway.enable = true;

I would reaallly appreciate some pointers.

Thanks!

Maintainer CC

No response

System information

 - system: `"x86_64-linux"`
 - host os: `Linux 6.6.33, NixOS, 24.05 (Uakari), 24.05.1409.cc54fb41d137`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.18.2`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`
testplayername commented 2 months ago

The file conflict happens because Home Manager's sway module, when enabled with wayland.windowManager.sway.enable = true;, automatically generates a ~/.config/sway/config file via xdg.configFile."sway/config": https://github.com/nix-community/home-manager/blob/0a7ffb28e5df5844d0e8039c9833d7075cdee792/modules/services/window-managers/i3-sway/sway.nix#L525C5-L533C9

xdg.configFile."sway/config" can be disabled with:

xdg.configFile."sway/config".enable = false;

This should stop Home Manager's sway module from creating ~/.config/sway/config and allow your own home.file definition to totally control the contents of ~/.config/sway/config.

trya2l commented 2 months ago

I had found a workaround using configuration.nix but this helps me to better understand Nixos and Linux. Thanks!