-
-
Notifications
You must be signed in to change notification settings - Fork 14.4k
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
nixos: move default module location logic to eval-config.nix
#126769
Conversation
Prevously, authors of the flake have decided to expend the extra effort not to add I would like to know why this decision was made. Without knowing why, I can't decide whether this change is good, or whether it should be simplified by just adding it to |
a195fe2
to
2a9d35c
Compare
2a9d35c
to
59b0ee2
Compare
Quoting @jtojnar on Matrix:
|
The way I think of it, is that indeed This is different from the (currently unofficial; NixOS/nix#4744) That's my "ivory tower" interpretation. However, More thoughtsCategorization of nixpkgs dependencies: Undisputed: pkgs -> lib Apparently necessary: nixos -> pkgs flake -> lib Practical: pkgs -> nixos (pkgs.nixosTests, pkgs.nixosTest, pkgs.nixos, pkgs.dockerTools.nixosImage (potentially, poc: #148456) Dubious: lib -> nixos Disallowed: lib -> * (apparently) Even more thoughtsIf we have I'm not 100% opposed to a change like this, but I think the current solution is not optimal, because it reinforces the existence of two differenet So architecturally we're between a rock (nixpkgs-flake.lib) and a hard place (lib/flake.nix). Perhaps we should admit defeat and make a pragmatic choice by adding |
I'm fine with that. Should I create a |
I don't think we should put NixOS-specific stuff in |
Fine by me too, I'll give you the final say in this matter. I would like to extend the scope of this PR a bit and move most of the logic of
Let me know how this sounds, I'll push code shortly. |
59b0ee2
to
55ba2cc
Compare
It seems best to write a helper function
See #151082. |
Sounds good.
Ah that's even nicer. I'll wait until that is merged and rebase. |
55ba2cc
to
e028074
Compare
With #151082 merged, this is now ready for review. |
The manual fails to evaluate but this doesn't seem related to this PR (also fails on master) |
e028074
to
2fb9c7c
Compare
2fb9c7c
to
27d3f32
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sadly I can't decide the future of lib
on my own. The rest of the PR looks good and I think it'd be a good idea to merge the refactoring separately.
flake.nix
Outdated
} | ||
]; | ||
nixosSystem = args: | ||
import ./nixos/lib/eval-config.nix ({ lib = final; } // args // { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line isn't uncontroversial.
I'm having trouble weighing the utility of "more stuff available" against the subjective "good architecture". That's because I can't assume that we continue to have two different lib
s prominently available in one repo.
I like "good architecture" too, but I think the die has been cast the moment nixosSystem
was added to lib
.
With that consideration, the solution is to add it to nixpkgs/lib
, along with the experimental nixos
attr above, and turn the whole thing into a nicely consistent user experience where lib
is just lib
.
So unless we have a real reason to keep the split, I think this change is vaguely in the right direction, but not complete or does not go to the root of the problem.
Hence, my question is, do we envisage a practical reason to keep nixpkgs/lib
decoupled? This would be some feasible future action where the decoupling is actually necessary.
The only action I can think of is extracting lib
into a separate repo. Although I question the utility of this, as pkgs, lib and nixos benefit a lot from being monorepos, I can see a solution for this, which is to extract the non-coupled parts - most of lib. Only a small layer that adds nixos and perhaps pkgs attrs would have to be separated out before extracting lib into a separate repo. We can even do this preemptively by making pkgs and nixos import a wrapper in a separate file, similar to what the flake does, but not just for the flake. Equivalently, we can move the non-coupled attrs into a separate overlay in lib, so that those parts can be accessed independently.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regardless of how we decide to organise the lib, I don't see a reason not to pass the "most accurate lib
" to eval-config.nix
(in this case final
). If nixosSystem
was defined in nixpkgs/lib
as you suggest, surely it would have something like { lib = lib; } // args
, right? Otherwise we just force the user to add the lib
argument themselves as soon as they want to use their own lib
extensions in a module. I don't see how this is good architecture.
I think the decoupling debate is important and deserves its own issue/discussion/RFC if that's what it takes, but should be orthogonal to this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Phrased differently, eval-config.nix
has a safe default value for lib
, but nixosSystem
knows better what the default lib
should be since it's in the process of defining it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but
nixosSystem
knows better whatlib
should be
Whether that's actually better is a judgement that would depend on the outcome of the discussion.
Alternative explanations exists that make it not better: conflating flake.lib
and nixpkgs/lib
if they're considered separate concepts. They could be.
These requirements make my mind go in circles. It's awful and I need to stop.
I hope others can agree on what's actually good for users.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cole-h would you happen to have an opinion about this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just noticed
nixos = import ./nixos/lib { lib = final; };
and now I'm confused
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uh, yeah, I guess I remembered what you want when I wrote it and didn't think about it again since then.
Zooming out from the lib = final
bit, that nixos
attr is an experimental interface for testing and RFC 22-related refactoring. See #148456
7d4f9bf
to
69d0694
Compare
eval-config.nix
Ok, this PR is just the refactoring now. I'll move the |
What does this mean exactly? That any commit to Nixpkgs will trigger a rebuild of all VM tests? That would be very bad. |
It would, so they don't. Also they already would have because that code has been around for a while. These defs are only used in |
Updated the original post. As @roberth says, that's not part of this PR anymore. |
Opened #157056 about the |
Wraps a module with a default location for reporting errors.
69d0694
to
5ab62e1
Compare
@test installer.simple |
I think you mean |
This patch refactorsnixosSystem
in a few ways.Semantically, it changes two things:thelib
argument that is passed tonixos/lib/eval-config.nix
now defaults tofinal
: this makes extensions of the lib (includingnixosSystem
itself) available in the modules by default.system.nixos.versionSuffix
andsystem.nixos.revision
are now also set in the VM configs, not only in the top-level config.I have tested both of these things.Syntactically, it removes a bit of duplication.The only thing that is now being done by this PR is to move the
addModuleDeclarationFile
bit intoeval-config.nix
as it doesn't only make sense for flake configs.cc @edolstra @cole-h