nix-community / home-manager

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

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

Open bonds opened 5 months ago

bonds commented 5 months 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 5 months 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 5 months 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.

Vortriz commented 4 months ago

I am facing a similar issue. I want add something to the end of .bashrc by

home.file.".bashrc".text = ''
    eval "$(direnv hook bash)"
'';

There are no errors in nixos-rebuild and the contents are also not appended to .bashrc.

EDIT: I disabled bash using programs.bash.enable = false; and now it did append. So is this taking precedence over home.file?

stale[bot] commented 1 month ago

Thank you for your contribution! I marked this issue as stale due to inactivity. Please be considerate of people watching this issue and receiving notifications before commenting 'I have this issue too'. We welcome additional information that will help resolve this issue. Please read the relevant sections below before commenting.

If you are the original author of the issue

* If this is resolved, please consider closing it so that the maintainers know not to focus on this. * If this might still be an issue, but you are not interested in promoting its resolution, please consider closing it while encouraging others to take over and reopen an issue if they care enough. * If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.

If you are not the original author of the issue

* If you are also experiencing this issue, please add details of your situation to help with the debugging process. * If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.

Memorandum on closing issues

Don't be afraid to manually close an issue, even if it holds valuable information. Closed issues stay in the system for people to search, read, cross-reference, or even reopen – nothing is lost! Closing obsolete issues is an important way to help maintainers focus their time and effort.