nixosTest with flake configurations

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’ve tried:

nixosTest { machine = self.nixosConfigurations.NixOS; }
nixosTest { machine = self.nixosConfigurations.NixOS.config; }
nixosTest { machine = self.nixosConfigurations.NixOS.config.system.build.toplevel; }
nixosTest { machine = self.nixosConfigurations.NixOS.config.system.build.vm; }

to no avail.

2 Likes

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;};}

2 Likes

Indeed, I already knew I had to generalize hosts. Dumb question but I’m glad it has an answer for anyone as stupid as me :+1:

If anyone is interested I created an issue here Use different versions of nixpkgs for the nodes than the one used for the nixos test · Issue #195600 · NixOS/nixpkgs · GitHub.