6. Managing Your User with Home Manager

Bring the same declarative, rollbackable discipline to your dotfiles, shell, and user packages

Everything in this series so far has been about the machine: configuration.nix decides the hostname, the bootloader, the system-wide packages, the services that run for everyone. But a running Linux box is really two territories laid on top of each other. There's the house — the walls, plumbing, and shared rooms that the landlord (root) manages — and there's your room: your shell prompt, your ~/.gitconfig, your editor config, the little pile of command-line tools you personally can't live without. NixOS, with configuration.nix, is fantastic at managing the house. It has almost nothing to say about your room.

That gap is where dotfiles live, and dotfiles are exactly the kind of accreted mess NixOS was invented to abolish. You copy a .zshrc off a blog in 2019, add an alias here, paste a plugin line there, forget which half of it still does anything, and by the time you set up a new laptop you're reverse-engineering your own home directory. Home Manager is the answer to that: it brings the declarative, reproducible, rollbackable model you already know for the system down into $HOME.

The one-sentence version

Home Manager is a Nix module system for your user account. You describe your dotfiles, shell, and user packages as options in a home.nix file, run one command, and it builds a generation — then symlinks the generated config files into your home directory from the Nix store. It's configuration.nix for you, and it works on plain Linux too, not just NixOS.

The problem with hand-edited dotfiles

Think about what a dotfile actually is. Your ~/.gitconfig is a stateful file you edit in place. There's no record of why any line is there, no way to diff your current machine against a known-good baseline, and no atomic "make it look like this again." If you break it, you fix it by editing it more. It's the imperative model — a sequence of edits with no description — applied to your own account, and it has all the same failure modes NixOS set out to kill at the system level:

Hand-edited dotfiles

Files mutate in place. New machine means copy-paste-and-pray, or a bespoke shell script that's itself undocumented. No generations, no rollback: if an edit breaks your shell, you debug the live file. Half of it is dead config you're afraid to delete because you don't remember what it does.

Home Manager

One home.nix describes the whole environment. A new machine is git clone plus one command. Every switch is a numbered generation you can roll back to. The config is generated from typed options, so a bad value often fails at evaluation time instead of silently at runtime.

If you've read the mental model and generations & rollbacks, none of this is new — it's the same argument, aimed one level down. What's genuinely new is that it works off NixOS. Home Manager runs on Ubuntu, Fedora, Arch, or a locked-down work machine where you can't touch the system config but you can install Nix in your home directory. That portability is a big part of why people reach for it.

Two ways to run it

There are exactly two integration modes, and picking the right one up front saves confusion later. The difference is simply who activates your config: a dedicated home-manager command that you run as your user, or nixos-rebuild folding it into the system switch.

Two integration modesStandaloneany Linux distro · your user onlyhome-manager switchhome.nix → $HOMEruns without root · own generationsNixOS moduleNixOS only · part of the systemnixos-rebuild switchthe systemhome.nixone command · one generation for both

Standalone (the home-manager CLI)

You install the home-manager command and run home-manager switch yourself. Your home configuration has its own generations, completely independent of the system. This is the only option on non-NixOS Linux, and it's also the right pick on NixOS when you want your dotfiles to live and version separately from the machine — for instance, the same home.nix shared across your NixOS desktop and your work Ubuntu laptop. No root required.

As a NixOS module

You import Home Manager into your system flake, and your home config is activated as part of nixos-rebuild switch — one command builds and switches both the system and your user environment, in a single generation. This is the tidiest option when the machine is yours and you want everything to move in lockstep: one repo, one rebuild, one rollback that takes the whole system and your dotfiles back together.

Which to choose? If you're on NixOS and this is a personal machine you fully control, module mode is usually the least friction — one command, one history. If you're on another distro, or you want your user config to be portable and rebuildable without a full system switch (or without root), go standalone. Plenty of people run standalone even on NixOS for exactly that decoupling. You can switch modes later; the home.nix itself is almost identical either way.

Wiring it into a flake

This series is flakes-first, so let's do both setups with flakes. In each case the crucial detail is the same one you met with any flake input: pin Home Manager to the same nixpkgs as everything else, using follows, so you don't end up evaluating two copies of a 100,000-package tree.

