about summary refs log tree commit diff
diff options
context:
space:
mode:
authorVika <vika@fireburn.ru>2024-05-19 01:27:56 +0300
committerVika <vika@fireburn.ru>2024-05-19 01:27:56 +0300
commit113a6f9fe6603be7488c1c9a5bb4b1b7c5bb2f71 (patch)
tree2d123cbe52f96cc1e470b754bb92d22776cb12df
parent9821be44cfdcbdc9c5a37b8eabddccabe0cbeabf (diff)
Move NixOS test initialization to the package
This allows to initialize tests easier and not have them depend on the
flake itself. This might be useful if I ever have to build this
package without a flake.
-rw-r--r--flake.nix12
-rw-r--r--kittybox.nix11
-rw-r--r--nixos-tests/distributed-test.nix3
-rw-r--r--nixos-tests/postgres-smoke-test.nix3
-rw-r--r--nixos-tests/smoke-test.nix5
-rw-r--r--nixos-tests/webmention-test.nix3
6 files changed, 19 insertions, 18 deletions
diff --git a/flake.nix b/flake.nix
index c844c23..d2e20a5 100644
--- a/flake.nix
+++ b/flake.nix
@@ -32,20 +32,16 @@
       kittybox = pkgs.callPackage ./kittybox.nix {
         naersk = naersk.lib.${system};
         inherit (pkgs.nodePackages) typescript;
-        nixosTests = {
-          smokeTest = self.checks.${system}.nixos-test;
-          postgresSmokeTest = self.checks.${system}.nixos-test-postgres;
-        };
       };
       default = self.packages.${system}.kittybox;
     };
 
     checks = {
       kittybox = self.packages.${system}.kittybox;
-      distributed-test = pkgs.nixosTest (import ./nixos-tests/distributed-test.nix self);
-      nixos-test = pkgs.nixosTest (import ./nixos-tests/smoke-test.nix self);
-      nixos-test-postgres = pkgs.nixosTest (import ./nixos-tests/postgres-smoke-test.nix self);
-      webmention-test = pkgs.nixosTest (import ./nixos-tests/webmention-test.nix self);
+      distributed-test = self.packages.${system}.kittybox.tests.distributed;
+      nixos-test = self.packages.${system}.kittybox.tests.smokeTest;
+      nixos-test-postgres = self.packages.${system}.kittybox.tests.postgresSmokeTest;
+      webmention-test = self.packages.${system}.kittybox.tests.webmention;
       dockerContainer = pkgs.callPackage ./docker.nix {
         inherit (self.packages.${system}) kittybox;
         rev = self.rev or "development";
diff --git a/kittybox.nix b/kittybox.nix
index 1d66fc7..eea7006 100644
--- a/kittybox.nix
+++ b/kittybox.nix
@@ -1,7 +1,7 @@
 { stdenv, lib, naersk, lld, mold, typescript
 , useWebAuthn ? false, openssl, zlib, pkg-config, protobuf
 , usePostgres ? true, postgresql, postgresqlTestHook
-, nixosTests }:
+, nixosTest }:
 
 assert useWebAuthn -> openssl != null && pkg-config != null;
 assert usePostgres -> postgresql != null && postgresqlTestHook != null;
@@ -36,7 +36,14 @@ naersk.buildPackage rec {
   '';
 
   passthru = {
-    tests = nixosTests;
+    tests = {
+      distributed = nixosTest ./nixos-tests/distributed-test.nix;
+      smokeTest = nixosTest ./nixos-tests/smoke-test.nix;
+    } // (lib.optionalAttrs usePostgres {
+      webmention = nixosTest ./nixos-tests/webmention-test.nix;
+      postgresSmokeTest = nixosTest ./nixos-tests/postgres-smoke-test.nix;
+    });
+
     hasPostgres = usePostgres;
   };
 
diff --git a/nixos-tests/distributed-test.nix b/nixos-tests/distributed-test.nix
index 11c2dba..5e43bbf 100644
--- a/nixos-tests/distributed-test.nix
+++ b/nixos-tests/distributed-test.nix
@@ -1,9 +1,8 @@
 # This doesn't seem to work for some reason. I wonder why.
 # The VMs themselves don't want to launch properly.
-kittybox:
 { lib, system, ... }: let
   kittyboxModule = { config, pkgs, lib, ... }: {
-    imports = [ kittybox.nixosModules.default commonModule ];
+    imports = [ ../configuration.nix commonModule ];
 
     services.kittybox = {
       enable = true;
diff --git a/nixos-tests/postgres-smoke-test.nix b/nixos-tests/postgres-smoke-test.nix
index 51d53c7..59096d3 100644
--- a/nixos-tests/postgres-smoke-test.nix
+++ b/nixos-tests/postgres-smoke-test.nix
@@ -1,10 +1,9 @@
-kittybox:
 { lib, ... }: {
   name = "nixos-kittybox";
 
   nodes = {
     kittybox = { config, pkgs, lib, ... }: {
-      imports = [ kittybox.nixosModules.default ];
+      imports = [ ../configuration.nix ];
 
       services.postgresql = {
         enable = true;
diff --git a/nixos-tests/smoke-test.nix b/nixos-tests/smoke-test.nix
index b043a31..737dbab 100644
--- a/nixos-tests/smoke-test.nix
+++ b/nixos-tests/smoke-test.nix
@@ -1,11 +1,12 @@
-kittybox:
 { lib, ... }: {
   name = "nixos-kittybox";
 
   nodes = {
     kittybox = { config, pkgs, lib, ... }: {
-      imports = [ kittybox.nixosModules.default ];
+      imports = [ ../configuration.nix ];
 
+      # TODO: figure out if we can get rid of Postgres here
+      # even at the cost of Webmention functionality
       services.postgresql = {
         enable = true;
         ensureDatabases = ["kittybox"];
diff --git a/nixos-tests/webmention-test.nix b/nixos-tests/webmention-test.nix
index 45e3ff7..314b3d4 100644
--- a/nixos-tests/webmention-test.nix
+++ b/nixos-tests/webmention-test.nix
@@ -1,4 +1,3 @@
-kittybox:
 { lib, ... }: let
   hosts = ''
     192.168.2.101 kittybox.test
@@ -9,7 +8,7 @@ in {
 
   nodes = {
     kittybox = { config, pkgs, lib, ... }: {
-      imports = [ kittybox.nixosModules.default ];
+      imports = [ ../configuration.nix ];
 
       services.postgresql = {
         enable = true;