Nix as an OS X package manager


advanced os x users are familiar with homebrew or macports to easily install and manage software packages. however, these two well-known tools are not the exclusive players. there is growing interest in nix, especially for its use on os x.

managing packages using nix is ​​fairly straightforward and intuitive. it works well enough to replace homebrew and macports. to get started, install nix by following the instructions:

curl | sh

nix only needs access to


, it doesn’t touch any other top-level directory (nix will never pollute your




). therefore, removing nix is ​​a matter of nuking that


phone book.

once installed, the primary command line tool that you will interact with the most will be


. try installing a trivial package like this:

$ nix-env -i hello
installing ‘hello-2.10’
these paths will be fetched (0.02 mib download, 0.07 mib unpacked):
fetching path ‘/nix/store/b6bxihaz9s5c79dsgbbxvjg8w44a036i-hello-2.10’...
$ hello --version
hello (gnu hello) 2.10

note the installation path, a particular subdirectory under


. the name contains the cryptographic hash of all entries needed to build the package, essentially capturing the full build dependencies. this enables powerful nix features such as easy management of multiple package versions, atomic installation and many more.

nix also creates a


for each user you are looking for once you find an executable (the importance of the nix profile itself will be more evident once you start to familiarize yourself with nix).

$ which hello

removing a package is as easy as installing it:

$ nix-env -e hello
uninstalling ‘hello-2.10’

in many cases, nix will install a package in its binary form (as built and cached by the hydra-based build farm).

wondering what you can install with nix? well, nix’s collection of packages (especially on os x, around seven thousand) isn’t as impressive as homebrew and macports. however, you can find the common packages already available, from git to vim (and its plugins). to list all the available packages:

Like any package manager, nix is ​​also useful for upgrading your arsenal of tools. for example, os x el capitan is armed with git 2.6 by default. but maybe you want to use the newer git 2.8 instead. it is not a difficult undertaking:

$ git --version
git version 2.6.4 (apple git-63)
$ nix-env -i git
warning: there are multiple derivations named ‘git-2.8.0’; using the first one
installing ‘git-2.8.0’
$ which git
$ git --version
git version 2.8.0

later if you decide you don’t like the latest version and prefer to stick with the default version, the rollback leaves no significant residue and returns the system state exactly before you installed git 2.8 :

$ nix-env -e git
uninstalling ‘git-2.8.0’
$ which git
$ git --version
git version 2.6.4 (apple git-63)

these package management tasks are not unique to nix. wait for the rest of this post, where we learn the power of nix to comfortably manage multiple environments (eg python 2.7 vs python 3.5).


Comments are closed.