Live data from Hacker News

Package management on macOS with Nix-Darwin

davi.sh

11–20 of 33 posts

Re: Package management on macOS with Nix-Darwin

#11
(this prolly deserves its own blog post somewhere)

The most useful setup pattern I can share for both nix-darwin and home-manager is to configure them to store their rc files next to the system files, and not overwrite them ...

This keeps darwin/hm from fully replacing your mac /etc/zsh* ~/.zsh* files on each update and also keeps os system updates from destroying your nix files ...

You instead add sourcing statements in your system/home files to bring in your nix files.

These sourcing statements are nuked after every OS upgrade so first time you login, nothing looks right in your shell.

For this, I keep a copy of both the system file before the nix sources and a copy of the file after the nix sources ... If the post-updated version of the system file matches the backup then I can simply replace with the backup of the versions with sources included ... If they don't match, then I have to review the file, manually add the sources, and create new backups ...

I'll also say that the system files haven't changed in a long time (zsh) so I can just copy my etc/zsh*-nix-backup files into place then restart my shell and be back to good ...

Re: Package management on macOS with Nix-Darwin

#12

(this prolly deserves its own blog post somewhere) The most useful setup pattern I can share for both nix-darwin and home-manager is to configure them to store their rc files next to the system files, and not overwrite them ... This keeps darwin/hm from fully replacing your mac /etc/zsh* ~/.zsh* files on each update and also keeps os system updates from destroying your nix files ... You instead add sourcing statement…

Have you tried using the Determinate Systems installer? This (supposedly) helps to not break everything on system updates. As far as I can tell, it works.

Re: Package management on macOS with Nix-Darwin

#13
post #3

That's pretty cool that it can install Homebrew packages. Can anyone speak to how well that actually works in practice?

I prefer to keep most of my homebrew stuff (especially casks) in a nix-managed Brewfile with some logic about when to run/update.

Re: Package management on macOS with Nix-Darwin

#14
post #3

That's pretty cool that it can install Homebrew packages. Can anyone speak to how well that actually works in practice?

Extremely well, even supports passing arguments (`--HEAD`) through and integrates with services for casks too, so it can restart things like postgresql when homebrew updates it. Having nix-darwin uninstall brews not declared in the flake makes me stay honest about keeping my configuration up to date as well, if I've just `brew install x` to try something it'll get removed next time I apply my config. Needs adding to…

> Having nix-darwin uninstall brews not declared in the flake makes me stay honest about keeping my configuration up to date as well

Note that you don't need nix-darwin to achieve that. I keep my homebrew stuff separate from nix but still "keep myself honest" with this:

  HOMEBREW_NO_AUTO_UPDATE=1 /opt/homebrew/bin/brew bundle --file="$HOME/Brewfile" --cleanup --no-upgrade

Re: Package management on macOS with Nix-Darwin

#15
post #10

I have all the love and appreciation in the world for enjoying a weekend spent in configuration files. But I feel the need to state the obvious: This is a long blog post ending with a preview to "future installments of the guide" to use nix, while almost everything that you need to know with homebrew is `brew install/update/upgrade/uninstall`, and I have rarely run into any trouble with brew, and none at all in recen…

I'm recently back on macOS for work, and I wanted to love nix-darwin, but just couldn't get it even installed / basics running well enough to start to enjoy configuring things with it. The whole flakes mess really doesn't help. (Maybe if you're already running NixOS and familiar with the latest it's a lot easier.) I couldn't even uninstall it cleanly, since the Mac was new I gave up after some time and decided it was…

The hardest part of Nix module systems for foreign operating systems, like Nix-Darwin and Home Manager, is absolutely installing them. The difficult bits are the bits they don't control— the parts where they plug into the underlying OS.

If you wanna give Nix-Darwin another go, I'm happy to help. Feel free to hit me up in the main Nix / NixOS channel or the Nix on macOS channel on Matrix. Getting everything working shouldn't take long with a little guidance.

(I can also help you get it cleanly uninstalled without reinstalling macOS, if you come away unsatisfied. I have manually uninstalled (i.e., not using the uninstaller) before.)

Re: Package management on macOS with Nix-Darwin

#16
post #7
post #3

That's pretty cool that it can install Homebrew packages. Can anyone speak to how well that actually works in practice?

I use it to install a bunch of Homebrew casks and a small number of regular packages to support those casks. It works perfectly well! My biggest annoyance is that Homebrew is really slow; the Homebrew part of my Nix-Darwin rebuilds usuay takes 3-5x as long as everything else combined. Homebrew is really slow even when it has nothing to do. The only caveat worth mentioning is that the module built into Nix-Darwin does…

Make sure you are disabling auto-update and auto-upgrade for most of the homebrew slowness. I like to roll the update/upgrade into a single, intentional call rather than rely on homebrews built-in logic.

Re: Package management on macOS with Nix-Darwin

#17
post #2

I tried setting up nix-darwin with home-manager, but it just made the system more confusing to operate. Ended up using home-manager standalone without flakes. Works like a charm.

I stuck with home-manager standalone for many years, but after setting up other nixos configs I found myself wanting to 1) align systems more closely and 2) manage more system-level stuff on darwin. It took some time to rework my standalone modules to nix-darwin modules but overall I'm really happy with the result.

I run everything through an idempotent 'rebuild' script, so I don't really notice any day-to-day difference between nixos, standalone HM, or nix-darwin.

Re: Package management on macOS with Nix-Darwin

#18

(this prolly deserves its own blog post somewhere) The most useful setup pattern I can share for both nix-darwin and home-manager is to configure them to store their rc files next to the system files, and not overwrite them ... This keeps darwin/hm from fully replacing your mac /etc/zsh* ~/.zsh* files on each update and also keeps os system updates from destroying your nix files ... You instead add sourcing statement…

Have you tried using the Determinate Systems installer? This (supposedly) helps to not break everything on system updates. As far as I can tell, it works.

It adds a launchd service that makes sure stuff sourcing your Nix environment setup script is present in all your shell units on boot, so they get reestablished when macOS updates nuke them.

macOS apps do weird shit to work around macOS quirks. But it's a really good installer. Can't recommend it enough.

Post reply on HN