I am trying to write some integration tests for my machines in a flake.nix, however I seem to have run into an issue. The nixosTest function and underlying make-test-python.nix seem to expect a nixos module, but the flakes nixosConfigurations output wants a system that has already been evaluated by eval-config.nix.
I don’t think you can do it at this level. However you can have your nixos modules list in variable and pass it to both nixosSystem { modules = myModules; } and nixosTest { nodes.machine = {...}: { imports = myModules;};}
I tried following your advice, but I run into an infinite recursion which I don’t fully understand, which I believe is related to access to config._module.args.
Any suggestions for how to test a nixosConfiguration with the testing framework?
Ive been down this rabbit hole myself and recently found a solution that fits my needs similar to you. Below is a link to a function that builds a nixosTest. I hope it helps and let me know if you are confused as to what is going on below.
Instead, runNixOSTest should be used, which coincidentally makes working with nixosConfigurations easier. This tester specifically helps you with the pkgs argument, which it tries to derive automatically. And, if you have overlay applied in your flake, you can use node.pkgsReadOnly = false; to pass the overlayed pkgs definition into your test.
A full example here with flake.parts: flake: add nixos tests by jhvst · Pull Request #92 · ponkila/homestaking-infra · GitHub
Moreover, in the diffset above, it’s possible to test a nixosConfiguration by doing a let binding for a nixosSystem before opening the flake schema. Take a look at the rest of the PR flake.nix for an example ponkila-ephemeral-sigma. You can test the full host by defining the imports = ponkila-ephemeral-sigma.modules; inside of the testable machine.
Anecdotally, I’ve had luck creating test machines that mirror flake nixosConfigurations (without a let-binding / post-hoc) by simply setting: nodes.machine.imports = self.nixosConfigurations.${NAME}._module.args.modules;