summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMitchell Hashimoto <m@mitchellh.com>2025-03-17 09:08:47 -0700
committerMitchell Hashimoto <m@mitchellh.com>2025-03-18 09:28:45 -0700
commitf9b7ba36d9ca3dd38449989aeb115c091b5cbc0e (patch)
tree91cb5ebfe0a216e7b01fe9bb4caf68e8f606b710
parent0f2f0ab69f65941ab85c0563abdc5583d1983527 (diff)
wip: testsvm-tests
Not meant for merging.
-rw-r--r--flake.nix39
-rw-r--r--nix/tests/basic.nix26
-rw-r--r--nix/tests/default.nix14
-rw-r--r--nix/tests/gnome.nix56
-rw-r--r--nix/tests/i3.nix59
5 files changed, 185 insertions, 9 deletions
diff --git a/flake.nix b/flake.nix
index fc8daf201..9772fa07b 100644
--- a/flake.nix
+++ b/flake.nix
@@ -47,6 +47,11 @@
system: let
pkgs-stable = nixpkgs-stable.legacyPackages.${system};
pkgs-unstable = nixpkgs-unstable.legacyPackages.${system};
+
+ # These are all of our VM tests.
+ tests = import ./nix/tests/default.nix {
+ nixpkgs = pkgs-unstable;
+ };
in {
devShell.${system} = pkgs-stable.callPackage ./nix/devShell.nix {
zig = zig.packages.${system}."0.14.0";
@@ -72,6 +77,8 @@
formatter.${system} = pkgs-stable.alejandra;
+ checks.${system} = tests;
+
apps.${system} = let
runVM = (
module: let
@@ -91,15 +98,29 @@
program = "${program}";
}
);
- in {
- wayland-cinnamon = runVM ./nix/vm/wayland-cinnamon.nix;
- wayland-gnome = runVM ./nix/vm/wayland-gnome.nix;
- wayland-plasma6 = runVM ./nix/vm/wayland-plasma6.nix;
- x11-cinnamon = runVM ./nix/vm/x11-cinnamon.nix;
- x11-gnome = runVM ./nix/vm/x11-gnome.nix;
- x11-plasma6 = runVM ./nix/vm/x11-plasma6.nix;
- x11-xfce = runVM ./nix/vm/x11-xfce.nix;
- };
+ in
+ {
+ wayland-cinnamon = runVM ./nix/vm/wayland-cinnamon.nix;
+ wayland-gnome = runVM ./nix/vm/wayland-gnome.nix;
+ wayland-plasma6 = runVM ./nix/vm/wayland-plasma6.nix;
+ x11-cinnamon = runVM ./nix/vm/x11-cinnamon.nix;
+ x11-gnome = runVM ./nix/vm/x11-gnome.nix;
+ x11-plasma6 = runVM ./nix/vm/x11-plasma6.nix;
+ x11-xfce = runVM ./nix/vm/x11-xfce.nix;
+ }
+ // (pkgs-stable.lib.mapAttrs' (
+ # This adds all of our VM tests as runnable apps that load
+ # the interactive driver (repl). We map all the names of the
+ # tests to "test-<name>" so its distinct from other apps.
+ name: value: {
+ name = "test-${name}";
+ value = {
+ type = "app";
+ program = pkgs-unstable.lib.getExe tests.${name}.driverInteractive;
+ };
+ }
+ )
+ tests);
}
# Our supported systems are the same supported systems as the Zig binaries.
) (builtins.attrNames zig.packages)
diff --git a/nix/tests/basic.nix b/nix/tests/basic.nix
new file mode 100644
index 000000000..4822c1500
--- /dev/null
+++ b/nix/tests/basic.nix
@@ -0,0 +1,26 @@
+{
+ name = "basic";
+
+ nodes.machine = {
+ config,
+ pkgs,
+ ...
+ }: {
+ users.users.alice = {
+ isNormalUser = true;
+ extraGroups = ["wheel"];
+ packages = with pkgs; [
+ firefox
+ (pkgs.callPackage ../package.nix {})
+ ];
+ };
+
+ system.stateVersion = "24.11";
+ };
+
+ testScript = ''
+ machine.wait_for_unit("default.target")
+ machine.succeed("su -- alice -c 'which firefox'")
+ machine.fail("su -- root -c 'which firefox'")
+ '';
+}
diff --git a/nix/tests/default.nix b/nix/tests/default.nix
new file mode 100644
index 000000000..6abab82ce
--- /dev/null
+++ b/nix/tests/default.nix
@@ -0,0 +1,14 @@
+{nixpkgs}: let
+ # mkTest does nothing special right now, its just a wrapper around
+ # runNixOSTest, but it could be extended in the future so I pulled it out.
+ mkTest = path:
+ nixpkgs.testers.runNixOSTest {
+ imports = [
+ path
+ ];
+ };
+in {
+ basic = mkTest ./basic.nix;
+ gnome = mkTest ./gnome.nix;
+ i3 = mkTest ./i3.nix;
+}
diff --git a/nix/tests/gnome.nix b/nix/tests/gnome.nix
new file mode 100644
index 000000000..dd0176596
--- /dev/null
+++ b/nix/tests/gnome.nix
@@ -0,0 +1,56 @@
+{
+ name = "gnome";
+
+ nodes.machine = {
+ config,
+ pkgs,
+ ...
+ }: {
+ users.users.alice = {
+ isNormalUser = true;
+ password = "alice";
+ extraGroups = ["wheel"];
+ packages = with pkgs; [
+ (pkgs.callPackage ../package.nix {})
+ ];
+ };
+
+ services.xserver.enable = true;
+
+ services.xserver.displayManager = {
+ gdm.enable = true;
+ gdm.debug = true;
+ };
+
+ services.displayManager.autoLogin = {
+ enable = true;
+ user = "alice";
+ };
+
+ services.xserver.desktopManager.gnome.enable = true;
+ services.xserver.desktopManager.gnome.debug = true;
+
+ systemd.user.services = {
+ "org.gnome.Shell@wayland" = {
+ serviceConfig = {
+ ExecStart = [
+ # Clear the list before overriding it.
+ ""
+ # Eval API is now internal so Shell needs to run in unsafe mode.
+ # TODO: improve test driver so that it supports openqa-like manipulation
+ # that would allow us to drop this mess.
+ "${pkgs.gnome-shell}/bin/gnome-shell --unsafe-mode"
+ ];
+ };
+ };
+ };
+
+ system.stateVersion = "24.11";
+ };
+
+ testScript = ''
+ machine.wait_for_unit("default.target")
+ machine.succeed("su -- alice -c 'which firefox'")
+ machine.fail("su -- root -c 'which firefox'")
+ '';
+}
diff --git a/nix/tests/i3.nix b/nix/tests/i3.nix
new file mode 100644
index 000000000..c1d5811f6
--- /dev/null
+++ b/nix/tests/i3.nix
@@ -0,0 +1,59 @@
+{
+ name = "gnome";
+
+ nodes.machine = {
+ config,
+ pkgs,
+ ...
+ }: {
+ users.users.alice = {
+ isNormalUser = true;
+ password = "alice";
+ extraGroups = ["wheel"];
+ packages = with pkgs; [
+ (pkgs.callPackage ../package.nix {})
+ ];
+ };
+
+ # We need an XDG portal for various applications to work properly,
+ # such as Flatpak applications.
+ xdg.portal = {
+ enable = true;
+ extraPortals = [ pkgs.xdg-desktop-portal-gtk ];
+ config.common.default = "*";
+ };
+
+ services.xserver = {
+ enable = true;
+ xkb.layout = "us";
+ dpi = 220;
+
+ desktopManager = {
+ xterm.enable = false;
+ wallpaper.mode = "fill";
+ };
+
+ displayManager = {
+ defaultSession = "none+i3";
+ lightdm.enable = true;
+ };
+
+ windowManager = {
+ i3.enable = true;
+ };
+ };
+
+ services.displayManager.autoLogin = {
+ enable = true;
+ user = "alice";
+ };
+
+ system.stateVersion = "24.11";
+ };
+
+ testScript = ''
+ machine.wait_for_unit("default.target")
+ machine.succeed("su -- alice -c 'which firefox'")
+ machine.fail("su -- root -c 'which firefox'")
+ '';
+}