nix-community / home-manager

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

bug: home.file doesn't work when using home-manager as a module in a nixos system #5519

Open bonds opened 4 weeks ago

bonds commented 4 weeks ago

Are you following the right branch?

Is there an existing issue for this?

Issue description

home.file won't create a file and symlink when I use home-manager as a module in a nixos config and running sudo nixos-rebuild switch --flake . The rebuild runs fine except for home.file, which fails quietly. I note that home.packages and other home dot config works fine, so home.nix does seem to be operating in general, it's just home.file that's not working.

The specific nix config in question can be seen here: https://github.com/bonds/dotfiles/tree/58bdcaffaf5cd40eee1796c708effd28b0807b4e/.config/nix

Maintainer CC

No response

System information

~/.config/nix on  main 
at 14:03:03 🆇 1 ❄️ ❯  nix-shell -p nix-info --run "nix-info -m"
warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels' does not exist, ignoring
 - system: `"x86_64-linux"`
 - host os: `Linux 6.6.32, NixOS, 24.05 (Uakari), 24.05.20240606.9b5328b`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.18.2`
 - nixpkgs: `/nix/store/x887lkxvgnrrcfgrzz351qhfvvrkm80x-source`
kbwhodat commented 3 weeks ago

I'm facing the same issue as well, but for nix-darwin. I thought I solved it by downgrading versions. But no luck. Are there any workaround for this?

bonds commented 4 days ago

I think I found something. Manually running the home manager script generated after running nixos-rebuild switch I see this:

at 12:16:49 ❄️ ❯  /nix/store/7i0d80cp7l2f3kzphp2pgl75f8k9bqal-hm-setup-env /nix/store/3wxnh4nrqifbxswim1awibrcssxg040v-home-manager-generation
Starting Home Manager activation
Activating checkFilesChanged
Activating checkLinkTargets
Existing file '/home/scott/.config/autostart/ulauncher.desktop' is in the way of '/nix/store/gsskllgsxxhikiv109lybnv6bgk12bzm-home-manager-files/.config/autostart/ulauncher.desktop'
Existing file '/home/scott/.local/share/applications/dwarf.desktop' is in the way of '/nix/store/gsskllgsxxhikiv109lybnv6bgk12bzm-home-manager-files/.local/share/applications/dwarf.desktop'
Please do one of the following:
- Move or remove the above files and try again.
- In standalone mode, use 'home-manager switch -b backup' to back up
  files automatically.
- When used as a NixOS or nix-darwin module, set
    'home-manager.backupFileExtension'
  to, for example, 'backup' and rebuild.

It seems that home manager errors out without reporting the problem to nixos-rebulid, so it's silently failing. I am able to fix the problem as it suggested, and then when I run nixos-rebuild switch, the home.files module works fine. So I think the bug here is the failing silently part...it would be better if home manager told nixos that there was an error and what the problem is, so that nixos-rebuild switch can error out and report the problem, rather than partially working and partially not working.