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

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: