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.

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

1 Like

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: