Home-manager command won't switch twice on nixos

i’ve got a fairly simple system running nixos 24.05. it’s a basic install - no flakes, just a configuration.nix file.

i’d like the users on this system to be able to manage their home directories using the home-manager command. so i am not installing home-manager as a nixos module.

instead, i’m adding pkgs.home-manager to environment.systemPackages in my configuration.nix file, like this:

environment.systemPackages = with pkgs; [
  <some packages>
  home-manager
  <more packages>
];

this install seems to work, and the home-manager command is available to all users. when a user runs home-manager init, the config file is created in ~/.config/home-manager/home.nix

two weird things to note at this point…

  • the fresh home.nix file has home.stateVersion = "23.11";
  • running home-manager --version reports 24.05pre

the user can now edit their home.nix and switch to it via home-manager switch. and the changes stick. for example, they can add pkgs.hello to home.packages, and after running home-manager switch, the hello command is available.

but at this point, the home-manager switch command will no longer run. it returns the following error…

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

       at «none»:0: (source not available)

other home-manager subcommands like edit and packages work fine. the build subcommand returns the error above.

i’ve searched for solutions to this error.

this issue seems to indicate that a fix was made to nixpkgs was made a year ago. it also mentions a workaround tweak to home-manager.overrideAttrs but i have no idea where that change would go (sorry i’m a nix newb).

in this issue, folks focus on the home-manager channel being used. i can’t tell which one i’m using… i would expect that adding the home-manager package to my configuration.nix would pick the correct version.

this pull request seems related, and it’s from three months ago. i’m guessing i would need to pull the home-manager package from a more recent channel or tarball, but i don’t see any nixos examples of how to do that.

what am i missing?

I’d recommend following the standalone-install instructions instead of using pkgs.home-manager.

thanks! these instructions are for an individual user, and they are not declarative. that is, you run the nix-channel command to pick a channel and then install home-manager via nix-shell.

this method forces each user to do it themselves, and provides no way to, say, declare the channel via a config file somewhere. i need a way to install home-manager system-wide and in a way that lets me declare all the details (e.g. which channel to install from) via a text file somewhere.

i chose nixos because of it’s declarative/reproducible ethos, so using commands like nix-channel seem to go against that.

Perhaps you could pin the Home Manager channel system-wide using the same mechanism you’re using for the system-wide Nixpkgs channel? As long as it ends up in your users’ NIX_PATH somehow, it doesn’t matter what tool you used to put it there.

But I use nix-channel for both, so I don’t know.