-
-
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
flake/lib.nixosSystem: add _file
-keys for error-location if needed
#129924
Conversation
Did you try |
Good point! Gonna try it out, this should simplify this by a lot! |
@roberth thanks a lot, very good point! Updated the PR accordingly! :) |
Haven't tested it myself, but I think this should be fine. |
I've added a tiny refactor to fix the formatting and add an inline doc. |
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.
Can be merged afaic.
When inlining a module with a problematic declaration, you usually get get a not-so helpful error like this: $ cat flake.nix { description = "A very basic flake"; inputs.nixpkgs.url = path:../.; outputs = { self, nixpkgs }: { nixosConfigurations.foo = nixpkgs.lib.nixosSystem { system = "x86_64-linux"; modules = [ ({ lib, ... }: { services.wrong = 2; }) { services.nginx.enable = true; } ]; }; }; } $ nixos-rebuild build --flake .#foo -L error: The option `services.wrong' does not exist. Definition values: - In `<unknown-file>': 2 While it's certainly possible to guess where this comes from, this is IMHO fairly confusing for beginners (and kinda reminds me of the infamous "infinite recursion at undefined position"-error). The module-system determines the position of a declaration using the `_file`-key: this is either `toString path` if `path` is e.g. a value from `imports = [ ./foo.nix ]` or the file used as `NIXOS_CONFIG` in `<nixpkgs/nixos>`. However such a mechanism doesn't exist (yet) for inlined flake modules, so I tried to implement this in a fairly basic way: * For non-path declarations, the position of `modules` inside the `flake.nix` which declares these modules is determined by doing `unsafeGetAttrPos` on the `modules`-argument of `lib.nixosSystem`. So the `flake.nix` from above would now raise the following error-message: $ nixos-rebuild build --flake .#foo -L error: The option `services.wrong' does not exist. Definition values: - In `/nix/store/4vi3nhqjyma73ygs4f93q38qjkhkaxw8-source/flake.nix': 2 Co-authored-by: Cole Helbling <[email protected]> Co-authored-by: Silvan Mosberger <[email protected]> Co-authored-by: Robert Hensing <[email protected]>
Squashed this together to have a nicer commit-message and re-checked this. Would merge in a minute as several folks are fine with this in the current state :) |
Is there a reason for having this in |
I don't recall the details anymore, but I think this was a flake-specific issue. Can you reproduce the overall problem with a non-flake NixOS configuration? If that's the case, please share your code with me and if needed, we should move the change to |
The reason I'm asking is that I'm working on a PR to move much of the logic of I didn't run into the overall problem, but it's easy to imagine a situation where it would arise: basically any time Now I'm actually wondering if this could be moved directly to |
Motivation for this change
When inlining a module with a problematic declaration, you usually get
get a not-so helpful error like this:
While it's certainly possible to guess where this comes from, this is
IMHO fairly confusing for beginners (and kinda reminds me of the
infamous "infinite recursion at undefined position"-error).
The module-system determines the position of a declaration using the
_file
-key: this is eithertoString path
ifpath
is e.g. a valuefrom
imports = [ ./foo.nix ]
or the file used asNIXOS_CONFIG
in<nixpkgs/nixos>
.However such a mechanism doesn't exist (yet) for inlined flake modules,
so I tried to implement this in a fairly basic way:
modules = [ ./path.nix ]
inlib.nixosSystem
doesn't require anyadditional steps,
./path.nix
is used as position for alldeclarations inside
./path.nix
.For non-path declarations, the position of
modules
inside theflake.nix
which declares these modules is determined by doingunsafeGetAttrPos
on themodules
-argument oflib.nixosSystem
.So the
flake.nix
from above would now raise the followingerror-message:
Things done
sandbox
innix.conf
on non-NixOS linux)nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
./result/bin/
)