Standalone

Add home-manager as an input and expose a homeConfigurations output. Here's a minimal flake.nix:

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05";
    home-manager = {
      url = "github:nix-community/home-manager/release-25.05";
      # pin HM's nixpkgs to ours — one nixpkgs, evaluated once
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };

  outputs = { nixpkgs, home-manager, ... }:
    let system = "x86_64-linux";
    in {
      homeConfigurations."alice" = home-manager.lib.homeManagerConfiguration {
        pkgs = nixpkgs.legacyPackages.${system};
        modules = [ ./home.nix ];
      };
    };
}

You activate it with:

home-manager switch --flake .#alice

That command reads the homeConfigurations."alice" output, builds it, and switches. (The name after # is just the attribute name — many people use "alice@hostname" so one flake can hold several machine-specific home configs.) The very first time, before the home-manager command exists on your PATH, you bootstrap it with nix run home-manager/release-25.05 -- switch --flake .#alice.

As a NixOS module

Here you fold Home Manager into the system flake you already built in your first flake. Add the same input, then import the module and describe your user under home-manager.users:

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05";
    home-manager = {
      url = "github:nix-community/home-manager/release-25.05";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };

  outputs = { nixpkgs, home-manager, ... }: {
    nixosConfigurations.bluewhale = nixpkgs.lib.nixosSystem {
      system = "x86_64-linux";
      modules = [
        ./configuration.nix
        home-manager.nixosModules.home-manager
        {
          home-manager.useGlobalPkgs = true;
          home-manager.useUserPackages = true;
          home-manager.users.alice = import ./home.nix;
        }
      ];
    };
  };
}

Now sudo nixos-rebuild switch --flake .#bluewhale builds the system and activates Alice's home config in the same step. Two options are worth understanding: useGlobalPkgs = true makes Home Manager use the system's nixpkgs (including any overlays and config you've set) instead of instantiating its own — almost always what you want, and another guard against a second nixpkgs. useUserPackages = true installs your user packages into the system profile (/etc/profiles/per-user/alice) rather than into ~/.nix-profile, which plays more nicely with the rest of NixOS.

Why follows matters here specifically

Without inputs.nixpkgs.follows = "nixpkgs", your flake would lock two nixpkgs revisions: yours, and whatever Home Manager's own lock file points at. That means longer evaluation, a bigger closure, and — the subtle one — your packages and Home Manager's built-in modules compiled against different nixpkgs, which is a classic source of "works for me, breaks for you" drift. follows collapses them into one.

Anatomy of a home.nix

Whichever mode you chose, the file that describes you looks the same. At its core are a few mandatory identity fields, a list of packages, and — the real payoff — the programs.* options. A first home.nix:

{ config, pkgs, ... }:
{
  home.username = "alice";
  home.homeDirectory = "/home/alice";
  home.stateVersion = "25.05";   # set once, then leave it — see gotchas

  # user packages, available on your PATH
  home.packages = with pkgs; [
    ripgrep
    fd
    htop
    jq
  ];

  # program modules: enable = true generates the config file for you
  programs.git = {
    enable = true;
    userName = "Alice Example";
    userEmail = "[email protected]";
    extraConfig.init.defaultBranch = "main";
  };

  programs.zsh.enable = true;
  programs.direnv = {
    enable = true;
    nix-direnv.enable = true;
  };
}

The identity fields are exactly what they say: home.username and home.homeDirectory tell Home Manager whose account it's managing (in module mode these are filled in for you). home.stateVersion we'll come back to — it's the one field people misunderstand. home.packages is the user-space twin of environment.systemPackages: tools that land on your PATH, without touching anyone else's account or needing root.

The real magic: programs.*

home.packages just installs a program. The programs.* modules go further — they configure it. This is the heart of Home Manager, and it's worth seeing concretely. Look at what programs.git above replaces. By hand, you'd maintain this file:

Hand-written ~/.gitconfig

[user]
	name = Alice Example
	email = [email protected]
[init]
	defaultBranch = main

