simple-homemanager icon indicating copy to clipboard operation
simple-homemanager copied to clipboard

01 home-manager install missing additional setup on multi-user install on foreign distro.

Open brisk-pm opened this issue 1 year ago • 11 comments

The instructions linked to install home-manager point the user to install home-manager with nix-shell '<home-manager>' -A install

In order to progress I had to add a nixpkgs channel and update the $NIX_PATH in my environment:

nix-channel --add https://nixos.org/channels/nixpkgs-unstable nixpkgs
export NIX_PATH=$NIX_PATH:$HOME/.nix-defexpr/channels

Also using the nix-shell install method wiped the home-manager path after the first make command that runs home-manager switch.

I was able to get home-manager persistently available with nix profile install home-manager. I'm not sure if this my unfamiliarity with nix or if the instructions are unclear for a multi-user nix install on a foreign distro.

brisk-pm avatar Feb 25 '24 19:02 brisk-pm

Mentioned this in the nixos discourse forums as well, but for visibility repeating:

I'm a little wary of adding too much troubleshooting to the guide itself. I'd rather leave that to the docs with the tools, because everyone's going to have a different specific setup.

I'd actually like to leave this issue open as something others can reference, to act as a troubleshooting supplement.

Evertras avatar Mar 05 '24 09:03 Evertras

@brisk-pm I ran into the same issue. I believe the issue is that the nix-shell '<home-manager>' -A install command, as I understand it, works by creating a temporary environment.

The nix profile install home-manager will install it directly into a permanent environment and in the default profile.

I believe the other way around this, and I think is probably the correct way if someone wants to do this declaratively, is by making sure home.nix has the home-manager application in it. I would say that the guide should modify the first iteration of home.nix to include it, by default, and explain that the instantiation is temporary and the way to make this stick is to encode it into your home.nix. I could be wrong, being new to Nix - but that's my takeaway. The snippet in home.nix I'm referring to editing in the first iteration would instead look like this...

...
  home = {
    packages = with pkgs; [
       home-manager
       hello
    ];
...

All that being said, thanks for a fantastic to-the-point guide @Evertras!

davidjmeier avatar Mar 06 '24 14:03 davidjmeier

Ah, I see we can make home-manager permanent as part of the initial home-manager switch

I like the generic way of bootstrapping home-manager with nix-shell -p home-manager (or equivalent) and adding the home-manager package via home.nix. We do not have to source any profile things this way.

Tested on a fresh NixOS install. I really appreciate this guide's encapsulation of home-manager in a flake. Its portable between foreign distros and NixOS.

brisk-pm avatar Mar 06 '24 19:03 brisk-pm

I think there's some merit to having home manager bootstrap itself, but I'd also be wary. If you accidentally delete home manager from the list (for example, forgetting to include a module that lists it while refactoring things), then you're going to get into weird states of trying to restore it. Successfully setting up the standalone version makes this much less of a hassle.

Because of that I'd rather not put that directly in the guide, but I'm happy to have this issue open as discussion for others to see as other options.

Evertras avatar Mar 09 '24 08:03 Evertras

Since you have flakes enabled, you don't actually need to install home-manager to use it, you can simply nix run home-manager/<branch> -- switch --flake .#myprofile the first time (see https://nix-community.github.io/home-manager/index.xhtml#sec-flakes-standalone). It can then self bootstrap if you put it in home.nix, and if you accidentally delete it, you can run from git again to fix it.

This simplifies the installation steps quite a bit.

bj0 avatar Jul 01 '24 22:07 bj0

Excellent guide. But I'm stuck in the exact same way. After running make for the first time home-manager is no longer found.

How is it meant to work in non-NixOS environments? I can see "home-manager-path" as an installed package.

I'm also stuck because I don't actually know how to deactivate my profile to even add "home-manager" to my packages list (if I have to solve this the less correct way).

jameshulse avatar Aug 31 '24 02:08 jameshulse

I actually use @bj0 's solution in my personal setup, I may add that to the guide officially at this point as this seems to be a painful bit.

Evertras avatar Sep 01 '24 00:09 Evertras

Fantastic. Yes I think that is a good solution. Or at least as a completely new user it is useful to realise that arbitrary commands can be run like that.

I ended up adding home-manager to my packages list which helped. But as you said, there is slightly more risk to that if you don't realise the escape hatch of running it directly with nix run ....

jameshulse avatar Sep 01 '24 23:09 jameshulse

Ran into this issue too, I got

$ home-manager switch --flake .#myprofile
/bin/sh: 1: home-manager: not found
make: *** [Makefile:3: update] Error 127

after the first switch.

After reading https://nix-community.github.io/home-manager/ I found that you can simply do:

  # Let Home Manager install and manage itself.
  programs.home-manager.enable = true;

sharksforarms avatar Sep 18 '24 18:09 sharksforarms