Posted on

As said in nix-dev-shells, I fell into the Nix rabbit hole. Today I want to take a look at Home Manager, which can be used to manage all (or most) applications for your user in an easy way. It enables you to replicate your setup across machines by using the declarative nature of Nix. And I'm not only talking about the programs themselves — I already had that in the past with my brew setup — but also about the actual configuration for the programs!

Let's take a look at how this would look for a tool like git.

  # Git configuration
  programs.git = {
    enable = true;
    ignores = [
      ".DS_Store"
    ];
    signing = {
      key = "~/.ssh/id_ed25519.pub";
      signByDefault = true;
    };
    settings = {
      user = {
        name = "André Sterba";
        email = "andre@sterba.dev";
      };
      color.ui = true;
      core = {
        autocrlf = "input";
      };
      init.defaultBranch = "main";
      ...
    };
  };

This config will create ~/.config/git/config and ~/.config/git/ignore.

  git ls -la
lrwxr-xr-x@ - aps 19 Jul 07:49 config -> /nix/store/bm4pgmrlyc7jd4gslbxs51878hhv4966-home-manager-files/.config/git/config
lrwxr-xr-x@ - aps 19 Jul 07:49 ignore -> /nix/store/bm4pgmrlyc7jd4gslbxs51878hhv4966-home-manager-files/.config/git/ignore

What I like about this solution is that both the declaration that I want to have git on my system and the actual configuration for it are next to each other. This is essentially how it works for all tools and their configuration, so I won't add any more examples.

Some handy commands to get rid of old Nix packages in the /nix store are nix store gc and nix store optimise. Otherwise you might run out of disk space sooner or later.

I'm currently in the process of migrating my home servers from a weird mix of Terraform and Ansible to Nix, so expect more about that in the future.