The setting

Using Nix to manage development environments is a very good choice: It works cross language, it handles C dependencies quite nice, it works on MacOS and Linux in the same way and it provides a ton of nice extra features.

Looking from the perspective of a developer, the following command should get you set up:

nix-shell

I have written down a few notes about how to use it for Node and for Python if you are interested in more details about how I am using it for my projects currently.

Channels

One benefit is that Nix comes together with a huge package collection: Nixpkgs. It is available via different channels, most interesting for development are the channels unstable and stable. I like to recommend colleagues to work against the channel stable by default, and consider switching to unstable once they feel more confident about mastering Nix. For releases I prefer to build software against the channel stable.

Every now and then a new challenge comes up when unstable introduces a change which is incompatible with the last stable channel. Since I am developing mainly against the unstable channel, I need a quick way to find out if my derivations would still work with the stable channel.

Building against a different channel

Using nix-shell and nix-build allows to change the import path. This allow to change where it will look for nixpkgs:

nix-shell -I nixpkgs=~/my-local-clone-of-nixpkgs

The import path can also include a URL, which allows us to grab the channel directly from Github without having to prepare a local clone first:

nix-build -I nixpkgs=https://github.com/NixOS/nixpkgs-channels/archive/nixos-16.09.tar.gz

As an alternative, the path can also be modified via the environment variable NIX_PATH. This is useful if a few runs of nix-build shall be performed:

export NIX_PATH=nixpkgs=https://github.com/NixOS/nixpkgs-channels/archive/nixos-16.09.tar.gz
nix-build

Comments

comments powered by Disqus