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

Allow "self" in flake input paths #6535

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

alexshpilkin
Copy link
Member

@alexshpilkin alexshpilkin commented May 16, 2022

Fixes #4931 by making “self” in flake input paths the moral equivalent of “.” in filesystem paths. This takes the lazy approach and interprets any “self” components in the path at parse time.

cc @thufschmitt

@thufschmitt
Copy link
Member

I don’t have a very strong opinion on that topic, deferring to @edolstra since he might have one

@roberth
Copy link
Member

roberth commented May 26, 2022

No particularly strong opinion here either, but if we create a keyword (self), we should disallow it as an input name to avoid potential for ambiguity.

@alexshpilkin
Copy link
Member Author

@roberth The point was (I thought) that self is already effectively a keyword in that even if you declare an input by that name you’ll still get your own outputs instead of it. I agree that you shouldn’t be able to declare one at all, though.

Copy link
Member

@roberth roberth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a test case in tests/flakes/flakes.sh. You may want to rebase before you add it, to avoid conflicts in that file.

We'll also want to disallow the flake to define inputs.self = { ... }.

@alexshpilkin
Copy link
Member Author

@roberth OK, that's fair. Except tests/flakes/follow-paths.sh looks more logical to me? And tests/flakes/circular.sh as well just to mirror the docs.

As for disallowing a "self" input, I'm a bit torn because in principle I see no reason why, for example, writing inputs.self.inputs.foo.follows = "bar" shouldn't work as an synonym of inputs.foo.follows = "bar"—it's silly but not nonsense—but trying to make it work seems extremely annoying, e.g. we then need to define how inputs.self.inputs.foo, inputs.foo.inputs.self, and inputs.foo are merged recursively if more than one of them is present. No other attributes of a "self" input seem to make sense, so I think I'll sacrifice this bit of orthogonality and just ban any mention of a self input in the inputs part of a flake.

@thufschmitt thufschmitt added the idea approved The given proposal has been discussed and approved by the Nix team. An implementation is welcome. label Aug 4, 2023
@Ericson2314
Copy link
Member

Triaged in the Nix Team meeting this morning (n.b. I could not make it):

Main takeaway:

  • Idea Approved, but requires tests and docs

Discussion:

  • @thufschmitt would prefer something like ., but doesn't care too much about the concrete syntax
  • self isn't that bad

@nixos-discourse
Copy link

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

https://discourse.nixos.org/t/2023-08-04-nix-team-meeting-minutes-77/31487/1

@roberth
Copy link
Member

roberth commented Dec 24, 2023

  • @thufschmitt would prefer something like ., but doesn't care too much about the concrete syntax

Note that since then we've also accepted flake#.foo as a notation for absolute attribute paths (e.g. to avoid packages.<system>.foo), which is also inspired on unix path notation but with . instead of /.

Things still to do:

  • Add test case
  • Only operate on the root of the inputs tree. The inputs attribute, such as e.g. returned by getFlake, does not contain any self attributes either.
  • Consider . as syntax for self

I'll mark this as draft for the time being. Please undraft when it's ready for review.

@roberth roberth marked this pull request as draft December 24, 2023 18:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flakes idea approved The given proposal has been discussed and approved by the Nix team. An implementation is welcome.
Projects
Status: 🏁 Review
Development

Successfully merging this pull request may close these issues.

flake inputs cannot follow "self"
7 participants