From 19d50fae6385fb5238683e9b9bf3816617cc637c Mon Sep 17 00:00:00 2001 From: h7x4 Date: Sat, 27 Jan 2024 07:39:59 +0100 Subject: [PATCH] nginx-pipeline: add basic test --- .gitignore | 1 + flake.lock | 20 ++++++++-------- flake.nix | 22 +++++++++++++++--- tests/default.nix | 4 ++++ tests/nginx-pipeline/default.nix | 39 ++++++++++++++++++++++++++++++++ 5 files changed, 73 insertions(+), 13 deletions(-) create mode 100644 .gitignore create mode 100644 tests/default.nix create mode 100644 tests/nginx-pipeline/default.nix diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b2be92b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +result diff --git a/flake.lock b/flake.lock index e8d4a00..ffc815b 100644 --- a/flake.lock +++ b/flake.lock @@ -1,23 +1,23 @@ { "nodes": { - "nixpkgs-lib": { + "nixpkgs": { "locked": { - "lastModified": 1673743903, - "narHash": "sha256-sloY6KYyVOozJ1CkbgJPpZ99TKIjIvM+04V48C04sMQ=", - "owner": "nix-community", - "repo": "nixpkgs.lib", - "rev": "7555e2dfcbac1533f047021f1744ac8871150f9f", + "lastModified": 1706098335, + "narHash": "sha256-r3dWjT8P9/Ah5m5ul4WqIWD8muj5F+/gbCdjiNVBKmU=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "a77ab169a83a4175169d78684ddd2e54486ac651", "type": "github" }, "original": { - "owner": "nix-community", - "repo": "nixpkgs.lib", - "type": "github" + "id": "nixpkgs", + "ref": "nixos-23.11", + "type": "indirect" } }, "root": { "inputs": { - "nixpkgs-lib": "nixpkgs-lib" + "nixpkgs": "nixpkgs" } } }, diff --git a/flake.nix b/flake.nix index a6125b5..b284666 100644 --- a/flake.nix +++ b/flake.nix @@ -2,13 +2,29 @@ description = "NixOS modules for matrix related services"; inputs = { - nixpkgs-lib.url = github:nix-community/nixpkgs.lib; + nixpkgs.url = "nixpkgs/nixos-23.11"; }; - outputs = { self, nixpkgs-lib }: { + outputs = { self, nixpkgs }: { nixosModules = { default = import ./module.nix; }; - lib = import ./lib.nix { lib = nixpkgs-lib.lib; }; + + lib = import ./lib.nix { lib = nixpkgs.lib; }; + + packages = let + forAllSystems = f: + nixpkgs.lib.genAttrs [ + "x86_64-linux" + "aarch64-linux" + "x86_64-darwin" + "aarch64-darwin" + ] (system: f nixpkgs.legacyPackages.${system}); + in forAllSystems (pkgs: { + tests = import ./tests { + inherit nixpkgs pkgs; + matrix-lib = self.lib; + }; + }); }; } diff --git a/tests/default.nix b/tests/default.nix new file mode 100644 index 0000000..5ad1572 --- /dev/null +++ b/tests/default.nix @@ -0,0 +1,4 @@ +{ nixpkgs, pkgs, matrix-lib, ... }: +{ + nginx-pipeline = pkgs.callPackage ./nginx-pipeline { inherit nixpkgs matrix-lib; }; +} diff --git a/tests/nginx-pipeline/default.nix b/tests/nginx-pipeline/default.nix new file mode 100644 index 0000000..87d84a8 --- /dev/null +++ b/tests/nginx-pipeline/default.nix @@ -0,0 +1,39 @@ +{ nixpkgs, lib, matrix-lib, writeText, ... }: +let + nixosConfig = nixpkgs.lib.nixosSystem { + system = "x86_64-linux"; + modules = [ + ../../module.nix + { + system.stateVersion = "23.11"; + boot.isContainer = true; + services.matrix-synapse-next = { + enable = true; + enableNginx = true; + + workers = { + enableMetrics = true; + + federationSenders = 3; + federationReceivers = 3; + initialSyncers = 1; + normalSyncers = 1; + eventPersisters = 1; + useUserDirectoryWorker = true; + }; + + settings.server_name = "example.com"; + }; + } + ]; + }; + + inherit (nixosConfig.config.services.matrix-synapse-next.workers) instances; +in + writeText "matrix-synapse-next-nginx-pipeline-test.txt" '' + ${(lib.generators.toPretty {}) instances} + + ==================================================== + + ${(lib.generators.toPretty {}) (matrix-lib.mapWorkersToUpstreamsByType instances)} + ''