1. 39
  1.  

  2. 13

    Just a note: you don’t strictly need nix-darwin if all you want to do is install and use packages via Nix. Try home-manager instead, which can also manage your dotfiles. I use it (see here) to declaratively configure my dotfiles and packages across Linux, macOS, ChromeOS & WSL (Windows).

    1. 3

      I like the nix-darwin due to being able to configure launchd services. I am running dnsmasq locally to resolve all *.localhost requests to loopback address, so I am able to work with multiple domains locally (useful for web development). And you can manage dotfiles with nix-darwin as well, of course it will be less straightforward than home-manager but is fully doable.

    2. 9

      Wanted to comment on the “Install Nix:” section since I helped narrowly with the Catalina installer update this May, just finished updating the Nix installer for Big Sur, and happen to be working this morning on a draft PR that may finally de-complicate Catalina+ installs.

      This works.

      Edit: I think I told a small lie; this method of install works, but the correct incantation is actually curl -L https://nixos.org/nix/install | sh :)

      • Catalina with a T2 chip: sh <(curl -L https://nixos.org/nix/install) –darwin-use-unencrypted-nix-store-volume (according to the site, “unecrypted” is a misnomer as the chip will encrypt it anyway).

      The scare-flag’s goal is to encourage anyone who cares (or is compelled to care by some policy) to go read the docs before installing. “Unencrypted” is only a ~misnomer for T2 macs and is quite accurate on non-T2 macs :)

      • Catalina without a T2 chip: follow these instructions 4.

      It isn’t this complicated/manual on a non-T2 Mac unless you use FileVault (in which case, the linked instructions are a good resource). If you do not use FileVault, sh <(curl -L https://nixos.org/nix/install) --darwin-use-unencrypted-nix-store-volume should be sufficient.

      1. 1

        Thanks for the info! I’ll update the post later tonight.

        1. 1

          If you see it as an evergreen post, you may want to keep an eye on https://github.com/NixOS/nix/pull/4181. I can’t swear if/when it’ll land, but hopefully it’ll de-complicate things a little.

      2. 4
        1. 4

          but you will have to edit a .nix file to install a package (there is no CLI equivalent to brew install that I am aware of)

          It’s possible to install packages with nix-env -i, though I’m not sure if that’s the right thing to do with nix-darwin.

          (Since plain nix-env -i seems to take ages resolving the argument to a package, my usual workflow is nix-search followed by nix-env -iA nixpkgs.<...>.)

          1. 3

            When my job forced a Macbook on me, I had similar frustrations with Homebrew, I didn’t like how it used /usr/local for everything, and seemed much messier than Linux-native package managers. I switched for Nix pkgs for work involving Python, and command-line utilities (I still used Homebrew for software with a GUI), and things improved dramatically. Nix-shell could do everything I needed Python’s virtualenv for and far more, and made deployment much simpler (and deployment was cross-platform as well). It was not without pain points though, as there’s a learning curve to the Nix expression language.

            1. 4

              I dislike homebrew too, which is why I use macports. Have you considered that?

            2. 2

              Switching to Nix is much harder than setting it up thanks to the deep integration of package managers :(

              1. 2

                I just switched from homebrew to pkgsrc on my mac. I don’t need a package manager much on the mac and I bet pkgsrc will serve me well. The installation was quite straight forward. I thought about using nix on it but my past experience with it on Mac OS X was bittersweet, the potential was there but having to do backflips to appeal the shit stuff that Apple been doing with macOS proved to be too much friction to me.

                1. 1

                  nix-darwin install doesn’t work

                  % nix-build https://github.com/LnL7/nix-darwin/archive/master.tar.gz -A installer ./result/bin/darwin-installer
                  unpacking 'https://github.com/LnL7/nix-darwin/archive/master.tar.gz'...
                  error: getting status of '/Users/whatever/result/bin/darwin-installer': No such file or directory
                  1: nix-build https://github.com/LnL7/nix-darwin/archive/master.tar.gz -A installer ./result/bin/darwin-installer
                  

                  Edit: https://listed.to/@estysdesu/17088/nix-os-on-darwin helped. The following works:

                  #!/usr/bin/env bash
                  set -xv
                  ##### INSTALL NIX #####
                  wget -qO - https://nixos.org/nix/install | sh -s -- --daemon --darwin-use-unencrypted-nix-store-volume
                  
                  source ~/.nix-profile/etc/profile.d/nix.sh
                  
                  ##### START NIX DAEMON #####
                  sudo -b nix-daemon # launchctl script for nix-daemon
                  
                  ##### INSTALL NIX-DARWIN #####
                  sudo -b su
                  NIX_DARWIN_INSTALLER="$TMPDIR/nix-darwin-installer"
                  mkdir -p "$NIX_DARWIN_INSTALLER" && cd "$NIX_DARWIN_INSTALLER"
                  nix-build https://github.com/LnL7/nix-darwin/archive/master.tar.gz -A installer
                  ./result/bin/darwin-installer
                  
                  1. 1

                    I should try this again, I guess. I’m not super happy with Homebrew, but it at least a) has everything I want and b) sort of kind of works OK, with brew bundle. I do run nixos on my Linux machine, so I’m not unfamiliar. I guess everything on the Mac that thinks about the CLI environment is going to feel like fighting the system to me, so I should sort of get over it.

                    1. 1

                      The article included a link about Macports vs Homebrew was a pretty compelling one for me: https://saagarjha.com/blog/2019/04/26/thoughts-on-macos-package-managers/

                      1. 2

                        I mean, the Unix user is a pointless relict on my machines at this point, so I don’t particularly find that argument compelling.

                        The other arguments, about the state of the open source projects themselves, are more resonant with me, but still, don’t rise to the level of discomfort that might have me switching.