Building older versions of libraries

I’ve recently been exploring using nix shell, rather than docker, to create a development environment. One issue I quickly ran into was being able to load up older versions of libraries. This is often necessary if you need to support old code.

For example, suppose I want to use opencv 4.5.4, instead of the current version, opencv 4.7.0. In theory, I can change the version of opencv that gets built by using overrideAttrs. However, when I change the version and source attributes (see example below), I get an error because the patches aren’t compatible with this older version of opencv. I don’t know a way to change the patches directly, since they’re inside mkDerivation and thus inaccessible with overrideAttrs (I think?).

Is there an established way of doing this? Should I load in an older version of the opencv nix file?

Thanks.

An example of what I’m doing:

opencv = (pkgs.opencv.override (previous: {

enablePython = true;})).overrideAttrs (oldAttrs: {
  nativeBuildInputs = oldAttrs.nativeBuildInputs ++ [pkgs.ant pkgs.jdk];
  
  version = "4.5.4";

  src = pkgs.fetchFromGitHub {
    owner = "opencv";
    repo = "opencv";
    rev = "4.5.4";
    sha256 = "sha256-eIESkc/yYiZZ5iY4t/rAPd+jfjuMYR3srCBC4fO3g70=";
  };

  contribSrc = pkgs.fetchFromGitHub {
    owner = "opencv";
    repo = "opencv_contrib";
    rev = "4.5.4";
    sha256 = "sha256-RkCIGukZ8KJkmVZQAZTWdVcVKD2I3NcfGShcqzKhQD0=";
  };

  testDataSrc = pkgs.fetchFromGitHub {
    owner = "opencv";
    repo = "opencv_extra";
    rev = "4.5.4";
    sha256 = "sha256-Ak0sTr4s7tPqRLcuIe+5NVGMz8SwTifYU7vBu1uH4rk=";
  };

})

1 Like

You could try loading an older version of the file, or copying the current file and modifying it to your needs. You could also add a nixpkgs input at a revision that contains the package you want, that way you know it will still be compatible with its dependencies.

Thanks. Yeah, using an older version of nixpkgs seems like the most straightforward approach. That way you know all of your packages are consistent. Of course it’s limiting in that you can’t mix and match different versions of different packages, so in some cases I guess you can do more complicated things like copy the text over and make edits as needed.

That all makes sense, I just wasn’t sure if there was a particular established way to do things. Thanks.

You can mix and match a bit by including multiple nixpkgs versions and installing different packages from different ones. There are a few examples of people installing packages from stable and unstable at the same time. If you need a tool to find the right revision for your package, this was posted today: https://www.nixhub.io/

1 Like

Yeah, I was thinking about different nixpkgs versions also. I guess where that could get messy is when each package pulls in dependencies from its own version of nixpkgs, so for example you could have two java projects using different versions of the jdk.

nixhub looks cool, thanks for the heads up.

1 Like

I’ve got a very old flake where I want to build blender from (nixpkgs/pkgs/applications/misc/blender/default.nix at e49189078fa5194d0bef55d2432c259a0cabc172 · NixOS/nixpkgs · GitHub) this is 4 years old and back then flakes still had the edition field. So when I tried to use this old version as flake input, flakes complained about that extra field. Is there another way to choose such an old version?

Please do not bump old solved topics when you only have slightly related question – open a new topic.

In fact, I see you did that in How to build old blender 2.83.

Asking question in multiple places without cross-linking is frowned upon as well, since it can cause people to spend time on writing a reply when it has already been answered elsewhere.