I am not a regular macOS user, but I have never liked brew for some reason. Recently I got a MacBook
for personal projects and occasional work. Almost immediately I needed to use brew, because the built-in OpenSSH
doesn’t really work with FIDO2 SSH keys. Installing it from brew feels wrong to me, I don’t really know why;
call it personal preference.
Then I tried to google the alternatives and found out that there is a nix-darwin project! Turns out you can enjoy
nixpkgs repositories on macOS and nix’s declarative way of configuring your system.
I don’t want to describe the pros and cons of that approach, but for me it’s much more preferable
to using plain brew.
I still use brew for all GUI apps as casks, because it’s a legitimate case, in my opinion. 90% of packages are part
of my independent Home Manager configuration (so I could use it on the Linux machine as well), and the other 10% are
system-wide packages like openssh and libfido2 and something like podman.
Here is a small guide for someone who has never used nix and nix-darwin before. A few years ago nix installation was
pretty invasive. It was a simple bash script, and if you wanted to remove it later, it was an interesting quest,
I would say.
Today you can just use nix-installer; I prefer the one provided by the NixOS community.
Install nix-installer
Use the following command from their README:
curl -sSfL https://artifacts.nixos.org/nix-installer | sh -s -- install --enable-flakes
Follow the instructions, it should be pretty straightforward.
Install nix-darwin
We can break down this process into these steps:
-
Create the
/etc/nix-darwindirectory and set proper permissions -
Initialize a flake using the
nixyou installed usingnix-installer -
Replace the
simpleconfiguration with your hostname.Why? Because when you build or switch to the configuration,
nixby default searches for the configuration for your current machine based on the hostname. It’s common for people to use a single config across a fleet of their machines. -
Install
nix-darwinusingnixitself. -
Edit the configuration to your liking.
-
Switch your machine to that configuration.
Those steps are described in detail in the nix-darwin README.
Example configuration
Since /etc/nix-darwin is owned by your user, you can open that directory in your favorite editor and
start building your configuration. You can check my personal configuration here.
As of 2026, it’s pretty basic:
flake.nix- flake entry point and host outputs.hosts/- machine-specific system configurations.modules/- system-level modules grouped by platform.home/- Home Manager user configurations.home/common/- shared Home Manager modules for shell, git, ssh, fzf, starship, and user packages.
You can use it as an entry point for your own configuration.