nixpkgs/nixos/modules/installer/tools/nixos-build-vms/build-vms.nix
Maximilian Bosch 1659bca6b7
nixos-build-vms(8): $out/bin/nixos-run-vms should non-interactively start VMs
Not entirely sure when it got broken this time, but when creating a VM
network with `nixos-build-vms(8)`, there are should be the following scripts:

* `$out/bin/nixos-test-driver` which drops into an interactive shell to
  interactively perform test steps.
* `$out/bin/nixos-run-vms` which non-interactively starts the VMs from
  the network so that one can manually play around in the VM.

The latter also starts an interactive shell for a while now which means
that it does the exact same thing as `nixos-test-driver` which is not
its purpose.
2022-02-19 19:43:34 +01:00

32 lines
971 B
Nix

{ system ? builtins.currentSystem
, config ? {}
, networkExpr
}:
let
nodes = builtins.mapAttrs (vm: module: {
_file = "${networkExpr}@node-${vm}";
imports = [ module ];
}) (import networkExpr);
pkgs = import ../../../../.. { inherit system config; };
testing = import ../../../../lib/testing-python.nix {
inherit system pkgs;
};
interactiveDriver = (testing.makeTest { inherit nodes; testScript = "start_all(); join_all();"; }).driverInteractive;
in
pkgs.runCommand "nixos-build-vms" { nativeBuildInputs = [ pkgs.makeWrapper ]; } ''
mkdir -p $out/bin
ln -s ${interactiveDriver}/bin/nixos-test-driver $out/bin/nixos-test-driver
ln -s ${interactiveDriver}/bin/nixos-test-driver $out/bin/nixos-run-vms
wrapProgram $out/bin/nixos-test-driver \
--add-flags "--interactive"
wrapProgram $out/bin/nixos-run-vms \
--set testScript "${pkgs.writeText "start-all" "start_all(); join_all();"}" \
--add-flags "--no-interactive"
''