This post is part of the Series: Nix can .
We just got new developer machines at work, so I decided to try setting up Nix for this machine as well. Nix-darwin that is, as it’s a mac. Did I mention its an M3? 🤤
What’s darwin?
Darwin is the core Unix operating system of macOS, iOS, watchOS - and all the other xyzOSs Apple develops.
What’s nix-darwin?
Nix-darwin is kinda like NixOS but for macos. While NixOS is a linux distribution, nix-darwin integrates “the nix way” of managing packages and installing and configuring software, alongside modules providing a declarative nix-like approach to configuring some of the macos system settings - just not to the depths of where NixOS goes. And its still macos underneath.
You can configure a whole bunch of stuff . Among other things:
- Useful global os settings
- Keyboard settings, and some remappings
- Trackpad settings
- Dock settings
- Finder settings
- ++
Homebrew and mas integration
Nix-darwin integrates with Homebrew and mas , which means you can use a single system for managing packages across all these package managers.
Some examples of what you could do with this include
- Install Homebrew programs, from selected taps
- Install Homebrew Casks, like Intellij and Swiftbar, from selected taps
- Install Apps from the Mac App Store, like Amphetamine
- Install a whole bunch of packages from the central nixpkgs repo
- ++
Home manager
You can use also use the same home-manager to manage dotfiles and user applications , like you would on a linux system.
Uncertainty of continued support
While derivations like those found on nixpkgs , that are descriptions of how Nix should build the software, can run on many architectures, care needs to be taken by their creators to adapt them to the specific platforms that they are to build the software for. This means that a lot of derivations that exist on nixpkgs include special handling of how darwin should be handled.
Over the years issues repeatedly surface that question whether or not darwin should continue to be supported . Build infrastructure seems to be lagging and burden of keeping darwin packages up to date is placed on linux users, that are the primary contributors of many packages. Apple’s recent shift from x86 to arm hardware seem to have worsened the situation. Some express frustration and indifference towards darwin, suggesting downgrading its support, while others highlight the importance of darwin for cross-platform capabilities and the Nixpkgs community in general. There’s seems to be a consensus on the need for improved darwin support, with suggestions for focusing on aarch64.
Other issues
I have not spent long enough time on nix-darwin to have met any darwin specific issues that I was not able to work around in an OK way. One issue I did face was that home-manager is linking .app files
into ~/Applications/
, which trips up applications like Alfred and Spotlight that seem to expect non-symlinked apps. There are seemingly no perfect solutions to this
. This seems to work OK
for me.
Also, when you recreate your system for the millionth time, you might end up with multiple applications that no longer represent what your config means should be the current one, meaning commands like open -a <app name>
and Open With
might open apps you no longer mean to have installed. Remember to run nix-collect-garbage
every once in a while to clean up leftover applications.
Multiple system configurations in a single repo
The repo I have set up to keep this configuration for the new mac lives here:
https://github.com/torgeir/nix-darwin/
Why is it a separate repo from torgeir/nix ? Nix supports combining these kinds of configurations and reusing modules across systems, even though they are for separate systems on different architectures.
As this is an early phase of me trying out both nix and nix-darwin I chose to keep them separate for now, not to introduce even more unnescessary complexity.
Let’s be honest, there’s more than enough lurking in here already! 🧶.
Resources
- https://github.com/LnL7/nix-darwin
- https://xyno.space/post/nix-darwin-introduction
- https://www.chrisportela.com/posts/home-manager-flake/
- https://dev.jmgilman.com/environment/tools/nix/nix-darwin/
- https://github.com/ingara/dotfiles/tree/flakes
- https://github.com/okpedersen/dotfiles/blob/master/common-dev-tools.nix