I’m still quite new to the Nix scene, but I feel like I’ve finally got the language down and am managing all of my personal projects and machines with Nix to great success. My company uses PHP and we have TONS of small deployed projects, some of which are still on PHP 5.5.9 servers! I used to use brew to link between different PHP versions to match the deployment environment and, especially since brew’s support for PHP is quickly declining, it’s been a life-saver to have a
shell.nix for each of my personal projects.
I was giving a small presentation to my team about how I ensure that I’m keeping my environment pristine between projects by using Nix. One of my best examples was a new project that made use of Redis and the PHP Redis extension. For everyone else, who already had that extension installed because of previous use in various projects, it was surprising when I warned them that even though it “worked on their machines” it would explode on the stage environment. This was because I’d already set up a Nix shell file for the project and the unit tests exploded within the shell environment because that environment, which I’d tried to match as closely as possible to the stage environment, didn’t have the PHP Redis extension (I didn’t know about that requirement at the time). Adding that extension fixed the problem! Now I have a shell file for every project I work on, just in case.
My co-workers like the idea of Nix environments, but they dislike the idea of learning a new, complicated tool to catch issues like this. One said, “I don’t see why we don’t just make a Dockerfile for each project to accomplish the same result,” and since I’m not really much of a Docker user I didn’t have any response to that. Is there really any meaningful difference to us as developers when working on these separate projects between running our tests and other tools through Nix-shell or through a Docker container? I know that one issue is that of an immutable environment and that a Docker machine can “drift” over time, but I’m not sure if that’s really much of an issue if you rebuild the container every now and then.