Rebuilding system using niv fails in nixos 22.05

It seems to work when I prepend nixpkgs=$HOME/Projects/nixpkgs to NIX_PATH, even with the same commit as the one pinned by niv.

Looking at it in Nix REPL, the output builtins.readFile appears to inherit string context from the path:

nix-repl> :t "${import ./nix/sources-dir.nix {}}"
a string with context

nix-repl> :t (import ./nix/sources.nix {}).nixpkgs.outPath
a string with context

nix-repl> :t builtins.readFile "${import ./nix/sources-dir.nix {}}/nixpkgs/.version"
a string with context

nix-repl> :t builtins.readFile "/home/jtojnar/Projects/nixpkgs/.version"
a string

So I guess you can apply the following workaround.

--- a/nix/sources-dir.nix
+++ b/nix/sources-dir.nix
@@ -9,6 +9,6 @@ in
     lib.concatStringsSep "\n" ([
       "mkdir $out"
     ]
-      ++ lib.mapAttrsToList (name: source: "ln -s ${source.outPath} $out/${name}") sources
+      ++ lib.mapAttrsToList (name: source: "ln -s ${builtins.unsafeDiscardStringContext source.outPath} $out/${name}") sources
     )
   )
\ No newline at end of file
1 Like