Bootstrapping stand-alone home-manager config with Flakes

Home-manager provides some template for using it with flakes. But there is still no bootstrap/install instructions and manual.

If you already have you config and it includes managing home-manager itself, then you probably can use something like:

nix build --no-write-lock-file home-manager
./result/bin/home-manager --flake ".#$USER" switch

(note that home-manager is in global Flakes registry)

Most likely can use home-manager/release-21.11 if needed (see choosing channel in manual).

If you are not on NixOS and manage nix via home-manager too, you probably want to remove nix installed into nix-env. Just use build instead of switch previously and separately activate it with removal:

nix shell 'nixpkgs#nix' --command sh -c 'nix-env -e nix && ./result/activate'

Much more comfortable that running build followed by ./result/bin/home-manager might be the use of nix run.

1 Like

Complete example

The command

nix run --no-write-lock-file github:nix-community/home-manager/ -- --flake ".#$USER" switch

on a brand-new VM with

  • Nix 2.6.1

  • experimental-features = nix-command flakes added to /etc/nix/nix.conf or to ~/.config/nix/nix.conf.

  • this flake
      ​description = "Home Manager configurations";
      ​inputs = {
        ​nixpkgs .url = "github:nixos/nixpkgs/nixos-21.11";
        ​home-manager = {
          ​url = "github:nix-community/home-manager/release-21.11";
          ​inputs.nixpkgs.follows = "nixpkgs";
      ​outputs = {self, nixpkgs, home-manager}: {
        ​homeConfigurations  = {
          ​"vagrant" = home-manager.lib.homeManagerConfiguration {
            ​configuration = {pkgs, ...}: {
              ​programs.home-manager.enable = true;
              ​home.packages = [
            ​system = "x86_64-linux";
            ​homeDirectory = "/home/vagrant";
            ​username = "vagrant";
            ​stateVersion = "21.11";

installs a home-manager that can subsequently be used with the command

home-manager --flake ".#$USER" switch
1 Like
Hosted by Flying Circus.