nix setup
Find a file
2026-02-09 16:57:57 +01:00
bootstrap-macos.sh fix: macos setup 2026-02-09 16:57:57 +01:00
direnv-nix.rc chore: direnv 2025-09-22 13:53:01 +02:00
direnv-nix.zsh fix: macos setup 2026-02-09 16:57:57 +01:00
macos.config.nix fix: macos setup 2026-02-09 16:57:57 +01:00
macos.nix.conf makito: nix setup for mac 2025-05-15 13:48:10 +02:00
macos.zlogin makito: update macos files and doc 2025-05-15 15:21:36 +02:00
macos.zprofile makito: update macos files and doc 2025-05-15 15:21:36 +02:00
macos.zshenv makito: update macos files and doc 2025-05-15 15:21:36 +02:00
README.md fix: macos setup 2026-02-09 16:57:57 +01:00
shell-hook.nix fix: manpages and completions 2026-02-08 19:22:13 +01:00

nix

direnv + nix shell integration

Three files that wire up direnv, nix, and zsh so that shell.nix projects get man pages and zsh completions automatically.

direnv-nix.rc

Bootstraps nix-direnv for cached nix-shell environments.

~/.config/direnv/direnvrc:

source ~/dev/vlv/nix/direnv-nix.rc

direnv-nix.zsh

Zsh integration: sets up the direnv hook and a chpwd hook that merges NIX_ZSH_FPATH into zsh's fpath and re-runs compinit when entering a direnv-managed directory.

~/.zshrc:

if _has direnv; then
    source ~/dev/vlv/nix/direnv-nix.zsh
fi

shell-hook.nix

Nix shellHook that exposes man pages and zsh completions from buildInputs. Sets MANPATH (with trailing : to preserve system defaults) and NIX_ZSH_FPATH (a custom variable picked up by direnv-nix.zsh, to avoid direnv overwriting zsh's default fpath).

shell.nix:

with (import <nixpkgs> {});

mkShell {
  buildInputs = [ jq gh ];
  shellHook = import ~/dev/vlv/nix/shell-hook.nix;
}

To append project-specific setup:

  shellHook = (import ~/dev/vlv/nix/shell-hook.nix) + ''
    echo "hello from this project"
  '';

Per-project .envrc

Each project with a shell.nix needs an .envrc:

use nix

macOS bootstrap

On a fresh Mac, run:

curl -fsLO https://git.meatbag.se/varl/nix/raw/branch/main/bootstrap-macos.sh
bash bootstrap-macos.sh

This does the following in order:

  1. Installs a standalone chezmoi binary to /tmp
  2. chezmoi init --apply — lays down all dotfiles (prompts for GPG keys and tokens)
  3. Installs nix via the official installer
  4. Adds your user to trusted-users in /etc/nix/nix.conf
  5. nix-env -ir user-macos — installs all packages (chezmoi, direnv, git, vim, etc.)
  6. Removes the standalone chezmoi (nix-managed chezmoi takes over)

Open a new terminal after it finishes.

Tip

For nix updates, if nix complains about build groups, see: https://github.com/NixOS/nix/issues/10892

Manual steps (if not using the bootstrap script)

expand

Install nix:

sh <(curl --proto '=https' --tlsv1.2 -L https://nixos.org/nix/install)

Add your user as a trusted-user in /etc/nix/nix.conf:

build-users-group = nixbld
+trusted-users = varl root

Reload the daemon:

sudo launchctl stop org.nixos.nix-daemon
sudo launchctl start org.nixos.nix-daemon

Copy config files:

mkdir -p ~/.config/nixpkgs
cp macos.config.nix ~/.config/nixpkgs/config.nix
cp macos.zlogin ~/.zlogin
cp macos.zprofile ~/.zprofile
cp macos.zshenv ~/.zshenv

Logout/login, then install packages:

nix-env -ir user-macos