Conversation
nixos/tests/all-tests.nix
Outdated
There was a problem hiding this comment.
Is the plan to set this for all tests?
There was a problem hiding this comment.
I think that would be best, but I can't speak for everyone.
Most tests aren't in runTest style yet, and I don't know if everyone wants to switch their test to it.
Doing it for handleTest is too complicated for me. Too many callbacks and alternate ways to invoke stuff.
There was a problem hiding this comment.
We can default it for runTest for now, right?
There was a problem hiding this comment.
Some modules will set something in nixpkgs.config, or add an overlay. Wouldn't recommend, but that means that we can't apply this everywhere. I don't mind if "leaky" things like this are repeated. It's good to be reminded of it.
There was a problem hiding this comment.
I've added a node.pkgsReadOnly option to the test framework so that the optimization can be disabled if needed.
We could run it through the python-test-refactoring job on hydra.nixos.org to figure out which tests need an opt out. https://nixos.org/manual/nixos/unstable/index.html#sec-test-the-test-framework
Although that's not necessary for this PR.
c56f2b7 to
f879074
Compare
|
Looks good to me. It would be great to have it run through all the tests to find out which one needs an opt-out to make the majority of them faster. Although... doesn't have to happen in this PR. Maybe it would be even cleaner to do that in a follow-up PR. |
A nominal type.
mkIf is unnecessary when the condition is statically known - that is knowable before entering the module evaluation. By changing this to a precomputed module, we support changing the defined options to readOnly options.
This speeds up evaluation by a factor 2. Ballpark figures from my machine: ``` $ time nix-build nixos/release.nix -A tests.acme /nix/store/q4fxp55k64clcarsx8xc8f6s10szlfvz-vm-test-run-acme /nix/store/lnfqg051sxx05hclva84bcbnjfc71c8x-vm-test-run-acme real 1m28.142s user 1m7.474s sys 0m7.932s $ time nix-build nixos/release.nix -A tests.acme /nix/store/q4fxp55k64clcarsx8xc8f6s10szlfvz-vm-test-run-acme /nix/store/lnfqg051sxx05hclva84bcbnjfc71c8x-vm-test-run-acme real 0m38.235s user 0m33.814s sys 0m2.283s ```
By factoring out this logic, it's easier for other projects to make use of it this optimization too (and do it correctly).
By adding this option indirection, a test can declare all by itself that it needs a custom nixpkgs. This is a more convenient way of going about this when the caller of the test framework receives a `node.pkgs` unconditionally.
It's just not necessary.
f879074 to
e7df22d
Compare
|
I've removed the change that disabled aliases on hydra, because a few tests were not compatible with that. Other than that, I've added this to |
Most tests are not affected by this because they use the `handleTest` function instead.
|
btw, are there plans of converting everything to runTest automatically? |
e7df22d to
16e3647
Compare
|
The tests are too messy to automate it. (maybe there are some patterns; not sure) Previously I haven't suggested migrating "other people's" tests because there's a little bit of friction involved, but I think now with the performance improvement, the case is strong enough to start migrating them. If you or anyone feels like converting some of the non-matrix tests, feel free to convert them. To reduce the friction, add something like this. EDIT: maybe not without making the case to the community in an RFC. |
|
Does this optimization also works by default on out-of-tree tests that use |
Yeah, just set That reminds me, #225313 should use it. |
|
@roberth I think this is a breaking change technically. While I am fine with it, I feel like it should have some:
message in the release notes for 23.05 if that's okay with you :). (not this PR per se, but the PRs transforming the tests to use this) Also, I know that manual mention it's not recommended to do this anymore, but we didn't really any warning / deprecation notice, so I think it is helpful to have extra redundancy on that. |
|
Individual test are not worth reporting on, but we could announce that this is happening.
They're not really a public interface, in the sense that nixpkgs is a library of packages and modules and whatnot, but it is a frequently used user interface nonetheless. Speaking of policy, this should probably be a formal community decision before we migrate other people's tests. Do you think it should be an RFC? |
Individual no, general notice yes. (with limited examples) :)
That's true, but we are big enough to make it nice for people working with internal APIs to be noticed about changes I believe. People who does this work are the most likely to read the changelog properly, so it's extra appreciated I believe.
I don't believe it should be a RFC, test ownership is already inferior to module ownership which is itself inferior to package ownership. But we should definitely ping maintainers on each of their tests when they are listed as maintainers, but I would not block any decision on them. |
|
Fair enough. If it's individual / collaborative choice and not policy, it's still worth noting. |
Calling `eval-config.nix` without a `system` from a Nix flake fails with `error: attribute 'currentSystem' missing` since #230523. Setting `system = null` removes the use of `currentSystem` and instead uses the value from the `nixpkgs` module.
Description of changes
Speed up
nixosTestsevaluation by reusing nixpkgs.nixpkgs.*options read-only (exceptnixpkgs.pkgswhich is set-once)all-tests.nix. Use the preceding module to make sure we don't test the wrong thing.As for the performance improvement in acme: about 90 seconds down to 40 seconds
Heap stats
Vanilla: 5.2G final heap, 9.5G total allocations
Read only 2.3G final heap, 5.3G total allocations
Things done
sandbox = trueset innix.conf? (See Nix manual)nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/)