nmattia / niv

Easy dependency management for Nix projects
https://github.com/nmattia/niv
MIT License
1.61k stars 79 forks source link

Pinning nixos nixpkgs using niv in 22.05 fails? #354

Open busti opened 2 years ago

busti commented 2 years ago

This may not be the right place to post this but I do not know where else to take this.
I have asked on discourse before but it may be a bit too obscure to get much answers. https://discourse.nixos.org/t/rebuilding-system-using-niv-fails-in-nixos-22-05/19667/3

I used to pin my nixos nixpkgs commit when rebuilding using niv using a technique shown to me by someone at the local hackerspace about a year ago.

To do this I copied my existing systems configuration into my homedir and initialized niv in it.
I then added a file called sources-dir.nix to the nix/ folder generated by niv:

{ system ? builtins.currentSystem }:

let
  sources = import ./sources.nix {};
  pkgs = import sources.nixpkgs { inherit system; };
  lib = pkgs.lib;
in
  pkgs.runCommand "sources" {} (
    lib.concatStringsSep "\n" ([
      "mkdir $out"
    ]
      ++ lib.mapAttrsToList (name: source: "ln -s ${source.outPath} $out/${name}") sources
    )
  )

I then built the system config using the following shell script in the root dir of the config:

sources=$(nix-build nix/sources-dir.nix --no-out-link)
nixos-rebuild rebuild --target-host builduser@127.0.0.1 --use-remote-sudo -I "$sources" -I "nixos-config=$PWD/configuration.nix"

This used to work out well until the 22.05 update. Whenever I run the command now I get this very obscure error:

building Nix...
building the system configuration...
error: the string '22.05' is not allowed to refer to a store path (such as '/nix/store/0qma2xzkmp0x3j6gb0936fimvqsp297g-nixpkgs-src')

       at /nix/store/363n9qpp2aibismayc93ack9kjbs1da7-sources/nixpkgs/lib/strings.nix:562:26:

          561|   */
          562|   versionOlder = v1: v2: compareVersions v2 v1 == 1;
             |                          ^
          563|
(use '--show-trace' to show detailed location information)

Here is the same when running it with --show-trace: https://gist.github.com/busti/ca32db85512a374ae62f0a78ae921ef5

I have managed to reproduce the error in a standalone repo: https://github.com/busti/nixos-rebuild_niv-bug/blob/dev/deploy.sh

nmattia commented 2 years ago

That's an odd one! I'll try to find some time this week to reproduce, thanks for the report!

busti commented 2 years ago

It can be reproduced using the repo I linked at the bottom of the issue post.