These are my dotfiles. Take anything you want, but at your own risk.
They are used for configuring several of my environments:
- MacBook with nix-darwin,
- NixOS VM running via UTM on the MacBook,
- user account on a shared company NixOS server.
~/.dotfiles/
├── flake.nix # Define all machines
├── flake.lock # Lock all dependencies
│
├── common/ # Shared modules across all systems
│ ├── direnv.nix
│ ├── files.nix
│ ├── gitconfig.nix
│ ├── tools.nix
│ ├── vim.nix
│ └── zsh.nix
│
├── macos/
│ ├── zbook.nix # nix-darwin for my MacBook
│ └── home.nix # Home Manager for my MacBook
│
├── nixos/
│ └── utm/ # UTM VM
│ ├── configuration.nix
│ ├── hardware-configuration.nix
│ └── home.nix
│
├── .secrets.env # Environment variables for secrets (git-ignored)
├── .secrets.ssh # Private SSH hosts configuration (git-ignored)
├── mkcert/ # development certificates
└── vscode/ # VS Code settings
TODO...
-
Use the official Nix installer for macOS: https://nixos.org/download.html#nix-install-macos
-
Follow
Flakesinstall steps for nix-darwin: https://github.com/LnL7/nix-darwin -
Another great resource is: https://nixcademy.com/2024/01/15/nix-on-macos/
-
Get my dotfiles and link them to places where they are used:
$ git clone https://github.com/zupo/dotfiles.git ~/.dotfiles
$ ln -sv ~/.dotfiles/vscode ~/Library/Application\ Support/Code/User
$ echo 'machine niteo.cachix.org password <CACHIX AUTH TOKEN>' >> ~/.config/nix/netrc
-
Create secret files in the
.dotfilesdirectory:.secrets.envfor environment variables:export OPENAI_API_KEY="sk-proj-..." export CACHIX_AUTH_TOKEN="..."
.secrets.sshfor SSH hosts:Host cruncher HostName 192.168.1.100 -
nix-channels are implicit and bad, so I remove them and instead use flakes to pin to exact nixpkgs commit hashes:
$ rm ~/.nix-channels
$ rm ~/.nix-defexpr/channels
$ rm ~/.nixpkgs/
- What to do with
/etc/zshrcand/etc/zprofile?
MacOS comes with the following:
/etc/zprofile/etc/zshrc/etc/zshrc_Apple_Terminal
I don't use it because it only provides load /usr/libexec/path_helper which is slow and not needed.
Also, nix-darwin/nix-darwin#532.
I don't use it because it only provides two features I don't need:
- emacs support,
- automatic history save/restore -> I prefer to use a shared history.
I override this one with my personal settings using flake.nix
In the end, the /etc folder should be like this:
/etc ➜ ls -l z*
lrwxr-xr-x 1 root wheel 20 Sep 14 18:17 zprofile -> /etc/static/zprofile
lrwxr-xr-x 1 root wheel 18 Apr 7 2020 zshenv -> /etc/static/zshenv
lrwxr-xr-x 1 root wheel 17 Sep 20 11:30 zshrc -> /etc/static/zshrc
Related: nix-darwin/nix-darwin#193
To update to the latest release in the currently used channel, run
nix flake update followed by nixre.
When a new nixpkgs channel is released, do the following:
- update the
nixpkgs.urlinput inflake.nixto the new channel - run
nixre
If you see this error when trying to reinstall, follow https://discourse.nixos.org/t/ssl-ca-cert-error-on-macos/31171/5.
If you see an error like this:
> mkdir: cannot create directory '/nix/store/31k835115bylz5qb3k7vhcvfgrl4cwpl-nixos-disk-image/nix-support': No space left on deviceThe problem might not be with your macOS disk space, but with the nix-darwin's linux-builder disk space. Fix it like this:
$ sudo ssh linux-builder
[builder@nixos:~]$ nix-collect-garbage