A stateful file you edit in place, hope you got the INI syntax right, and copy by hand to every new machine.

Generated from programs.git

programs.git = {
  enable = true;
  userName  = "Alice Example";
  userEmail = "[email protected]";
  extraConfig.init.defaultBranch = "main";
};

Typed options. Home Manager renders the exact INI above into the store and symlinks it to ~/.gitconfig. Same result — but reproducible, diffable, and part of one description.

When you set programs.git.enable = true, Home Manager takes your options, generates a real .gitconfig in the Nix store, and links it into place. You never write the INI — you write the intent, and the module knows how to render it. And because these are typed options, programs.git knows about aliases, signing, delta integration, LFS, and dozens more; you're not memorizing git's config-file grammar, you're setting fields with tab-completion and documentation behind them.

There are hundreds of these modules. A few you'll meet early:

  • programs.zsh / programs.bash — shell config, aliases, history settings, plugins, and prompt, instead of a hand-grown .zshrc.
  • programs.neovim — plugins (from nixpkgs), init.lua/vimrc content, and the vi/vim aliases, all declared.
  • programs.direnv — with nix-direnv.enable = true it wires the shell hook so an .envrc auto-loads a project's dev shell (the exact pairing we lean on in reproducible dev environments).
  • programs.starship, programs.tmux, programs.fzf, programs.bat — the usual command-line comfort layer, each with its own typed options.

The pattern is always the same: enable = true turns the tool on and generates its config; a handful of well-named options cover the common cases; and an extraConfig (or extraLuaConfig, initExtra, etc.) escape hatch lets you paste raw config for anything the module doesn't model. You get abstraction and a trapdoor.

When there's no module: home.file and xdg.configFile

Not every program has a programs.* module, and not every config maps cleanly onto typed options. For those, Home Manager gives you two direct ways to place a file in your home directory from your description.

home.file writes a file relative to $HOME. xdg.configFile writes one relative to ~/.config (i.e. $XDG_CONFIG_HOME), which is where most modern tools keep their config. Both can take inline text or point at a source file living next to your home.nix:

# inline content, written to ~/.config/foo/config.toml
xdg.configFile."foo/config.toml".text = ''
  theme = "gruvbox"
  tab_width = 2
'';

# an existing file in your repo, linked to ~/.gitignore_global
home.file.".gitignore_global".source = ./dotfiles/gitignore_global;

# a whole directory, linked recursively
xdg.configFile."nvim" = {
  source = ./dotfiles/nvim;
  recursive = true;
};

This is the bridge for the long tail: a tool with a config format Home Manager doesn't model, or a config you'd rather keep as a plain file under version control and just link into place. The result is the same as a programs.* module — a read-only file in the store, symlinked into your home — just without the typed-option layer on top.

Activation & generations

Here's where the parallel to system generations becomes exact. When you run home-manager switch (or nixos-rebuild switch in module mode), Home Manager:

  1. Builds all your generated config files and packages into the Nix store — every managed dotfile becomes an immutable store path.
  2. Registers a new generation in your per-user profile (modern location: ~/.local/state/nix/profiles/home-manager), exactly like the system profile from the last article but scoped to you.
  3. Runs the activation script, which atomically swaps the symlinks in $HOME to point at the new generation's files and cleans up links from the old one.

So your ~/.gitconfig isn't really a file you own — it's a symlink into /nix/store/…-home-manager-files/.gitconfig, read-only, regenerated on every switch. That's what makes the whole thing atomic and reversible: switching is a symlink move, and the previous generation's store paths were never deleted.

/.local/state/nix/profiles/home-manager-6home-manager-7home-manager-8home-managercurrent profile/nix/store/9fx…-home-managergeneration 8's files (read-only)/.gitconfig/.zshrc/.config/nvimsymlinks into the store

Listing and rolling back mirror the system commands you already know:

List your home generations

$ home-manager generations
2026-07-06 10:14 : id 8 -> /nix/store/9fx…-home-manager-generation
2026-07-04 21:02 : id 7 -> /nix/store/3ab…-home-manager-generation
2026-07-02 08:41 : id 6 -> /nix/store/7cd…-home-manager-generation

