3 min read

Nix is the best package manager i've ever used

Table of Contents

Many developers on MacOS use Homebrew to install software. Homebrew is a package manager for MacOS. It is a great package manager, but the problem is that after a while your system becomes bloated and thus slower.

You can also transfer your whole system to another Mac, and you won’t have to find and reinstall all of your packages again.

Nix is a package manager with a declarative nature meaning that it is very easy to install and uninstall software. (and no downsides!)

What about my homebrew packages?

With Nix-darwin, you can install homebrew packages straight from the config file, which allows you to keep in track what homebrew packages you have installed, and uninstall them with ease. It also has a configurable behaviour in which it zaps all of your existing homebrew packages to get a fresh start.

How did I configure it?

I’m using nix-darwin to configure my nix environment. I have a ~/.config/nix/flake.nix file in which I declare my packages using both Nix and Homebrew:

environment.systemPackages = [
  pkgs.neovim
  pkgs.tmux
  ...
];

homebrew = {
  enable = true;
  casks = [
    "aerospace"
    "notion"
    "notion-calendar"
    "clop"
  ];
  brews = [
    "geometry"
    "romkatv/gitstatus/gitstatus"
    "jnsahaj/lumen/lumen"
    "imagemagick"
  ];
  onActivation.cleanup = "zap";
  onActivation.autoUpdate = true;
  onActivation.upgrade = true;
};

(the full file can be found here)

As you can see, I install most of my packages from Nix which keeps them in a separate environment, and I use Homebrew packages for the few packages that I can’t find in Nix or don’t work properly with Nix.

The only downside is that every time I want to install a new package, I have to rebuild my entire environment, but Nix is very fast so it’s not a big deal.

Bonus features

Nix-darwin allows you to easily set your MacOS settings straight from the configuration file. This means you can have the same MacOS settings on all your machines that can also be updated easily.

system.defaults = {
  dock.autohide = true;
  dock.orientation = "left";
  dock.show-recents = false;
  dock.showhidden = true;
  dock.mru-spaces = false;
  dock.persistent-apps = [
    "/Applications/Formalsurf.app"
    "/Applications/Ghostty.app"
    "/Applications/Vesktop.app"
    "${pkgs.obsidian}/Applications/Obsidian.app"
    "${pkgs.youtube-music}/Applications/YouTube Music.app"
  ];
  finder.FXPreferredViewStyle = "clmv";
  loginwindow.GuestEnabled = false;
  screencapture.location = "~/Pictures/screenshots";
  screensaver.askForPasswordDelay = 10;
  NSGlobalDomain.AppleICUForce24HourTime = true;
  NSGlobalDomain.AppleInterfaceStyle = "Dark";
};

Conclusion

Nix is a great package manager, and I am very happy with it. Now, I also don’t have to worry about losing my system nor bloating it.

You can check out my dotfiles for more information, and the full configuration file here.

Thanks for reading!