DeterminateSystems / zero-to-nix

Zero to Nix is your guide to learning Nix and flakes. Created by Determinate Systems.

Home Page:https://zero-to-nix.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How would one make an environment with specific versions of packages tied together?

frencojobs opened this issue · comments

commented

This maybe doesn't concern the repo, but, I'm trying out the tutorial (on how to use flake.nix to configure a development environment) and I'm trying to configure an environment for a project. But I need to use specific versions for certain packages for the project. Otherwise it doesn't work due to the nature of the concerning project. Let's say, as an example, I need packages A, B and C. I need v1 of A, v2 of B and v3 of C. How can one achieve such configuration?

I thought that would be a common/popular use-case/requirement for a lot of projects so I thought I could just maybe specify the versions like { derivation = pkgs.git; version = "1.2.3" } but it seems there's no such API.

The only way I could manage was to manually find the git commit number at which the package I want is at the version I want, and then to add it as a separate input. Like,

inputs = {
  nixpkgs-for-A = "github:NixOS/nixpkgs/v1commit...";
  nixpkgs-for-B = "github:NixOS/nixpkgs/v2commit...";
  nixpkgs-for-C = "github:NixOS/nixpkgs/v3commit...";
}

But I have more than 3 packages, and this approach easily becomes unmaintainable. It can't be the optimal solution. Any advice?

Unfortunately, there isn't really a straightforward way to do this in Nix. The issue is that when you use a specific revision of Nixpkgs as your input, all the derivations are tied to that revision, including the package-specific version info. The way you've tried does work because it involves taking snapshots of Nixpkgs at the "correct" revision for that package. Another approach would be to use a single version of Nixpkgs and use overrides to get specific versions of packages.

@frencojobs You may find this search engine helpful: https://lazamar.co.uk/nix-versions/