Each row is a timestamp, a generation id, and the store path it points at. To go back, you can run home-manager switch --rollback to activate the previous one, or activate a specific generation directly by running its activation script — copy the store path from the list and run /nix/store/3ab…-home-manager-generation/activate. Under the hood a rollback is nix-env --rollback on the profile followed by that generation's activation script — the same symlink-move-plus-activate you saw for the system.

Your home generations are their own GC roots, and they're pruned by your garbage collection, not root's — a sudo nix-collect-garbage -d cleans the system profile but not your home history, so run it as your user too (or use home-manager expire-generations "-30 days" to trim on a schedule). That's the same subtlety flagged in the generations article, now that you have a second profile to keep in mind.

Three gotchas that catch everyone

1. stateVersion is a compatibility marker, not a version to bump

home.stateVersion records which Home Manager release your config was written against. Some modules choose defaults that would change stored state (a file's format, a directory's location) between releases; stateVersion pins those defaults so an upgrade doesn't silently move your data out from under you. Set it once when you first install, to the release you started on, and then leave it alone — even when you upgrade Home Manager itself. It is not "which version am I running," and changing it can rearrange files you didn't expect. (The system's system.stateVersion works the same way.)

2. Collisions with dotfiles you already have

On your first switch, Home Manager refuses to clobber an existing unmanaged file. Because it wants to replace ~/.gitconfig with a symlink but a real ~/.gitconfig is already there, activation aborts with an "Existing file … would be clobbered" error. The fix is to let it back the old file up: pass -b backup to the CLI (home-manager switch -b backup), which renames the conflicting file to ~/.gitconfig.backup before linking. In module mode the equivalent is the option home-manager.backupFileExtension = "backup";. Set it, switch once, then delete the .backup files once you've confirmed nothing was lost.

3. Forgetting follows and evaluating two nixpkgs

We said it above but it earns repeating, because it's the single most common Home Manager setup mistake: always set inputs.home-manager.inputs.nixpkgs.follows = "nixpkgs". Skip it and your lock file carries a second nixpkgs, your closure balloons, evaluation slows, and your packages can end up built against a different nixpkgs than Home Manager's modules expect. One nixpkgs, followed everywhere.

Try it: see the two worlds side by side

The clearest way to feel the value of programs.* is to watch a handful of toggles produce both the hand-written dotfile you'd otherwise babysit and the Nix snippet that generates it. Pick a program, flip some options, and compare.

By hand
programs.* (home.nix)

Key Takeaways

  • Home Manager is configuration.nix for your user: it manages dotfiles, shell config, and user packages declaratively, with generations and rollback — and it works on non-NixOS Linux too.
  • Two modes: standalone (home-manager switch, own generations, no root, any distro) or NixOS module (home-manager.nixosModules.home-manager, activated by nixos-rebuild, one generation for system + home).
  • Flakes-first setup: add home-manager as an input, always inputs.nixpkgs.follows = "nixpkgs", and expose homeConfigurations (standalone) or import the module with useGlobalPkgs/useUserPackages (module mode).
  • programs.* is the payoff: programs.git.enable = true plus typed options generates ~/.gitconfig for you — abstraction over hand-written dotfiles, with an extraConfig trapdoor for anything unmodeled.
  • No module? Use home.file / xdg.configFile to link arbitrary files (inline text or a source) into $HOME or ~/.config.
  • Activation builds a generation and symlinks read-only store files into your home; list with home-manager generations, roll back with home-manager switch --rollback or a generation's activate script.
  • Gotchas: set stateVersion once and leave it; clear first-run collisions with -b backup / backupFileExtension; and never forget follows.

You've now brought the whole NixOS discipline down into your home directory: your dotfiles, your shell, and your personal tools are one description you can rebuild anywhere and roll back at will. That closes out the getting-started arc — you can describe a machine and describe yourself. The rest of the series goes deeper into the machinery underneath. Next, we open an interactive window onto nixpkgs itself: the Nix REPL, where you can load your flake, drill into pkgs and lib, and test an expression before it ever touches a rebuild.