Using Nix 2.6 in NixOS 21.11

nixpkgs 21.11 provides

  • nix (2.3.16}
  • nix_2_3
  • nixStable (2.3.16)
  • nix_2_4
  • nixUnstable (2.5pre-yaddayadda)

nixpkgs unstable provides

  • nixVersions.nix_2_3
  • nixVersions.nix_2_4
  • nix (2.5.1)
  • nixVersions.nix_2_6

What is the most sensible way of using Nix 2.6 in NixOS 21.11?

1 Like

There’s nothing keeping you from using an unstable package on stable; you can get a reference to unstable via import <nixpkgs-unstable> (if your channel is named that), or niv/flakes if you live in the future.

Whether this is sensible to begin with is a different question. I think using future nix is unlikely to actually cause problems in this case, but you are throwing the stability guarantees of the stable branch out of the window; nix may have changed in a way that breaks nixpkgs, after all.

I think best practice would be to backport nix 2.6 upstream, going through test processes while you’re at it. I suspect that it’s just a case of nobody getting around to that backport yet.

I avoid channels and NIX_PATH like the plague. To my mind they defeat the whole point of Nix. (So it irks me that upgrading NixOS itself requires messing around with channels. (Unless I’ve missed something (hope I have!)))

I’ve been avoiding niv, pinning stuff by hand, waiting until I go full-flake. (I’m now trying to go full-flake.)

Yes, I’m trying to move to the future.

But I’m drawing a blank on how I would do this with a flake. Probably because all my flakes explorations have been about development environments for projects, and I haven’t got around to flakifying home-manager or configuration.nix.

1 Like

Ah, I live in the future, for those exact reasons, but assume people don’t if they ask questions so I don’t overload them with a bunch of flakes context when they’re learning :wink: Point out you’re using flakes when asking, that makes it easier to pin down what answer you’re looking for.

It’s much, much nicer with flakes. You would add a second input for unstable:

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-21.11";
    nixpkgs-unstable.url = "github:nixos/nixpkgs/nixos-unstable";

  outputs = { nixpkgs, nixpkgs-unstable, ... }: { }

As with flakes in general, this gives you pinning through flake.lock, and sorts out pulling in updates with nix flake update.

Then, the choice is yours. You need to take that nixpkgs-unstable, and
somehow prop it into the same place you define nix.package. You can
do that via an overlay, _module.args, or simply by setting
nix.package in flake.nix, so you still have access to that
nixpkgs-unstable variable.

There’s this recent question that has some discussion on the benefits of the various ways you can do that: Install agenix in "environment.systemPackages" on nixos with flakes

Note that nixpkgs exposes its packages through nixpkgs-unstable.legacyPackages, so if I’m not mistaken a direct reference to nix 2.6 would be nixpkgs-unstable.legacyPackages."x86_64".nix_2_6.

The system doesn’t need to be quoted, and the correct one would be x86_64-linux


I am at the stage of flakifying my development projects but have been avoiding touching my NixOS and home-manager configurations (for the time being). As this was a question about managing NixOS, I didn’t really want a flakey answer, at present.

But I’ll be getting there soon, so thanks for you flake example: it will be useful to me Any Time Now.

I guess that the pragmatic course of action for me, for now, is to forget about nix 2.6: 2.5 should be fine for most flake experimentation, shouldn’t it?

I think 2.4 and newer should be fine for almost all such experimentation :slight_smile: See the release notes: Release 2.4 (2021-11-01)

Releases since 2.4 have been quite small, you’re unlikely to miss out on much.

If you specifically care about the flakes feature, note that pkgs.nixFlakes exists, which will point to a stable release that supports flakes.

Unfortunately, in this particular case, not upgrading beyond the pre-2.5 available in 21.11 ended up wasting a lot of my time and thoroughly confusing me :slightly_frowning_face:

(Not blaming you in the slightest: shit happens, and I completely agreed with your conclusion. I just ended up falling into the gap left open by the ‘almost’ :slight_smile: )

1 Like