Running home-manager first time on a new machine

Hey folks,

I was bootstrapping a new machine in which I was NOT using NixOS for the system, just home-manager for my package manager (it was linux still, tho, latest Ubuntu).

I was trying to do a dry run of my flake, but I could never seem to get the arguments to work. Finally, I just used nix-shell.

Here’s my history – what’s the recommendation for how to correctly do this on a new machine?

nix run home-manager/master switch -- --help
nix run home-manager/master switch -- --flake .#optiplex -n
nix run home-manager/master switch -- --flake . -n
nix run home-manager/master switch -n -- --flake . 
nix run home-manager/master -- switch - --flake . 
nix run home-manager/master -- switch -n --flake . 
nix run home-manager/master -- -n switch --flake . 
nix-shell -p home-manager

Yeah, I think Home Manager historically does things a lot more complicated than necessary, and the installation instructions are appropriately weird and needlessly imperative.

I recommend starting from nix-shell -p or nix shell because it’s obvious and easy.

If you want to absolutely make sure that your working configuration will build on any (compatible) machine, you can add a shell environment to your target expression (in your case the flake), which contains the Home Manager from your final environment. If it’s not obvious how to do that: evaluate the configuration using internal Home Manager facilities and grab the configured Home Manager package from the result. Check reference documentation and source code for details. Otherwise it could happen that a fresh Nix installation, or the version of Nixpkgs that is set up with it, or the version of Home Manager inside, is somehow incompatible with your target expression. Then you’d invoke Home Manager from that shell environment for the first time, or even with nix run when you set up the flake accordingly.

1 Like