NixOS / nix

Nix, the purely functional package manager
https://nixos.org/
GNU Lesser General Public License v2.1
12.87k stars 1.52k forks source link

Transitive inputs "not in registry" #5790

Open NobbZ opened 2 years ago

NobbZ commented 2 years ago

Describe the bug

I want to use follows on the input of an input.

Though I get an error, that this is not in the registry.

Steps To Reproduce

  1. Add an arbitrary nixpkgs input to a flake.nix.
  2. Add the following to your flake.nix at appropriate location:
    inputs.rnix-lsp.url = "github:nix-community/rnix-lsp/master";
    inputs.rnix-lsp.inputs.nixpkgs.follows = "nixpkgs";
    inputs.rnix-lsp.inputs.naersk.inputs.nixpkgs.follows = "nixpkgs";
  3. Update the flake.lock and observe error:
    error: cannot find flake 'flake:naersk' in the flake registries
    (use '--show-trace' to show detailed location information)

Expected behavior

The nixpkgs input of the naersk input of rnix-lsp is properly overwritten and follows "my" nixpkgs.

nix-env --version output

$ nix-env --version
nix-env (Nix) 2.6.0pre20211214_18e4851

Additional context

I tried this as a way to workaround #5609.

The same problem happens on 2.4 and 2.5:

$ nix shell github:nixos/nix/2.4 -c nix flake metadata
warning: Git tree '/home/…/Projects/system-config' is dirty
error: cannot find flake 'flake:naersk' in the flake registries
(use '--show-trace' to show detailed location information)
$ nix shell github:nixos/nix/2.5.0 -c nix flake metadata
warning: Git tree '/home/…/Projects/system-config' is dirty
error: cannot find flake 'flake:naersk' in the flake registries
(use '--show-trace' to show detailed location information)
thufschmitt commented 2 years ago

I can indeed reproduce this. More self-contained repro:

#!/usr/bin/env bash

set -euo pipefail
set -x

rm -rf A B C D
mkdir -p A B C D

cat <<EOF > A/flake.nix
{ outputs = _: {}; }
EOF
cat <<EOF > B/flake.nix
{
  inputs.A.url = "path:$PWD/A";
  outputs = _: {};
}
EOF
cat <<EOF > C/flake.nix
{
  inputs.B.url = "path:$PWD/B";
  outputs = _: {};
}
EOF
cat <<EOF > D/flake.nix
{
  inputs.C.url = "path:$PWD/C";
  inputs.A.url = "path:$PWD/A";
  inputs.C.inputs.B.inputs.A.follows = "A";
  outputs = _: {};
}
EOF

nix flake update ./D
nixos-discourse commented 2 years ago

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/how-should-i-setup-nested-flake-follows-to-use-top-level-nixpkgs/12670/4

jali-clarke commented 2 years ago

may have been fixed in https://github.com/NixOS/nix/pull/6036

tejing1 commented 2 years ago

Nope. Running thuf's script still fails:

$ nix shell github:NixOS/nix\#nix
$ ./tempscript
+ rm -rf A B C D
+ mkdir -p A B C D
+ cat
+ cat
+ cat
+ cat
+ nix flake update ./D
error: cannot find flake 'flake:B' in the flake registries
(use '--show-trace' to show detailed location information)
$ nix --version
nix (Nix) 2.7.0pre20220211_4d67ecb
tomberek commented 2 years ago

The desired change to the resulting lockfile for the relevant "follows" line,

inputs.C.inputs.B.inputs.A.follows = "A";

should cause this:

diff --git a/flake.lock b/flake.lock.post
index 7d50628..c51a7d1 100644
--- a/flake.lock
+++ b/flake.lock.post
@@ -26,7 +26,7 @@
     },
     "B": {
       "inputs": {
-        "A": "A_2"
+        "A": ["A"]
       },
       "locked": {
         "lastModified": 1654174365,

I've tried a few combination such as bringing B to the top and they trying to override it:

{
  inputs.B.follows = "C/B";
  inputs.B.inputs.A.follows = "A";
  outputs = _: {};
}

but then the relevant line to follow A has no effect.

What does work is to bring everything to the top level:

{
  inputs.A.follows = "C/B/A";
  inputs.B.follows = "C/B";
  outputs = _: {};
}

This can work in some cases if all you need is top level access to those inputs, but it does not allow you to change them, which is where people run into this problem.

deemp commented 2 years ago

Perhaps this issue can be reopened as #6621 was reverted in favor of #6530

azazel75 commented 1 year ago

Have you found any work-around for this?

deemp commented 1 year ago

@azazel75, yes, I now use flake-compat and import + custom logic for making inputs and outputs. I reduced flake.lock sizes significantly and made flakes very flexible, but now have to write a bit of boilerplate and can't nix flake archive to cache flake inputs transitively.

https://github.com/deemp/flakes/blob/main/flake.nix https://github.com/deemp/flakes/blob/main/flakes-tools/flake.nix