From f3fcbc2b40953ca5388a30becf9a8fdfb3f8706c Mon Sep 17 00:00:00 2001 From: h7x4 Date: Tue, 1 Aug 2023 22:34:55 +0200 Subject: [PATCH] WIP: create tests --- flake.lock | 16 ++++++++++++++++ flake.nix | 18 ++++++++++++++++-- tests/auto-workers-config.nix | 18 ++++++++++++++++++ tests/base-config.nix | 7 +++++++ tests/default.nix | 16 ++++++++++++++++ 5 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 tests/auto-workers-config.nix create mode 100644 tests/base-config.nix create mode 100644 tests/default.nix diff --git a/flake.lock b/flake.lock index e8d4a00..1d33786 100644 --- a/flake.lock +++ b/flake.lock @@ -1,5 +1,20 @@ { "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1690789960, + "narHash": "sha256-3K+2HuyGTiJUSZNJxXXvc0qj4xFx1FHC/ItYtEa7/Xs=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "fb942492b7accdee4e6d17f5447091c65897dde4", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "ref": "nixos-unstable", + "type": "indirect" + } + }, "nixpkgs-lib": { "locked": { "lastModified": 1673743903, @@ -17,6 +32,7 @@ }, "root": { "inputs": { + "nixpkgs": "nixpkgs", "nixpkgs-lib": "nixpkgs-lib" } } diff --git a/flake.nix b/flake.nix index a6125b5..a49ab39 100644 --- a/flake.nix +++ b/flake.nix @@ -2,13 +2,27 @@ description = "NixOS modules for matrix related services"; inputs = { - nixpkgs-lib.url = github:nix-community/nixpkgs.lib; + nixpkgs-lib.url = "github:nix-community/nixpkgs.lib"; + nixpkgs.url = "nixpkgs/nixos-unstable"; }; - outputs = { self, nixpkgs-lib }: { + outputs = { self, nixpkgs, nixpkgs-lib }: { nixosModules = { default = import ./module.nix; }; + lib = import ./lib.nix { lib = nixpkgs-lib.lib; }; + + packages = let + system = "x86_64-linux"; + pkgs = nixpkgs.legacyPackages.${system}; + in { + ${system}.tests = import ./tests { + inherit system; + inherit nixpkgs; + inherit pkgs; + nixosModule = self.outputs.nixosModules.synapse; + }; + }; }; } diff --git a/tests/auto-workers-config.nix b/tests/auto-workers-config.nix new file mode 100644 index 0000000..21ec478 --- /dev/null +++ b/tests/auto-workers-config.nix @@ -0,0 +1,18 @@ +{ pkgs, lib, ... }: +{ + services.matrix-synapse-next = { + enable = true; + settings.server_name = "matrix.example.com"; + + workers = { + enableMetrics = true; + + federationSenders = 2; + federationReceivers = 2; + initialSyncers = 2; + normalSyncers = 2; + eventPersisters = 2; + useUserDirectoryWorker = true; + }; + }; +} diff --git a/tests/base-config.nix b/tests/base-config.nix new file mode 100644 index 0000000..8dc7d43 --- /dev/null +++ b/tests/base-config.nix @@ -0,0 +1,7 @@ +{ pkgs, lib, ... }: +{ + services.matrix-synapse-next = { + enable = true; + settings.server_name = "matrix.example.com"; + }; +} diff --git a/tests/default.nix b/tests/default.nix new file mode 100644 index 0000000..9e6b57d --- /dev/null +++ b/tests/default.nix @@ -0,0 +1,16 @@ +{ nixpkgs, pkgs, system ? pkgs.system, nixosModule, ... }: let + buildSystemWithConfig = configPath: (nixpkgs.lib.nixosSystem { + inherit system; + modules = [ + nixosModule + configPath + { + boot.isContainer = true; + } + ]; + }).config.system.build.toplevel; +in { + a = pkgs.writeText "hello-world" ''a''; + base-config = buildSystemWithConfig ./base-config.nix; + auto-workers-config = buildSystemWithConfig ./auto-workers-config.nix; +}