Home Manager

Robert Helgesson <robert@rycee.net>

What?

  • A declarative system to manage your $HOME

  • Based on the Nix package manager

  • Somewhat resembles NixOS

Support

  • Standalone

    • NixOS
    • Other GNU/Linux distros
    • macOS
  • System module

    • NixOS
    • nix-darwin

Why?

  • Install user-level packages

  • Configure programs & manage dotfiles

  • Configure user services

  • Reproducible

  • (Inconvenient) rollbacks

Integrations

Configure email accounts once, generate setups for

  • notmuch
  • mbsync
  • msmtp
  • astroid

Integrations

Calendars & contacts in progress

Nix crash course?

Nix

  • A purely functional package manager

  • Can interact with it as a regular user

    $ nix build nixpkgs.cowsay
    $ ./result/bin/cowsay Nix rocks!
     ____________
    < Nix rocks! >
     ------------
            \   ^__^
             \  (oo)\_______
                (__)\       )\/\
                    ||----w |
                    ||     ||

Nix expression language

  • A pure, lazy, functional language

  • Dynamically typed

  • Not general purpose

Basics

1 + 2
# ⟹ 3

if true then 1.5 else -1.5
# ⟹ 1.5

let b = false; in b || !b
# ⟹ true

Strings

"My system: ${builtins.currentSystem}"
# ⟹ "My system: x86_64-linux"

''
  1 + 5
    = ${toString (1 + 5)}
''
# ⟹ "1 + 5\n  = 6\n"

Lists & attribute sets

[ 1 2 ] ++ [ "three" ]
# ⟹ [ 1 2 "three" ]

{ key1 = "v1"; key2 = 2; }
# ⟹ { key1 = "v1"; key2 = 2; }

{ key1 = "v1"; key2 = 2; }.key2
# ⟹ 2

{ "/can/have/odd/keys!" = 1; }."/can/have/odd/keys!"
# ⟹ 1

Functions

add = x: y: x + y
add 5 6
# ⟹ 11

builtins.map (add 5) [ 1 2 ]
# ⟹ [ 6 7 ]

mul = { x, y }: x * y
mul { x = 2; y = -9; }
# ⟹ -18

Path literals

./presentation.mdwn
# ⟹ /home/rycee/presentation.mdwn

/home/rycee/presentation.mdwn
# ⟹ /home/rycee/presentation.mdwn

"${/home/rycee/presentation.mdwn}"
# ⟹ "/nix/store/8d4s4[…]78881-presentation.mdwn"

Laziness

let x = { a = x; }; in x
# ⟹ { a = { ... }; }

let x = { a = x; }; in x.a
# ⟹ { a = { ... }; }

let x = { a = x; }; in x.a.a
# ⟹ { a = { ... }; }

let x = { a = x; }; in x.a.a.a
# ⟹ { a = { ... }; }

How?

Install

$ sudo nix-channel --add https://…/master.tar.gz home-manager
$ # or https://…/release-19.03.tar.gz
$ # depending on whether you use Nixpkgs unstable or 19.03
$ sudo nix-channel --update
$ nix-shell '<home-manager>' -A install

All done! The home-manager tool should now be installed
and you can edit

    /home/rycee/.config/nixpkgs/home.nix

to configure Home Manager. Run 'man home-configuration.nix'
to see all available options.

home.nix

{ config, pkgs, ... }:

{
  # Let Home Manager install and manage itself.
  programs.home-manager.enable = true;
}

Install packages

{ config, pkgs, ... }:

{
  home.packages = [
    pkgs.bat
    pkgs.cowsay
  ];

  # Let Home Manager install and manage itself.
  programs.home-manager.enable = true;
}

home-manager switch

… and

$ cowsay It works!
 ___________
< It works! >
 -----------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

Manage dotfiles

home.packages = [
  pkgs.git
];

home.file.".config/git/config".text = ''
  [user]
  name=Robert Helgesson
  email=robert@rycee.net
'';

… and

$ cat .config/git/config
[user]
name=Robert Helgesson
email=robert@rycee.net

$ readlink .config/git/config
/nix/store/xbm98…9cw3c-home-manager-files/.config/git/config

Note, files are world readable!

Program modules

programs.git = {
  enable = true;
  userName = "Robert Helgesson";
  userEmail = "robert@rycee.net";
};

… and

$ cat .config/git/config
[user]
email=robert@rycee.net
name=Robert Helgesson

User services

services.random-background = {
  enable = true;
  imageDirectory = "%h/backgrounds";
  interval = "1h";
};

E-mail accounts

programs.msmtp.enable = true;
programs.mbsync.enable = true;
accounts.email.accounts.test-account = {
  primary = true;
  address = "home.manager@zoho.eu";
  userName = "home.manager";
  realName = "Home Manager Test Account";
  passwordCommand = "cat ${config.home.homeDirectory}/pass";
  imap.host = "imap.zoho.eu";
  smtp.host = "smtp.zoho.eu";
  msmtp.enable = true;
  mbsync.enable = true;
};

Meta

Numbers

  • Born Christmas 2016

  • 79 contributors since

  • 692 commits

Alternatives

Where?