aryeh.fun Aryeh Hillman's Blog

nix

nix is good. It’s a lot of things, it can be hard to get everything that it’s about. But one thing that it is extremely good at it managing binary dependencies. One can think of it as a package manager like brew, apt, or pacman, except that one have unlimited number of minimal (or even mutually incompatible) environments whose definition can be easily shared with other developers (or just yourself, say, if you want to be able to quickly spin up an environment on another machine). It is also far more convenient than docker, as it runs natively as opposed to within a container, which can require setting up the network, often does not play well with your IDE, requires managing images, etc.

nix can also be used on CI/CD when you’re ready for it – meaning that you’ll have the same environment there as on your local box, more or less.

If you’ve used virtualenv for Python, you can think of nix as being just like it, except that it can manage higher-level binary dependencies like your language, your language’s package manager, etc. with ease.

To use nix as an environment manager for a given coding project, I suggest the following:

with import <nixpkgs> {}; mkShell {
  nativeBuildInputs = with pkgs;[
    ocaml # find more packages at https://search.nixos.org
  ];
}
  • run nix-shell then ocaml