-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
The definition of self
is inconsistent in flakes
#7263
Comments
This issue has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/self-input-for-flakes-in-sub-directories/22774/4 |
I think I found the bug. It's a subtle operator precedence issue that causes the subdir path within the git repository to remain empty. Fix incoming soon. |
Whelp, that didn't do it. Needs more investigating. I thought it was this line:
and that operator precedence makes the key part interpreted as |
There may be inconsistencies in more places. The example I provided shows one case, but I'm sure I have had inconsistent behavior in other examples. To be sure we're both on the same page: |
Hmm, I was at first misunderstanding the situation. Here's what I understand now.
I'm actually struggling to find a good reference for what the string evaluation of a flake should be. In the current implementation, it comes from fetchTree on the git repository so that is why it gives the root of the git repository. To me it seems more consistent that stringification of |
This sure is a bug, because the manual says:
It also contradicts the idea that the flake should produce the same result regardless of where it is placed. |
When triaging the bugfix #7796 in the meeting today, we decided that more discussion is needed.
It seems that there's some disagreement about what constitutes a flake. It was mentioned that a subflake in a git repository is allowed to use I think a solution to this subflake-or-not conundrum is to require the user to be more explicit. After all a subflake isn't really a thing, but rather an interaction between two flakes, or, as we see in the current behavior, an interaction between a flake and a repository. What if we could turn subflake from an ontologically complicated thing into a property that's actually part of the flake? By being explicit about subflake-ness we set the right expectations. An attribute in flake.nix could achieve that. However, I don't think we need a new mechanism. Instead, we can reuse the existing dependency mechanism to represent subflake-ness. A dependency would be sufficient. {
input.parent.url = "..";
outputs = { self, parent, ... }:
# ...
;
} Without introducing any new concepts, we've made the relation between the subflake and its parent explicit, while also setting expectations about what this flake can and can't do. In this context, what should the It also simplifies the rules for hermeticity. That's all about the question: which files are an input to my evaluation? With this change it should be just: the directory of the flake + the files that make up the evaluation of the inputs; no need to make an exception for flakes that exist in a git repository. |
@roberth in my opinion, the actual problem here is that Flakes actually provide 2 different functionalities (compared to "old" nix files):
These are both great things, but unfortunately Flakes were designed from the ground up with those 2 features tied at the hip. And now this decision is biting us in the ***, because there is no way to get "Grouping" without "Reproducibility" (or vice-versa). A "subflake" should be a flake in terms of "Grouping", but not in terms of "Reproducibility". It doesn't need it's own reproducibility, because the reproducibility is already provided by the parent flake. The fact that Nix doesn't have any way to organize code without forcing the "Reproducibility" mechanics is (in my opinion) the root cause of a lot of issues with flakes (i.e. #3978, #5810, #5570, #5663, etc). |
Click for off topic part of reply to @RuRoI agree, but that's not the direction that was taken. "Grouping" is little more than a standard schema that could have been adopted without using flakes, but that's not what people did, because they wanted the "whole package", including the lock file and the CLI. There's plenty to be said about past decisions, or the architecture for that matter, but let's keep this discussion centered around "The definition of
Sounds like something we can do with # child/flake.nix
{
inputs.parent.url = "..";
inputs.foo.follows = "parent/foo";
inputs.bar.follows = "parent/bar";
outputs = { self, parent, foo, bar, ... }:
# ...
;
} The need (yes/no) for a lock file can be inferred from the inputs. Do you know of any other use cases or requirements that I didn't think of? I think this one is covered. |
Of course, sorry, can you link me to the RFCs you are talking about?
That's a bit verbose. I vaguely recall being able to do something like
Makes sense. |
|
Thank you so much to everyone! |
Describe the bug
When
flake.nix
is not located at the root of agit
repository I have found a few scenarios in which the definition ofself
is inconsistent. Sometimesself
refers to the entire repository, sometimesself
refers to the directory thatflake.nix
resides in (and therefore excludes the rest of the repository code).Steps To Reproduce
Why do i get different results? 🤔
Expected behavior
I would expect that
self
is consistently referring to the same path within my repository and includes all the same code, regardless of how I referenceself
.nix-env --version
outputNix 2.8.1
The text was updated successfully, but these errors were encountered: