Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

flake inputs cannot follow "self" #4931

Closed
blaggacao opened this issue Jun 21, 2021 · 11 comments · May be fixed by #6535
Closed

flake inputs cannot follow "self" #4931

blaggacao opened this issue Jun 21, 2021 · 11 comments · May be fixed by #6535

Comments

@blaggacao
Copy link
Contributor

───────┬────────────────────────────────────────────────────────────────────────────────────────────────────────────────
       │ File: flake.nix
───────┼────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   1   │ {
   2 ~ │   description = "Test Flake For Follows";
   3 ~ │   inputs =
   4 ~ │     {
   5 ~ │       nixos-generators.url = "github:nix-community/nixos-generators";
   6 ~ │       nixos-generators.inputs.nixpkgs.follows = "self";
   7   │     };
   89 ~ │   outputs = { ... }: {};
  10   │ }
───────┴────────────────────────────────────────────────────────────────────────────────────────────────────────────────
nix flake lock --update-input nixos-generators
warning: Git tree '/tmp/flake-test' is dirty
error: input 'nixos-generators/nixpkgs' follows a non-existent input 'self'
(use '--show-trace' to show detailed location information)

Imagine I wanted to ship a remote flake that depends on my local flake as part of my local flake ("engulfing").

With this bug present, I cant do that in flake interface land.

It is a legal operation.

@blaggacao blaggacao added the bug label Jun 21, 2021
@blaggacao blaggacao changed the title flake inputs cannot floow "self" flake inputs cannot follow "self" Jun 21, 2021
@roberth
Copy link
Member

roberth commented Jun 22, 2021

This is a valid improvement. I see two use cases:

Plugin

This situation occurs when flake A has a plugin interface and flake B defines a plugin. The following dependencies arise:

A.lib <- B.plugin <- A.wrappedExe

Here A must be able to specify that B.inputs.A equals A aka follows self.

Megarepo

Another use case is "megarepos": repositories that define multiple related packages. Here the repo boundary is usually the same as the (human) organizational boundary. Sometimes a "high-level" package in the megarepo will depend on an external package that in turn depends on a "low-level" package that is in the same megarepo.

@RealityAnomaly
Copy link
Member

This will require a little more thought I think, because this is technically a circular reference.

When a flake's input is being locked, it requires a reference to said input in the store; and that must be a locked reference. So you can't actually pass the current flake self in because it hasn't been evaluated yet, and to evaluate it the inputs must be locked which now depend on the current flake... you can see where this is going 😄

@blaggacao

This comment has been minimized.

@roberth
Copy link
Member

roberth commented Jun 23, 2021

@citadelcore

When a flake's input is being locked, it requires a reference to said input in the store; and that must be a locked reference.

This isn't the case. If you look at call-flake.nix or flake-compat, you'll see that Nix takes the lockfile and connects all the inputs with mapAttrs and looking up the nodes lazily. It does not need to access dependency lockfiles during evaluation, because the transitive dependencies are also in the lockfile.

So all recursion happens in the Nix language, which is lazy, so we have no problem tying the recursive knot.

@RealityAnomaly
Copy link
Member

Hmm, you make a good point. I'll investigate this a bit further.

@stale
Copy link

stale bot commented Jan 3, 2022

I marked this as stale due to inactivity. → More info

@stale stale bot added the stale label Jan 3, 2022
@alexshpilkin
Copy link
Member

Not stale.

@stale stale bot removed the stale label May 11, 2022
@thufschmitt
Copy link
Member

This is actually possible (there’s even an example in the manual, although it’s not entirely obvious) using an empty string ( or /) in the follows. So nixos-generators.inputs.nixpkgs.follows = ""; should work in the original example

@alexshpilkin
Copy link
Member

@thufschmitt Empty path means this flake? Whoa. That is... not how paths usually work, but I guess there is no real reason to reject that, either. What about keeping that interpretation but also making “self” components no-ops, like “.” components in filesystem paths?

@edolstra
Copy link
Member

edolstra commented May 16, 2022

Given that follows takes a slash-separated path of flake input names, I think / is the most natural way to refer to the root, i.e.

nixos-generators.inputs.nixpkgs.follows = "/";

The empty string works sort of by accident, so maybe we should disallow it.

Note however that following the root flake currently does not work in pure mode since it's not locked in the lock file. So you'll get an error like:

error: in pure evaluation mode, 'fetchTarball' requires a 'sha256' argument

@thufschmitt
Copy link
Member

Given that follows takes a slash-separated path of flake input names, I think / is the most natural way to refer to the root

Just my 2cts as to the design of the bikeshed: / is a bit surprising in that context given that it evokes an absolute path while all the flakerefs are (usually, this isn’t mandatory) written as what would syntactically be a relative path. So maybe . would be a more intuitive choice for that :)

(But I don’t have a strong opinion on that either, as long as it’s clearly documented)

@stale stale bot added the stale label Nov 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants