Nix modules for darwin, /etc/nixos/configuration.nix for macOS.
This project aims to bring the convenience of a declarative system approach to macOS. nix-darwin is built up around Nixpkgs, quite similar to NixOS.
The only prerequisite is a Nix implementation; both Nix and Lix are supported.
As the official Nix installer does not include an automated uninstaller, and manual uninstallation on macOS is a complex process, we recommend using one of the following installers instead:
-
The Nix installer from Determinate Systems is only recommended for use with flake-based setups. It can install one of two distributions of Nix:
-
To install the recommended vanilla upstream Nix, you will need to explicitly say
nowhen prompted to installDeterminate Nix. -
When run with the
--determinateflag, it will install the Determinate distribution. As Determinate manages the Nix installation itself, you will need to setnix.enable = false;in your configuration to disable nix-darwin’s own Nix management. Some nix-darwin functionality that relies on managing the Nix installation, like thenix.*options to adjust Nix settings or configure a Linux builder, will be unavailable.
-
-
The Lix installer supports both flake-based and channel-based setups.
Despite being an experimental feature in Nix currently, nix-darwin recommends that beginners use flakes to manage their nix-darwin configurations.
Flakes (Recommended for beginners)
Getting started from scratch
If you don't have an existing configuration.nix, you can run the following commands to generate a basic flake.nix inside /etc/nix-darwin:
sudo mkdir -p /etc/nix-darwin
sudo chown $(id -nu):$(id -ng) /etc/nix-darwin
cd /etc/nix-darwin
# To use Nixpkgs unstable:
nix flake init -t nix-darwin/master
# To use Nixpkgs 25.05:
nix flake init -t nix-darwin/nix-darwin-25.05
sed -i '' "s/simple/$(scutil --get LocalHostName)/" flake.nixMake sure to check if nixpkgs.hostPlatform is set to either x86_64-darwin for Intel or aarch64-darwin for Apple Silicon.
Migrating from an existing configuration.nix
Add the following to flake.nix in the same folder as configuration.nix:
{
description = "John's darwin system";
inputs = {
# Use `github:NixOS/nixpkgs/nixpkgs-25.05-darwin` to use Nixpkgs 25.05.
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
# Use `github:nix-darwin/nix-darwin/nix-darwin-25.05` to use Nixpkgs 25.05.
nix-darwin.url = "github:nix-darwin/nix-darwin/master";
nix-darwin.inputs.nixpkgs.follows = "nixpkgs";
};
outputs = inputs@{ self, nix-darwin, nixpkgs }: {
darwinConfigurations."Johns-MacBook" = nix-darwin.lib.darwinSystem {
modules = [ ./configuration.nix ];
};
};
}Make sure to replace Johns-MacBook with your hostname which you can find by running scutil --get LocalHostName.
Make sure to set nixpkgs.hostPlatform in your configuration.nix to either x86_64-darwin (Intel) or aarch64-darwin (Apple Silicon).
Unlike NixOS, nix-darwin does not have an installer, you can just run darwin-rebuild switch to install nix-darwin. As darwin-rebuild won't be installed in your PATH yet, you can use the following command:
# To use Nixpkgs unstable:
sudo nix run nix-darwin/master#darwin-rebuild -- switch
# To use Nixpkgs 25.05:
sudo nix run nix-darwin/nix-darwin-25.05#darwin-rebuild -- switchAfter installing, you can run darwin-rebuild to apply changes to your system:
sudo darwin-rebuild switchInputs from the flake can also be passed into darwinSystem. These inputs are then
accessible as an argument inputs, similar to pkgs and lib, inside the configuration.
# in flake.nix
nix-darwin.lib.darwinSystem {
modules = [ ./configuration.nix ];
specialArgs = { inherit inputs; };
}# in configuration.nix
{ pkgs, lib, inputs }:
# inputs.self, inputs.nix-darwin, and inputs.nixpkgs can be accessed hereChannels
Copy the simple example to /etc/nix-darwin/configuration.nix.
# If you use Nixpkgs unstable (the default):
sudo nix-channel --add https://github.com/nix-darwin/nix-darwin/archive/master.tar.gz darwin
# If you use Nixpkgs 25.05:
sudo nix-channel --add https://github.com/nix-darwin/nix-darwin/archive/nix-darwin-25.05.tar.gz darwin
sudo nix-channel --updateTo install nix-darwin, you can just run darwin-rebuild switch to install nix-darwin. As darwin-rebuild won't be installed in your PATH yet, you can use the following command:
nix-build '<darwin>' -A darwin-rebuild
sudo ./result/bin/darwin-rebuild switch -I darwin-config=/etc/nix-darwin/configuration.nixAfter installing, you can run darwin-rebuild to apply changes to your system:
sudo darwin-rebuild switchYou can update Nixpkgs and nix-darwin using the following command:
sudo nix-channel --updatedarwin-help will open up a local copy of the reference documentation, it can also be found online here.
The documentation is also available as manpages by running man 5 configuration.nix.
To run the latest version of the uninstaller, you can run the following command:
sudo nix --extra-experimental-features "nix-command flakes" run nix-darwin#darwin-uninstaller
If that command doesn't work for you, you can try the locally installed uninstaller:
sudo darwin-uninstaller
There are basic tests that run sanity checks for some of the modules, you can run them like this:
# run all tests
nix-build release.nix -A tests
# or just a subset
nix-build release.nix -A tests.environment-pathLet's make Nix on macOS awesome!
Don't hesitate to contribute modules or open an issue.
To build your configuration with local changes you can run this. This
flag can also be used to override darwin-config or nixpkgs, for more
information on the -I flag look at the nix-build manpage.
sudo darwin-rebuild switch -I darwin=.If you're adding a module, please add yourself to meta.maintainers, for example
meta.maintainers = [
lib.maintainers.alice or "alice"
];
options.services.alicebot = # ...The or operator takes care of graceful degradation when lib from Nixpkgs
goes out of sync.
Feel free to contact us on Matrix if you have questions:
- User support: #macos:nixos.org
- Development discussion: #nix-darwin-dev:nixos.org
