Home Manager is great. It allows configuring user environments fully declaratively.
But installing Home Manager has always been wrong:
Channels are bad, nix-env
is bad.
And Home Manager dropping a flake.nix
somewhere is also bad.
While Home Manager environments are declarative, installation is not!
In my opinion, using Home Manager should work like this:
-
Add a
default.nix
in a directory of choice. -
Import the Home Manager Nix library from there.
-
Put your configuration and custom modules wherever you please.
-
Add attributes to
default.nix
that correspond to the machines or profiles or users you're managing. -
Run
nix-shell -A <attribute> --run switch
to instantly switch to an environment. -
In an existing environment, run
home-manager switch
as usual.
This repository implements such a wrapper around Home Manager, which you can use as just described.
The underlying problem is that we've been doing it backwards this entire time. Nix is still being misunderstood as a user-facing application, while really it's a low-level library that actual applications can build upon to do useful things.
Home Manager is such an application, which strongly depends on Nixpkgs, which in turn strongly depends on the Nix language and the Nix store. Note how the Nix CLI doesn't even get an honorable mention here.
This is why with home-damager
you import and keep updated a Home Manager release and use the version of Nixpkgs shipped with Home Manager, not the other way around.
Passing your own arbitrary Nixpkgs is merely an escape hatch, such as for emergency updates, and should be a very deliberate exception.
Driven to conclusion, Home Manager should have its own first-class installer and bring its own Nix under the hood.
Check example.nix
for the structure of the entry point to your set of Home Manager configurations.
To use it, get a copy and add remote sources:
nix-shell -p npins curl
pushd $(mktemp -d)
curl https://github.com/fricklerhandwerk/home-damager/blob/main/example.nix > default.nix
npins init --bare
npins add github nix-community home-manager --branch release-24.11
npins add github fricklerhandwerk home-damager --branch main
nix-shell --run switch
To uninstall, delete all profile generations created by Home Manager. On a vanilla system this amounts to:
rm "${XDG_STATE_HOME:-$HOME/.local/state}"/nix/profiles/{home-manager,profile}*
The next garbage collection will remove the dangling store objects.
Run a NixOS VM test:
nix-build -A test
Run the test interactively:
nix-shell --run test-interactive