Nixos 24.05 The program 'home-manager' is not in your PATH

newby question: I have a new installation with nixos on an amd64 box and installed home-manager as an nixos module following the instructions https://nix-community.github.io/home-manager/index.xhtml#sec-install-nixos-module. The relevant part of the config.nix is

imports = [ <home-manager/nixos> ];

home-manager.users.frank = { pkgs, … }: {
home.packages = [ pkgs.atool pkgs.httpie ];
programs.bash.enable = true;
home.stateVersion = “24.05”;
};

and in home.nix

home.username = “frank”;
home.homeDirectory = “/home/frank”;
home.stateVersion = “24.05”;
programs.home-manager.enable = true;

Then nix-env -q gives

home-manager-path

but when I run home-manager switch I get the error

home-manager switch
The program ‘home-manager’ is not in your PATH. You can make it available in an
ephemeral shell by typing:
nix-shell -p home-manager

only after I type nix-shell -p home-manager then home-manager runs ok.

What am I doing wrong?

PS: I see that running nixos-rebuild switch gives the warning:

warning: frank profile: You are using

Home Manager version 24.11 and
Nixpkgs version 24.05.

which I cannot undertand; I have never set a version 24.11. What should I change?

Which commit is the home-manager channel tracking? What is the output of sudo nix-channel --list?

Please show your channels.

Its likely that you use home-manager master combined with nixos-24.05, which is not supported (like the warning mentions).

Not 100% sure about that, but from code it lookl ike that you are using home-manager as module inside a nixosConfiguration (you also mentioned that).

Afaik you then need to set

programs.home-manager.enable = true;

in your HM config, otherwise it will not add HM (as it would install anyways via nixosConfiguration).

nix-channel --list gives nothing back (empty).

i set the channel per instructions as

sudo nix-channel --add https://github.com/nix-community/home-manager/archive/release-24.05.tar.gz home-manager

sudo nix-channel --update

but with sudo, I get:

sudo nix-channel --list
home-manager https://github.com/nix-community/home-manager/archive/master.tar.gz
nixos nixos-24.05 release nixos-24.05.1503.752c634c09ce

That looks better?

My home.nix in ~/.config is

{ config, pkgs, … }:

{
programs.git = {
enable = true;
userName = “Andrew U Frank”;
userEmail = “frank@gerastree.at”;
package = pkgs.gitFull;
};

services.gpg-agent = {
enable = true;
defaultCacheTtl = 1800;
enableSshSupport = true;
};

home.username = “frank”;
home.homeDirectory = “/home/frank”;
home.stateVersion = “24.05”;
programs.home-manager.enable = true;
}

The installation is a new NixOS 24.05.

I assume that I have a problem with the channel and appreciate help to fix it – I switched to Nix a few days ago! Thank you!

I am not totally familiar with channel setup, but for root you are mixing 24.11 and 24.05, so remove the home manager and add it with 24.05 release.

I have to admit that I am not using NixOS with channels, but I think that imports = [ <home-manager/nixos> ]; should not work if there were no channels. I think you might have forgotten the sudo in front.

It seems as if you configured the master.tar.gz at some point. Not sure if you can just add a channel a second time with a different source. My suggestion would be to remove the home-manager channel and add it with the correct release-24.05.tar.gz tarball. Something like this:

sudo nix-channel --remove home-manager
sudo nix-channel --add https://github.com/nix-community/home-manager/archive/release-24.05.tar.gz home-manager

If that doesn’t help, we probably need to wait for someone more knowledgeable with channels.

1 Like

This is a NixOS module setup, which doesn’t use the home-manager binary, so it should not be installed - nixos-rebuild will do everything home-manager normally does to install stuff, so the home-manager binary is useless (except maybe for browsing documentation).

This is fine if you want to use that instead of the configuration you set in home.nix.

If you have other config in home.nix that you want in there, just copy it over and delete home.nix. Or switch to a standalone config, removing everything home-manager related from your configuration.nix.

Whatever the case, you should not mix a standalone and NixOS setup. I’m unsure whether home-manager switch will warn you, be flaky as it fights nixos-rebuild, or just completely break your user profile, but this is definitely not an intended use case.

The home-manager docs kind of invite this confusion because they end up telling you to edit home.nix and run home-manager switch in the “using” section regardless of which installation setup guide you followed. We get a confused newbie every few weeks.

If you want a NixOS module setup, just ignore that section of the manual and follow normal NixOS usage, except with home-manager configuration in that little home-manager.users.frank area.

@Shawn8901 does say as much, but I think you need the full explanation to not make mistakes here.

