4 years ago
Diving into Nix
At Shopify,
the dev-infra team has been working on using Nix from one of our internal tools,
dev
.
The tool is responsible for setting up the developers’ environment,
as well as providing a standard CLI for automation for projects like Rails, iOS, or Android apps.
As you probably know,
setting things up in a developer’s environment is wild —
you don’t know what to expect.
It’s hard to set things up deterministically,
and reproduce one environment into another.
Homebrew for instance,
tries to do as best as it can,
but since it treats the environment as a global space in which dumping things,
alike a singleton class that anyone can modify,
that often results in hard-to-debug errors.
The first time that I heard about Nix was on this blog post from Pinterest, but it didn’t catch my attention until now. I started reading about it and watching some internal videos that Burke is creating to evangelize the idea. The more I read about it, the more amazed I am with the idea. These are the ideas that struck me:
- Environments are defined in directories with symlinks to other directories that represent nodes of a dependency graph. Each node has a unique hash based on its content, the input, and the output.
- Every modification of your environment is tracked and can be rolled-back akin to how Git works.
- If one of those nodes needs to be built locally, the output artifacts can be shared remotely and pulled from other environments to speed things up.
- The dependency graph extends to components that are very core to the system. That prevents, among others, that macOS upgrades break the user environment.
- You can pull and run a package without polluting the environment.
- Nix provides its own expressive language that prevents developers from doing operations that might introduce side effects.
I’ll keep reading about it. I think Tuist could benefit from some of its ideas. For example, the idea of minimizing the IO and side effects, as well as the way it models the dependency graph.
I hope everyone is safe in these difficult times. Stay at home!