How do I install nix 2.4?

Hi! I was excited to see the release announcement for Nix 2.4, but I do not understand how to install it via configuration.nix. What is the one true way to do it?

Here is what I’ve gathered so far:

  • This comment says that Nix 2.4 is available in nixpkgs-unstable, but I don’t know how (or if I even should) expose nixpkgs-unstable to my configuration.nix file.
  • I can run Nix 2.4 via its flake, like so: nix run github:nixos/nix/2.4, but this is quite different from installing it systemwide.
  • I can use builtins.getFlake to install the Nix 2.4 flake via home-manager, but that doesn’t seem like a good idea–or rather, it does not solve my ultimate problem, which is that I would like a systemwide installation.
  • I cannot use builtins.getFlake to install that flake in my system configuration, because getFlake is supplied by experimental Nix (i.e. it’s a chicken-and-egg problem, I think).

This seems like a simple thing to accomplish, so perhaps I’ve just missed the documentation for how to do this. The announcement links to an installation help page that says to pipe curl through sh, but that’s a quickstart kind of thing that I’m obviously trying to avoid.

Thanks for any help on this!

roni

To install a specific version you can set the nix.package option in your configuration.nix.

To get version 2.4 from the unstable channel, you could do e.g.

{ config, pkgs, ... }:

{
  nix.package = 
    let pkgsUnstable = import (pkgs.fetchFromGitHub {
      owner = "nixos";
      repo = "nixpkgs";
      rev = "c935f5e0add2cf0ae650d072c8357533e21b0c35";
      sha256 = "1jwv20dxiaiwfqsa2jryib20d7ggvy5kfggna3cam6mafbpvad18";
    }) { system = config.nixpkgs.system; };
    in pkgsUnstable.nix_2_4;
}
2 Likes

Thank you!!

I’m still at a loss for what the “right way” is to install Nix 2.4. Are people supposed to know to do this?

I think this is simpler method, unless you want newer version that is in nixFlakes which is alias to nixUnstable.

{ pkgs, ... }: {
  nix = {
    package = pkgs.nixFlakes;
    extraOptions = ''
      experimental-features = nix-command flakes
    '';
   };
}

https://nixos.wiki/wiki/Flakes

This query

finds nixFlakes in https://github.com/NixOS/nixpkgs/blob/7e9b0dff974c89e070da1ad85713ff3c20b0ca97/pkgs/top-level/aliases.nix

And this query

Finds nixUnstable in https://github.com/NixOS/nixpkgs/blob/7e9b0dff974c89e070da1ad85713ff3c20b0ca97/pkgs/tools/package-management/nix/default.nix

  nixUnstable = lib.lowPrio (callPackage common rec {
    pname = "nix";
    version = "2.4${suffix}";
    suffix = "pre20210503_6d2553a";

    src = fetchFromGitHub {
      owner = "NixOS";
      repo = "nix";
      rev = "6d2553ae1496288554e871c530836428f405fd67";
      sha256 = "sha256-YeSeyOKhBAXHlkzo4mwYr8QIjIP9AgdpJ7YdhqOO2CA=";
    };

    inherit storeDir stateDir confDir boehmgc;

    patches = [
      (fetchpatch {
        url = "https://github.com/NixOS/nix/commit/8c7e043de2f673bc355d83f1e873baa93f30be62.patch";
        sha256 = "sha256-aTcUnZXheewnyCT7yQKnTqQDKS2uDoN9plMQgxJH8Ag=";
      })
    ];
  });
1 Like

Alternatively, you can update to NixOS 21.11 which will be officially released tomorrow and contains nix 2.4.

2 Likes

Great. Where can I find this information? Progress about preparing release? I know this site https://status.nixos.org/ but I am not sure if this is relevant.

November 26 is listed in schedule: Let's have a great 21.11 release cycle! - #3 by tomberek

I saw it, but wasn’t there some delay? Where can I find information about progress? What is left? Updated timelines?

Maybe this is helpful.

1 Like

Our current preference is to revert the default Nix version to 2.3 ONLY for the 21.11 release

Well, even if 21.11 ends up reverting Nix to Nix 2.3, it will be possible to use nix.package = pkgs.nix_2_4 on it.

1 Like

Which you can do already without waiting for 21.11