To fix the warning from nixos-rebuild (or home-manager if you switch to a standalone setup), follow @polygon 's suggestion.

2 Likes

@polygon I tried to follow your instructions

nix-channel --list
home-manager https://github.com/nix-community/home-manager/archive/release-24.05.tar.gz
nixos nixos-24.05 release nixos-24.05.1503.752c634c09ce

and have now the error

error: file 'home-manager' was not found in the Nix search path (add it using $NIX_PATH or -I)

Is there a way not to use channels and insert the reference to the release directly in the configuration.nix file?

@TLATER : Thank you for pointing out my confusion. I did not understand the home-manager manual and have removed the home.nix file completely and moved the content (userName for git etc.) into the home-manager.users.frank stanza.

That’s without sudo - your user and root have different channels, and your configuration.nix will pull its channels from root. So you likely configured it for your user rather than root, resulting in that error.

If you did configure it for root, maybe you need to sudo nix-channel --update?

Yes! Channels are considered an archaic flaw of the ecosystem anyway (exactly because of the problems you’re having). See this random blog post: Pinning NixOS with npins, or how to kill channels forever without flakes - jade's www site

There’s also flakes, but that’s harder to grok when you just start out.

I’d link you to nix.dev, but sadly the official tutorial only covers packages, not NixOS.

@TLATER what would then go into the configuration.nix to replace the entry for the channel?

I fear I have ruined my configuratin with nix-channel --remove nixos or some similar… hope it will be reset after a reboot.

Reading the text you linked: I see that channels are clearly not helping “reproducible” builds! The details are over my head… Obviously it would be better to just reference a build in the imports.

Thank you for helping a newby!

Did you remove it from the root user or your daily user (just asking as you did include sudo prior when referring to root stuff).

If it’s from the root user, re-add the channel, I am not aware of “self healing” here. Tho i think it will not break your system unless you try to rebuild.

If it’s for your daily user, you don’t need to have a nixos channel, it will pick it from the system (root user), if I remember correctly, but please if that is wrong someone who is using channels please correct me here. :slight_smile:

1 Like

Sadly that’s not quite that trivial. YMMV, and all guides that aren’t about flakes will cover channels, so I’m not 100% sure this is the right thing to recommend to a newcomer.

Nonetheless, I tried making a little guide here since the blog post is admittedly a bit long-winded:

You’d start off by setting up npins, which is a little tool to manage the imports for you - you don’t want to have to manually change commit shas. You’d do that by going to /etc/nixos and running:

# Don't forget to `cd /etc/nixos` first
$ nix-shell -p npins
$ sudo npins init --bare

That will add an npins directory to your configuration directory, and in it a default.nix and a sources.json. By default it’s set up with the unstable branch for nixpkgs, and nothing else, so we’ll have to change it to use home-manager and nixpkgs stable:

$ sudo npins add --name nixpkgs channel nixos-24.05
$ sudo npins add --name home-manager github --branch release-24.05 nix-community home-manager

Now we need to change what the NixOS module system uses to source its source code. Without flakes, nixos-rebuild will always use the value from $NIX_PATH for that, which by default uses your channels. We need to override that behavior. So we’re going to have to tweak nixos-rebuild. That’s what the script in the blog post is for.

For that script to work, we’ll first need to enable some experimental nix features. To do that, in your configuration.nix, add:

# configuration.nix
{ pkgs, ... }: {
  # We need the flakes experimental feature to do the NIX_PATH thing cleanly
  # below. Given that this is literally the default config for flake-based
  # NixOS installations in the upcoming NixOS 24.05, future Nix/Lix releases
  # will not get away with breaking it.
  nix.settings = {
    experimental-features = "nix-command flakes";
  };

  # Add npins to your system so you don't need to use `nix-shell` while we're
  # here.
  environment.systemPackages = with pkgs; [
    npins
  ];
}

Then rebuild your system with sudo nixos-rebuild switch one last time to enable that setting.

Next, copy the script from the blog post to /etc/nixos/rebuild.sh, and make it executable with sudo chmod +x rebuild.sh. You can then build your system with sudo ./rebuild.sh switch from that directory, just like before, except this time you won’t be using channels.

The rest of the blog post is quite succinct, it tells you how to:

  1. Make commands like nix-shell also use the npins, including removing existing channels: Pinning NixOS with npins, or how to kill channels forever without flakes - jade's www site
  2. How to update with the npins: Pinning NixOS with npins, or how to kill channels forever without flakes - jade's www site

Nix channels doesn’t magically reset on reboot, sadly. That’s a permanent change. Just add back the nixpkgs channel:

sudo nix-channel --add https://channels.nixos.org/nixos-24.05 nixpkgs

