Closed will-ca closed 1 year ago
Having nix as an alternative to docker for self-contained reproducible environments seems reasonable - I've no idea how that works, but pull requests would be welcome :)
(I expect we'd still want the Docker image for windows users to have a reproducible dev environment, as it seems nix doesn't work there?)
I started putting together a flake for this repo last month; it's since fallen out of date (and I only got as far as doing C++/Rust/Zig/Go) but if there's interest and if it looks like something that upstream would accept I'm happy to update it and add Nim/PHP/Python support.
I have interest \o/
Especially if utils/shell.sh
was updated to use nix if that's installed, else use docker if that's installed, else error -- then the docs can be "use this script to get a self-contained dev environment in whatever way is appropriate for your system"
(There should probably also be a shell.bat for windows users, but that's an issue for another time...)
Just FYI I've got a branch where I've set up a working shell.nix
for all of the implementations except for Zig (which I think I did, but still need to test/finish), as well as a global shell.nix
that imports and combines every language implementation together. Will finish off and then PR with details later.
Do all the languages work well on Windows?
AFAIK all the languages should work on windows, but I've only personally used linux and macos
closing this as nix is now my main development method for mac-based development
(though if somebody wants to put up a PR showing how flakes would work and why they're better, that would be interesting too)
I got the below error trying to run the Zig version:
Rather than endlessly trying to keep track of libraries, version incompatibilities, etc., I think Nix can be used to declaratively define reproducible, self-contained development environments as needed.
For example, I have the below
shell.nix
file for the Python version:(To read this if you haven't looked into Nix before: The language is functional. Colons are function definitions, with signature to the left and the return expression to the right. Calls are names followed by a space and then argument.
With
makes names from a mapping available in the subsequent scope. Lists are whitespace-separated, and curly braces are mappings. — The root expression is a function that takes the argumentpkgs
(or actually uses the default valueimport <nixpkgs> {}
) and returns an environment, and the argument passed to.withPackages
is a function that takes the argumentpypkgs
and returns a list of Python packages.)And then, anyone on any distro of Linux or MacOS can just run
$ nix-shell
in the terminal to get the exact right development environment. The packages are stored entirely self-contained in/nix
, and symlinked in~/.nix-profile
or added to$PATH
as requested.For perfect reproducibility, the packages used can be pinned to a specific version by downloading from a specific commit in the
nixpkgs
respository. So this way, if you specify a version of a library or language that works on your machine, anyone else running it will get the exact same version.More info:
https://nixos.org/guides/declarative-and-reproducible-developer-environments.html
I'm not trying to evangelize. I bring this up as somebody who is reluctant to modify my global computing environment for a local requirement— I.E. I'm not going to change my system Zig, set up
venv
s everywhere, or install newpip
packages just to run this, so I was just thinking it'd be useful if a declarative ad-hoc environment were provided.I do see there's already something similar with Docker/Podman, which I guess fills the same purpose. But that seems heavier (pulling in a whole Debian, looks like?), and involves more permissions and system configuration to set up. — FWIW, Nix can also be used to generate Docker images, and it looks like there's a Nix image on Docker (though I haven't tried either).
Anyway, it's just an idea.