Reproducible Dev Environments
Some folks at work have been looking at Dockerization of our dev environment to make it work more consistently across people’s computers. This may be less ideal on Macs, given the need to run a VM, so I’m starting some notes here about other potential options.
The Nix package manager is one way to get a reproducible dev environment on the Mac without containers, which currently rely on Linux.
Nix on the Mac
Jean-Philippe blogged about using Nix in his Mac dev workflow. Martin Myrseth has another blog post about using Nix for a development environment.
Sander van der Burg presented on the topic of deploying npm packages with Nix.
nix-shell doesn’t fully isolate you
One aspect of a “reproducible” environment is one that is isolated enough from other things on the developer’s system so that dependencies build properly. There’s a balancing act, though, because you need some things from the host system. On a Mac, you’d want access to the standard system-provided frameworks, for example.
Then there comes the question about how to handle programming language-specific dependencies. It seems to me that there’s a lot of friction to having to make Nix packages out of, for example, every Node package that you use. If you can set up a Nix environment with Node and Yarn and then use Yarn to install the rest in a reproducible manner, that may be enough.
I tried setting up an environment using
nix-shell --pure. My first impression was that it was easy to set up the environment, packages were readily available, and typing
python -v, and
go version all immediately returned exactly what I expected. The problem I encountered when putting it to a real-world test was that tools would break out of the shell.
node-gyp (used for building binary modules for Node packages) kept finding my nvm version of node, even when I removed nvm from my .bashrc. It wanted to use
/usr/local/bin/python3 instead of the Nix-provided one.
There is an open Nix issue about running nix-shell without the user’s .bashrc and even a merged pull request to help with this, but neither did the trick. node-gyp seems to have issues generally with cleanly operating within a Nix environment.
I also encountered problems with Python not finding setuptools or not being able to install pyobjc. I didn’t look very far into those issues, though.