How to install a one-off package in NixOS

nixnixosnixpkgs

I've got a NixOS box that I keep on the nixos-16.03 channel. I want the machine to stay in a mostly-stable state, and so I am wanting to avoid switching to the nixos-unstable channel.

However, I need to install a newer version of a package than is available in that channel (nodejs-6_x in this instance). In the manual, there is a section that describes One-Click Installation, which seemed at first like exactly what I needed. However, the Hydra server at http://hydra.nixos.org doesn't appear to be serving up any .nixpkg files which are used by the nix-install-package tool described in that section.

The wiki also documents a process by which one can customize a package (the page is called Modifying Packages), which I suppose could be used for my purposes, although it seems like I'd be fighting the tool rather than using it.

I asked about this in IRC as well (thanks to M-Ralith for patiently answering my ignorant questions!), but I didn't quite understand how to apply it. The advice was to "override src and version in your nixpkgs config", which sounds like I could write a nix expression in .nixpkgs/configuration.nix and override those properties for the package in my subscribed channel (nixos-16.03). When I asked about packages that don't exist in the channel, the advice was "to specify the entire package rather than just overriding src and version", which I take to mean that I would need to duplicate the entire nix expression for the package I'm interested in. It seems to me that this would have the effect of preventing nix-env from ever updating that package should the stable channel catch up or overtake the version that I use to override.

For packages that exist in another channel that I want to install, but stay on my current channel, is there a better way? It almost feels like I should be able to do something like nix-build <url> | nix-env -i. What would be ideal is to install this one off, but not have configuration that might prevent it from being upgraded later on if my current channel were to catch up.

Best Answer

you can use nix-env tool

% nix-env -f https://github.com/NixOS/nixpkgs-channels/archive/nixos-unstable.tar.gz -iA tig

or use nix-build tool

% nix-build -I nixpkgs=https://github.com/NixOS/nixpkgs-channels/archive/nixos-unstable.tar.gz -A tig

how that helps!