| bootstrap-macos.sh | ||
| direnv-nix.rc | ||
| direnv-nix.zsh | ||
| macos.config.nix | ||
| macos.nix.conf | ||
| macos.zlogin | ||
| macos.zprofile | ||
| macos.zshenv | ||
| README.md | ||
| shell-hook.nix | ||
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:
- Installs a standalone chezmoi binary to
/tmp chezmoi init --apply— lays down all dotfiles (prompts for GPG keys and tokens)- Installs nix via the official installer
- Adds your user to
trusted-usersin/etc/nix/nix.conf nix-env -ir user-macos— installs all packages (chezmoi, direnv, git, vim, etc.)- 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