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

FR: Config to default `home-manager` commands to `--impure` #4784

Open ilyagr opened 6 months ago

ilyagr commented 6 months ago

I would like there to be a config I could set in flake.nix or home.nix that makes home-manager assume --impure for all invocations (home-manager switch, mainly, but --impure is also needed for home-manager news and who knows what else).

The reason I'd like to use --impure is that I want to share my home.nix between machines. As a result, on my machine ~/.config/home-manager/home.nix is a symlink to a managed with GNU Stow). The only way I could get it to work is to replace ./home.nix in the default flake.nix with ~/.config/home-manager/home.nix, and then use --impure for everything.

I'd prefer to not use flakes at all, but I couldn't get that to work with https://github.com/DeterminateSystems/nix-installer, which feels safer to use than the default installer (easier to uninstall).

Aside: I found no way to share flake.nix conveniently with Stow. If flake.nix is a symlink, nothing works. But this is both a less important problem and might be more difficult to solve.

Aside 2: With my setup, I also get error messages that seem to imply --impure doesn't propagate everywhere it should. See the first two lines below. I'm not sure whether they have any detrimental effect. I may file this as a separate bug once I make a minimal example or do more research.

$ home-manager switch --impure
error: the path '~/.config/home-manager/home.nix' can not be resolved in pure mode
error: the path '~/.config/home-manager/home.nix' can not be resolved in pure mode
Starting Home Manager activation
Activating checkFilesChanged
Activating checkLaunchAgents
Activating checkLinkTargets
Activating writeBoundary
Activating copyFonts
Activating installPackages
nix profile remove /nix/store/dmybjrwxbs3m65wh54nk75j1k7h3a4yi-home-manager-path
removing 'home-manager-path'
Activating linkGeneration
Cleaning up orphan links from /Users/ilyagr
No change so reusing latest profile generation 2
Creating home file links in /Users/ilyagr
Activating onFilesChange
Activating setupLaunchAgents
stale[bot] commented 3 months 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.

Andy3153 commented 3 months ago

I'd like home-manager switch to assume I'm always using the --impure flag as well, because I will always be using it anyways too. Any news on this?

CobaltSpace commented 2 weeks ago

Is there something wrong with adding home-manager = "home-manager --impure" to aliases? I guess it is clunky, but it seems to work.

ilyagr commented 2 weeks ago

Is there something wrong with adding home-manager = "home-manager --impure" to aliases? I guess it is clunky, but it seems to work.

I think this is good advice and a good workaround, I might do just that. Thanks!

I also think that having this as a home-manager feature, independent of which shell you use it whether you call it from a script, would be even better. Whether --impure is needed depends on flake.nix, so ideally it should be specified there or adjacently.

Andy3153 commented 2 weeks ago

Is there something wrong with adding home-manager = "home-manager --impure" to aliases? I guess it is clunky, but it seems to work.

It's no longer much of a problem for me because I switched my entire configuration to custom modules and home-manager as a nixos module, so at least I only have to run one command with the impure flag now