-
-
Notifications
You must be signed in to change notification settings - Fork 16.7k
lib.evalModules: add graph attribute #403839
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
Conversation
b8928a3
to
2a5c8ff
Compare
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/obtaining-a-nixpkgs-module-system-configuration-modules-graph/63286/4 |
e2f87c8
to
724fccd
Compare
Should this new attribute be nested inside another attrset to reserve a place for more metrics in the future? Does the design otherwise make sense? To us it seems like this does not change a hot evaluation path. |
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/obtaining-a-nixpkgs-module-system-configuration-modules-graph/63286/5 |
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/prs-ready-for-review/3032/5547 |
Since our CI only performs a nixpkgs evaluation, for this PR it would be nice to also include a full nixos evaluation comparison. Before: nixos = import ./nixos/lib/eval-config.nix {
modules = [
{
fileSystems."/".device = "/dev/null";
boot.loader.systemd-boot.enable = true;
}
{
nixpkgs.system = "x86_64-linux";
}
];
}; Command: Note: CPU, and time is noisy, but i.e.
|
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.
Overall looking very nice. Some minor things should be fixed.
lib/modules.nix
Outdated
# | ||
# Filters a structure as emitted by collectStructuredModules by removing all disabled | ||
# Filters a `[ StructuredModule ]` by removing all disabled |
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.
The term StructuredModule
is never defined, would be nice to add a defining comment somewhere
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 kind of don't want to. Perhaps unnecesarry?
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 believe it's possible to significantly reduce the amount of memory retained during normal, non-graph
evaluation.
Unfortunately, I can't reproduce the increase in gc.heapSize
due to rounding (NixOS/nix#13336), so I'm unable to confirm as of now.
Represents all the modules that took part in the evaluation. | ||
It is a list of `ModuleGraph` where `ModuleGraph` has the following attributes: | ||
|
||
- `key`: `string` |
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.
file
seems useful for troubleshooting and should also be in the module attrset.
This is not implemented yet.
- `key`: `string` | |
- `key`: `string` for the purpose of module deduplication and `disabledModules` | |
- `file`: `string` for the purpose of error messages and warnings |
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.
We applied the docstring for key
and added a file
. Please review to make sure we did that right thing.
@@ -55,7 +59,7 @@ evalConfig() { | |||
local attr=$1 | |||
shift | |||
local script="import ./default.nix { modules = [ $* ];}" | |||
nix-instantiate --timeout 1 -E "$script" -A "$attr" --eval-only --show-trace --read-write-mode --json |
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'd prefer keeping the nix-instantiate
as is and provide the additional arguments that you need via checkExpression
That change has a subtle altering affect to checkConfigOutput
like adding --strict
and removing -A "$attr
.
That change to the testing framework is probably possible, but i wouldn't change it, if there is no motivation behind that.
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.
Fiy: Will need a bit more time to review the hard part of the changes 😄
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.
You're right about the --strict
. We've now moved --strict
out of local-nix-instantiate
and into `checkExpression.
Not sure what you mean with the -A "$attr"
.
It seems that now behavior of existing tests is preserved.
lib/modules.nix
Outdated
# This function takes an empty attrset as an argument. | ||
# It could theoretically be replaced with its body, | ||
# but such a binding is avoided to allow for earlier grabage collection. | ||
doCollect = | ||
{ }: | ||
collectModules class (specialArgs.modulesPath or "") (regularModules ++ [ internalModule ]) ( | ||
{ | ||
inherit | ||
lib | ||
options | ||
config | ||
specialArgs | ||
; | ||
_class = class; | ||
_prefix = prefix; | ||
} | ||
// specialArgs | ||
); |
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.
Here's the doCollect
. Is the comment correct?
dfa25a7
to
a9ea851
Compare
I used this recently and it was helpful to me 🪄 |
It would be great to see a practical use case for this, to illustrate a bit more what this does. |
It gave me a list of all files in which I was defining |
Co-authored-by: Shahar "Dawn" Or <[email protected]>
Co-authored-by: Ali Jamadi <[email protected]>
a9ea851
to
5186921
Compare
Spent some time rebasing 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.
Awesome!
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/nixpkgs-module-system-config-modules-graph/67722/1 |
For various module evaluation design/refactor analysis purposes one may want to obtain a data structure that represents all the modules that took part of a configuration evaluation.
This PR adds an attribute to the return value of
lib.evalModules
with such a data structure.Initially discussed here.
Things done
nix.conf
? (See Nix manual)sandbox = relaxed
sandbox = true
nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD"
. Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/
)Co-authored-by: @A-jay98
Add a 👍 reaction to pull requests you find important.