7 ms·
Package management on macOS with Nix-Darwin
- NewJazz 2y agoI 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.
- JamesSwift 2y agoI 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.
- earthling8118 2y agoWith or without flakes works nearly identically if it is just home-manager configurations
- _mlbt 2y agoThat's pretty cool that it can install Homebrew packages. Can anyone speak to how well that actually works in practice?
- caiusdurling 2y agoExtremely 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 the flake to keep it installed persistently, which in turn means my config tends to be up to date.
- JamesSwift 2y ago> 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
- pxc 2y agoI 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 doesn't support installing Homebrew itself. Instead you tell it the prefix for an existing Homebrew installation. (There is an out-of-tree module for installing Homebrew as well, but I haven't tried it.)
- JamesSwift 2y agoMake 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.
- pxc 2y agoThat's the default for Nix Darwin's Homebrew module, see: https://github.com/LnL7/nix-darwin/blob/230a197063de9287128e2c68a7a4b0cd7d0b50a7/modules/homebrew.nix#L94 https://github.com/LnL7/nix-darwin/blob/230a197063de9287128e... and https://github.com/LnL7/nix-darwin/blob/230a197063de9287128e2c68a7a4b0cd7d0b50a7/modules/homebrew.nix#L139 https://github.com/LnL7/nix-darwin/blob/230a197063de9287128e... By default, brew commands run manually do still perform the automatic updates, though. That can be disabled with the following Nix-Darwin option: https://daiderd.com/nix-darwin/manual/#opt-homebrew.global.autoUpdate https://daiderd.com/nix-darwin/manual/#opt-homebrew.global.a...
- JamesSwift 2y agoI'm not sure whats taking so long then. My entire darwin-rebuild switch takes ~1s without the homebrew commands. If I manually run homebrew separately it takes ~4s the first time and ~1.5s in subsequent runs.
- pxc 2y ago
- JamesSwift 2y agoI prefer to keep most of my homebrew stuff (especially casks) in a nix-managed Brewfile with some logic about when to run/update.
- IfOnlyYouKnew 2y agoI 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 recent memory.
- wenc 2y agoI have used brew trouble free for many years.
- OJFord 2y agoI'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 easier to reinstall macOS (which takes several hours but at least I can just leave it and then know that it's done). So I'm back to (purely) brew (and scripts to `defaults write` etc.). My frustration with brew is that it's getting increasingly opinionated, and those opinions are not familiar to me from any other OS/package manager... Like if you want postgres v15 you have to `brew install postgresql@15`, and then even if that's your only installed version it's 'keg-only', which means it's not on your PATH, and their suggestion is to dump some stuff at the end of your ~/.zshrc, which aside from the fact you're not using zsh and they could tell that, just seems dumb. Then there's python & npm packages... They're deprecated and being removed as independent formulae, so don't do it like that. You're not allowed to install them with the python/node formula you installed, so don't do that. So what do you do, `python -m venv ~/system-python-venv` or something, activate it, and install in there. And now remember to activate that every time you want to use a command that happens to be a python package so you had to install it there. Or dump it in the end of your zshrc, I guess!
- pxc 2y ago
- dlyons 2y agoI’ve wrapped nix-darwin, home-manager etc in a Nix configuration for macOS, with a starter template and simple installer. I’ve been running it for a couple years, you can use it to try Nix without as much up front learning. Almost 1000 stars! https://github.com/dustinlyons/nixos-config https://github.com/dustinlyons/nixos-config Edit: Just crossed 1k! Thanks HN
- dudus 2y agoI could never get into nix on Mac os. Maybe it's a different thing if you use nixOS but I'm not willing to make that jump. It seems the clear barrier to entry to nix is UX and to an extent the custom language they use. Maybe this problem can be solved with LLMs. We need an LLM fine tuned to write nix language.
- thomastjeffery 2y agoThe language itself isn't as challenging as the overall structure of NixOS/nixpkgs itself. It's a monolithic source-tree of interdependent "derivations". The entire notion of "package" has been thrown halfway out the window. There is logic and reason to the madness, but it's really difficult to find your bearings.
- earthling8118 2y agoSo the barrier to nix is... nix? No, the language is not the problem. It is not a particularly difficult language at all. There are plenty of actual problems to address, but the language isn't the issue.
- davidpfarrell 2y ago(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 ...
- jordanreger 2y agoHave 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.
- pxc 2y agoIt 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.
- jordanreger 2y agoInteresting. Good to know!
- hazebooth 2y agoWithout reading the article: I've used Nix on macOS without nix-darwin or home-manager for some time now. I define my packages in a flake.nix that exports an environment and I use install using `nix profile`.
- pxc 2y agoThat's a great setup for package management. Stuff like Nix-Darwin and Home Manager start to shine when you want to also do some configuration management. For just package management, your approach is probably better in that it's simpler.
- deleted 2y ago[deleted]