And maybe delete your user channels so they stop confusing you:

nix-channel --remove nixpkgs
nix-channel --remove home-manager

Then remember to always run nix-channel with sudo.

Or switch to npins and forget that command ever existed :wink:

@Shawn8901 nixos is new to me - I used debian for a couple of years and typically worked in my user account and use sudo su and continue to do OS stuff - but logged in the my usual account (i.e. I have only one account and never use the root account).

is this not a practical approach for nixos? does it matter in which account i am logged in when doing ‘sudo nix-os-rebuild’ ? In debian I think I have with sudo always the same environment as root, independent of where I logged in?

I seem no to get out of the problem, going a number of generations back; the moment I do nixos-rebuild i get errors of missing 'nixpkgs/nixos, I can start over …

This is true on NixOS as well. You should use sudo su (sudo -s is better by the way) much more rarely, though, basically only to edit /etc/nixos/configuration.nix.

Generations do not affect the channels (yeah… You see why they aren’t considered great). You will need to manually fix your channels.

@TLATER I am somewhat surprised to have found in 5 days a point, where the guarantee ‘consistent rebuild’ is invalid and “you can always go back” not correct… sad. I think nix should get away from channels, as your text suggests.

As I have no idea how to fix the channels, I will just start fresh and keep the configuration files - and not touch channels again.

Regarding working procedures: I have the configuration files in my directory and edit them there without sudo. In /etc/nixos is just a link… I use sudo only to run ‘nixos-rebuild’ and stuff with channels (e.g. nix-channels --list)… Is this a reasonable approach? Dangerous?

Yep. You’ll find others here and there. NixOS can’t automagically revert a postgres db to an older version, for example. Some software is inherently side-effectful.

NixOS can solve the majority of these things, especially if coupled with an Erase your darlings: immutable infrastructure for mutable systems - Graham Christensen -style setup. But not all of it.

Channels are probably the worst offender, and the ecosystem is slowly moving away from them indeed. That’s what all the fuzz about flakes is about, but I believe we’re at least a couple of years away from that.

Very reasonable. Only dangerous if you have scripts that automatically update or something, since then user processes could feasibly edit your configuration.nix without you noticing.

Interesting reading - thank you for the link.
I have about 30 years of Haskell usage - and wonder why cleaning things up takes so long. Obviously, cleaning-up is not an attractive task! And why is adding an additional feature so attractive? Human nature!

Thank you for building and supporting nix!
andrew

According the error message you state I think that the channel has to be called nixpkgs. TLATER did mention that also in the commands stated out (when I re-read the post).

The name in the <> until a possible / should be the channel name if I recall correctly.
So the state should be recoverable.

As TLATER mentioned there is always stateful data, that can not be reverted. Something like databases (example was postgres here) will always be a problem (that is the nature of that software to have a state). Nixos generations are not a snapshot or so for your disk, you can apply old(er) configurations of your system, no extra magic is included after that. In case you want to recover states you might want to consider snapshots and proper backups.

I use sudo only to run ‘nixos-rebuild’ and stuff with channels (e.g. nix-channels --list)… Is this a reasonable approach? Dangerous?

Actually you can also just use nixos-rebuild without root, as building a configuration should not need root access.
Just activating it needs root access. There is a flag on nixos-rebuild that handles that situation --use-remote-sudo or so. If that make sense for your workflow it’s up to you.

About the overall situation with channels vs others and having multiple possible solutions. The “problem” is that the flake solution is controversial in the community, some like that, some dislike it (all on my opinion for valid reasons), some want to keep the channels, others don’t like the overall flake thing, but want to lock the channels (eG something like npins).
The advantage and disadvantage at the same about open source is that if a possible solution is disliked, those will come up with a different solution, which makes it harder for newcomers to get onboard.

1 Like

Thank you for your thoughtful comment; it solved - indirectly - the initial problem, as I had to reread the comment by TLATER and therefore I saw that I need to enable the experimental features. After this the home-manager in the configuration.nix did build.

I understand the issues regarding mutable and un-mutable data to some degree (having worked in geographic information systems) and I like the Nix approach. Haskell had multiple “solutions” before Wadler showed how the mathematical theory of monad explained and practically solved the issue.

A perfect example how open source allows multiple approaches and till the right solution emerges.

In practice, “solutions” are often suggested to avoid (real or imaginary) performance problems or are just convenient. On a more careful consideration, solution with good math (monads for example) are often more economical, less to learn, simpler interface, less errors… That’s at least, what I have learned in the Haskell community. Now I have to see how to bring my Haskell stuff into Nix…

2 Likes