3 ms·
I’m curious about nix in macOS. I’ll Kagi / chatgpt it in a bit, I’m sick of brew. But was hoping to hear your experiences as well (assuming you’re not a genera
by fnordpiglet 4y ago
I’m curious about nix in macOS. I’ll Kagi / chatgpt it in a bit, I’m sick of brew. But was hoping to hear your experiences as well (assuming you’re not a generative AI). I run a nixos home server so am familiar, just not with using it for macOS.
- pxc 4y agoNix support on macOS is pretty good, but it's not the main OS of most Nixpkgs contributors and that does show in some ways, and there are some differences in using it as a 'guest' package manager rather than having it run the whole show. First, the bad: Apple does minorly break things on every OS upgrade by nuking all of your systemwide shell RC files, besides the more substantial. (There's been some investigation into more robust ways to get that integration working, but so far none of the leads are very promising.) Nix on macOS has to do some weird stuff to achieve integration due to macOS' security features like SIP and non-writable /. Nowadays the installer just takes care of this. macOS GUI apps don't get built by Hydra, so they're not in the binary cache. This is because they require proprietary software (Xcode) to build, and Hydra doesn't build or cache non-free derivations as a legal precaution. For grabbing things like iTerm or whatever, you might prefer using Homebrew in a limited way ('casks' only) with a non-standard prefix. This is what I have done and recommend doing. (That said, macOS GUI apps do exist in Nixpkgs and they build just fine, so if you want you can still use Nix for your iTerm and your custom Emacs build and whatever.) Now the good parts: Package availability on macOS is still great. Nix feels really fast compared to Homebrew! There's a new, alternative Nix installer available from a credible company in the Nix community that seems to cope a bit better with macOS' integration quirks, making uninstalling and reinstalling a bit easier: https://github.com/DeterminateSystems/nix-installer https://github.com/DeterminateSystems/nix-installer If you like NixOS' declarative style and service/configuration management capabilities, there's an awesome module system that lets you get a very similar experience on macOS: https://daiderd.com/nix-darwin/ https://daiderd.com/nix-darwin/ The ugly(?): The default build environment for packages on macOS uses a completely different toolchain than Nix uses on Linux. LLVM instead of GCC, libsystem instead of glibc. This is appropriate and generally invisible, but you may notice it and think about it when writing your own packages or something like that. Nix builds and the environment in general are a bit less 'pure' on macOS. Some of that is part of what I just mentioned above. Another aspect is that Nix builds are not sandboxed on macOS. I hope that helps! Overall, if you like NixOS, I think you will find lots to like about Nix on Mac. :)
- fnordpiglet 4y agoAmazing thank you super helpful!
- yusefnapora 4y agoNot the person you're asking, but I use nix on my MacBook and ditched brew after a few weeks. The main draw for me was that I was already using home-manager on NixOS, and being able to share the same config on macOS was pretty compelling. I had to sprinkle a couple conditionals in the home-manager config to account for things that are linux-only, but it was pretty painless. Here's an example of using `pkgs.stdenv.isLinux` to conditionally install stuff (there's also an `isDarwin`, if you prefer): https://github.com/yusefnapora/nixos-system-flake/blob/660dd2619f1cd728845ffe2a5d4b8815cc0c5185/home-manager/programs/gui/default.nix#LL51 https://github.com/yusefnapora/nixos-system-flake/blob/660dd... For my own use case, I install a few things "globally" in my home-manager config (neovim, vscode, fish shell, etc.). Then each of my projects gets its own flake with a devShell, and I use nix-direnv to bring things into the PATH when I cd into the project directory. I also use `nix shell` a fair bit if I just want to run something in a one-off shell session. You can also use nix profiles if you're looking for a more brew-like experience, but I never really mess with those. I figure if I want something to be persistently installed, it's better to just stuff it into my home-manager config so it will be there on all my machines. On the whole, I much prefer nix to brew. I'd still recommend brew to people that don't want to bother with learning nix, but if you're already running NixOS I'd say go for it.
- fnordpiglet 4y agoThanks! Super helpful.