Skip to content
gvolpePublic

About

A simple Home Manager module for efficiently working with dotfiles that can be mutable to tinker with different configurations, but that can be easily made immutable for sharing and reproducibility.

Resources

Stars

6 stars

Watchers

0 watching

Forks

Latest commit

 

History

4 Commits

Folders and files

Repository files navigation

dots

nix-badge Build

A simple Home Manager module for efficiently working with dotfiles that can be mutable to quickly tinker with different configurations without home-manager switch getting in the way, but that can be easily made immutable for sharing and reproducibility.

The dotfiles.make function handles the correct symlinking of configuration files.

Install

Add the following input to your Nix flake.

{
  inputs.dots.url = "github:gvolpe/dots";
}

Followed by using the provided Home Manager module.

modules = [ inputs.dots.homeModules.default ];

Usage

The HM module provides a few simple options under dotfiles.

{ config, ...}:

{
  dotfiles = {
    mutable = true;
    path = "${config.home.homeDirectory}/workspace/nix-config/home";
    sourceRoot = ../home;
  };
}

The two "path" options under this module are similar in a sense, but have completely different use cases.

  • path: the runtime directory path used for mutable symlinks.
  • sourceRoot: the immutable flake source copy, which evaluates to something like /nix/store/<hash>-source/home.

The dotfiles.make function needs the /home directory configured under both path (runtime) and sourceRoot (nix store) to essentially represent the same directory tree for symlinks to be set correctly.

Example

Here's dotfiles.make being used for a config file located under home/programs/fastfetch/:

{ config, pkgs, ... }:

{
  home.packages = [ pkgs.fastfetch ];

  xdg.configFile."fastfetch/config.jsonc".source =
    config.dotfiles.make ./config.jsonc;
}

The configuration file will be either mutable or immutable, depending on the value of dotfiles.mutable.

  • true: mutable symlink target -> /home/gvolpe/workspace/nix-config/home/programs/fastfetch/config.jsonc.
  • false: immutable symlink to the nix store -> /nix/store/<hash>-source/home/programs/fastfetch/config.jsonc.

Tests

The ./tests/ directory includes a test flake that verifies the correct behavior of the dotfiles module. Furthermore, we can demonstrate the results in the REPL.

When dotfiles.mutable = false, the file will be symlinked to the nix store.

nix-repl> :b checks.x86_64-linux.immutable-module-eval

This derivation produced the following outputs:
  out -> /nix/store/0xjfg0brn3ddkypifnxl3aymvxzjsg36-home-manager-generation

$ readlink -f /nix/store/0xjfg0brn3ddkypifnxl3aymvxzjsg36-home-manager-generation/home-files/.config/example.conf
/nix/store/kxbywmh0c74vx1fazn9zlgv9plcmjzjd-hm_example.conf

When dotfiles.mutable = true, the file will be symlinked to the mutable dotfiles.path value.

nix-repl> :b checks.x86_64-linux.mutable-module-eval

This derivation produced the following outputs:
  out -> /nix/store/bqx6cf18qg6i8rfdbbn925xw1a5l65qd-home-manager-generation

$ readlink -m /nix/store/bqx6cf18qg6i8rfdbbn925xw1a5l65qd-home-manager-generation/home-files/.config/example.conf
/home/dots-test/.dotfiles/home/example.conf

About

A simple Home Manager module for efficiently working with dotfiles that can be mutable to tinker with different configurations, but that can be easily made immutable for sharing and reproducibility.

Resources

Stars

6 stars

Watchers

0 watching

Forks

Contributors

Languages