[Nix-dev] How to install specific version of a package?

Daniel Hlynskyi abcz2.uprola at gmail.com
Fri Aug 12 23:06:59 CEST 2016

Nix allows you to have multiple versions of one package, but each version
can require it's specific build recipe.

nixpkgs - is a place for latest versions of packages, and, pragmatically,
for most used non-latest versions. The place for all packages of all
versions is currently vacant.

Given this, I can think of several ways to get non-latest version of
package in Nix:

- already mentioned install from binary cache
- install from specific checkout of nixpkgs (
http://edwtjo.me/posts/2016-04-24-installing-older-pkgs-in-nixos/ and
- install from overriden expression. This is the most unstable way, because
many packages do require changes to recipe. But for certain simple kinds of
packages it can be automated.

Given the following oldversion.nix:

{ pkg, version }:
  pkgs = import <nixpkgs> {};
  inherit (builtins) trace;
  inherit (pkgs) lib;
  traceSeq = x: y: trace (builtins.deepSeq x x) y;
  oldversion = package: version:
    let getVersion = name: lib.last (lib.splitString "-" name);
    in package.overrideDerivation (super: {
      name = super.name + "-oldversion-" + version;
      inherit version;
      src =
        let upstreamUrls = super.src.urls;
            patchedUrls = map (x: builtins.replaceStrings [(getVersion
super.name)] [version] x) upstreamUrls;
        in pkgs.fetchurl { urls = patchedUrls; sha256 = null; sha512 =
null; md5 = null; sha1 = null; };
in oldversion pkg version

you can install different versions of same package with the following
monstruous command:

danbst at iron ~/oldversion$
$ nix-env -f oldversion.nix --arg pkg "with import <nixpkgs>{}; siege"
--argstr version "3.0.3" --install
replacing old ‘siege-3.0.8-oldversion-3.0.3’
installing ‘siege-3.0.8-oldversion-3.0.3’

danbst at iron ~/oldversion$
$ nix-env -f oldversion.nix --arg pkg "with import <nixpkgs>{}; siege"
--argstr version "4.0.2" --install
replacing old ‘siege-3.0.8-oldversion-3.0.3’
installing ‘siege-3.0.8-oldversion-4.0.2’

2016-08-12 20:06 GMT+00:00 Nick Sabalausky <bus_nixos_list at semitwist.com>:

> On 08/12/2016 02:58 AM, Roger Qiu wrote:
>> Nix is based on content addressing. To install a specific version of a
>> package, just pick a version, fix the content address, and install it!
>> [...]
>> or if a previous (or newer) revision of nixpkgs had the
>> package, then you load that package set and point to a package there to
>> install it.
> Can you point me to documentation for that? I only know of installing via
> "environment.systemPackages", enabling a service, or "nix-env -i ...".
> I did just now try following this:
> https://nixos.org/nixpkgs/manual/#sec-modify-via-packageOverrides
> And created a ~/.nixpkgs/config.nix containing (just to try things out)
> this:
> {
>     packageOverrides = pkgs: rec {
>         firefox = pkgs.firefox.override {
>             common.version = "33.0";
>         };
>     };
> }
> But then I just get:
> $ nix-env -i firefox
> error: attribute ‘override’ missing, at /home/nick/.nixpkgs/config.nix
> :3:13
> _______________________________________________
> nix-dev mailing list
> nix-dev at lists.science.uu.nl
> http://lists.science.uu.nl/mailman/listinfo/nix-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.science.uu.nl/pipermail/nix-dev/attachments/20160812/8649ba6f/attachment.html>

More information about the nix-dev mailing list