Learning Nix: Recipes and Solutions
I’m learning Nix and documenting solutions I’ve encountered while setting up my declarative system configuration with Home Manager. This post will be updated regularly as I discover new patterns. Here’s my first version of the .nix flake configuration. It’s rough around the edges, but it’s a start.
1. How to Symlink Files Outside the Nix Store
I had .claude/settings.json tracked in my dotfiles repository, but I wanted it to work from ~/.claude/settings.json where Claude looks for it. Most dotfiles like .zsh and .vim are handled by their Nix packages, but for .claude, I needed something different.
The solution: mkOutOfStoreSymlink. This poorly documented Nix function creates a symlink between your folder and the target directory.
options = {
dotfiles = lib.mkOption {
type = lib.types.path;
apply = toString;
default = "${config.home.homeDirectory}/Documents/personal/opensource/config-files";
description = "Location of the dotfiles working copy";
};
};
home.file.".claude/settings.json".source = config.lib.file.mkOutOfStoreSymlink "${config.dotfiles}/claude/settings.json";
Changes are now reflected immediately without running home-manager switch or without having git in ~.claude. Note: this creates a chain of symlinks. Use readlink -f to follow the entire chain to the final destination.