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
Add pkgs.nixosTest #47684
Add pkgs.nixosTest #47684
Conversation
cc @aszlig |
|
2aa1e86
to
bba4655
Compare
@GrahamcOfBorg build tests.nixos-functions.nixosTest-test tests.nixos-functions.nixos-test |
Success on x86_64-linux (full log) Attempted: tests.nixos-functions.nixosTest-test, tests.nixos-functions.nixos-test Partial log (click to expand)
|
Success on aarch64-linux (full log) Attempted: tests.nixos-functions.nixosTest-test, tests.nixos-functions.nixos-test Partial log (click to expand)
|
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’m a bit out of my league when it comes to full evaluation of test frameworks and nixos configs, but I highlighted parts where I see potential problems.
You should get one or two reviewers that are more familiar with this parts of nixpkgs, @edolstra certainly is.
else test; | ||
calledTest = if pkgs.lib.isFunction loadedTest | ||
then callPackage loadedTest {} | ||
else loadedTest; |
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.
Are these really necessary? The user can add the import
and callPackage
if needed. Plus, if I see this correctly, the global callPackage
from all-packages.nix
is used here, which is scoped to a specific version of pkgs
.
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 is desirable to be compatible with testing.nix
/makeTest
that people are used to.
Using a specific version ('the version') of pkgs
is the point of this function. It's called as pkgs.nixosTest
. If you want to use another pkgs
, you call otherPkgs.nixosTest
or do the deep import of testing.nix
or similar that people have been doing.
then callPackage loadedTest {} | ||
else loadedTest; | ||
in | ||
nixosTesting.makeTest calledTest; |
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.
Hm, the function only accepts one test. I don’t know how much sharing is done internally, this might mean a hefty evaluation for each test if you want to run multiple tests. cc @aszlig maybe.
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 reuses an applied Nixpkgs (pkgs
), so that will be efficient. Evaluation nixos configurations is inevitable because each machine in a nixos test is unique.
Thanks Profpatsch, I believe I have addressed your review. Would you mind having a look at my comments?
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.
While I really appreciate making a few things a bit more overridable, applying nixpkgs.pkgs
to all machines really is a blocker here, because it makes tests behave differently than by using <nixpkgs/nixos/tests/make-test.nix>
or even <nixpkgs/nixoslib/testing.nix>
.
inherit pkgs; | ||
extraConfigurations = [( | ||
{ lib, ... }: { | ||
config.nixpkgs.pkgs = lib.mkDefault pkgs; |
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 is a bit tricky here, because the default in the nixpkgs
NixOS module is:
nixpkgs/nixos/modules/misc/nixpkgs.nix
Lines 68 to 70 in 591ba73
default = import ../../.. { | |
inherit (cfg) config overlays localSystem crossSystem; | |
}; |
Setting this to pkgs
here has the effect that overlays and config now no longer work and test machines will be built with whatever overlays were set outside of their machine definition.
I'd say this not only leads to surprising behavior when overlays are no longer working but also could lead to tests failing because you have some pretty weird override somewhere in your ~/.config/nixpkgs/overlays.nix
when going the impure import route (which is the default right now).
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.
Thanks aszlig for your review. You have made it very clear that I needed to improve the documentation wrt handling of pkgs. The goal is not to replace anything in NixOS but to add a new way to invoke NixOS tests that is both more accessible and more efficient.
Documenting this limitation (which is still the case, not only for What would be the actual use cases where importing |
The logic in this PR is entirely deterministic. If someone wants to have a fresh Nixpkgs, they should just import it. Having
It makes sense for a project to use Nixpkgs as a central part of their Nix expressions. Having functions like
These don't work if you only have a |
Another very important reason to have this function is to make it easy for beginners to get started with writing NixOS tests for their own projects. It's really a 'killer feature' of the Nix ecosystem so it should be easy to get started with. This function is easy to get started with and it scales well into 'serious projects' and setups with a company overlay, for example. |
The good news is that it worked as expected.
886e72f
to
5a8bddf
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.
Looks good! I still think the extraConfigurations thing is awkward but it’s okay for now
These kinds of attributes should not be included in
It may be undocumented but so is an attribute in BTW, the flake mechanism should provide a better way to handle this by giving tools like |
Same applies to I hope flakes aren't too heavy a solution. How are those coming along? |
Yes, |
Shouldn't there be a way to tell nix-env to exclude something to be installable? We have a way to do that for Hydra. |
This also breaks nixops:
|
nixops breakage documented here: #50419 |
No, this doesn't break NixOps. #50233 broke NixOps. Everything in Nixpkgs is a 'public interface'. |
yes unfortunately. |
It's ~4 years later and this can be discussed now.
|
Motivation for this change
This makes writing NixOS tests easier and faster for project that use Nixpkgs, because it reuses the applied
pkgs
.(The fast aspect was available since
config.nixpkgs.pkgs
but its use is unlikely to have spread much)This now also includes a test for
pkgs.nixos
.Things done
sandbox
innix.conf
on non-NixOS)nix-shell -p nox --run "nox-review wip"
./result/bin/
)nix path-info -S
before and after)