From 01971a632323cd9f3dbf9857bfd968844d1e38d9 Mon Sep 17 00:00:00 2001 From: Ruby Iris Juric Date: Wed, 28 May 2025 14:39:51 +1000 Subject: [PATCH] nixos/tests/sharkey: init --- nixos/tests/all-tests.nix | 1 + nixos/tests/web-apps/sharkey.nix | 55 +++++++++++++++++++++++++++++ pkgs/by-name/sh/sharkey/package.nix | 3 ++ 3 files changed, 59 insertions(+) create mode 100644 nixos/tests/web-apps/sharkey.nix diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index 82aef7fdea8a..d370a4180286 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -1277,6 +1277,7 @@ in sgt-puzzles = runTest ./sgt-puzzles.nix; shadow = runTest ./shadow.nix; shadowsocks = handleTest ./shadowsocks { }; + sharkey = runTest ./web-apps/sharkey.nix; shattered-pixel-dungeon = runTest ./shattered-pixel-dungeon.nix; shiori = runTest ./shiori.nix; signal-desktop = runTest ./signal-desktop.nix; diff --git a/nixos/tests/web-apps/sharkey.nix b/nixos/tests/web-apps/sharkey.nix new file mode 100644 index 000000000000..b10fec68744e --- /dev/null +++ b/nixos/tests/web-apps/sharkey.nix @@ -0,0 +1,55 @@ +{ lib, ... }: + +let + meilisearchKey = "TESTKEY-naXRkVX7nhvLaGOmGGuicDKxZAj0khEaoOZPeEZafv8w9j8V6aKb0NVdXRChL5kR"; +in +{ + name = "sharkey"; + + nodes.machine = + { pkgs, ... }: + { + services.sharkey = { + enable = true; + setupMeilisearch = true; + environmentFiles = [ "/run/secrets/sharkey-env" ]; + settings = { + url = "http://exampleurl.invalid"; + meilisearch.index = "exampleurl_invalid"; + }; + }; + + services.meilisearch.masterKeyEnvironmentFile = pkgs.writeText "meilisearch-key" '' + MEILI_MASTER_KEY=${meilisearchKey} + ''; + }; + + testScript = + let + createIndexPayload = builtins.toJSON { + description = "Sharkey API key"; + actions = [ "*" ]; + indexes = [ "exampleurl_invalid---notes" ]; + expiresAt = null; + }; + in + '' + import json + + with subtest("Setting up Meilisearch API key and index"): + machine.wait_for_unit("meilisearch.service") + machine.wait_for_open_port(7700) + + json_body = '${createIndexPayload}' + create_index_result = json.loads(machine.succeed(f"curl -s -X POST 'http://localhost:7700/keys' -H 'Content-Type: application/json' -H 'Authorization: Bearer ${meilisearchKey}' --data-binary '{json_body}'")) + machine.succeed(f"mkdir /run/secrets; echo 'MK_CONFIG_MEILISEARCH_APIKEY={create_index_result["key"]}' > /run/secrets/sharkey-env") + + with subtest("Testing Sharkey is running and listening to HTTP requests"): + machine.systemctl("restart sharkey") + machine.wait_for_open_port(3000) + + machine.succeed("curl --fail http://localhost:3000") + ''; + + meta.maintainers = with lib.maintainers; [ srxl ]; +} diff --git a/pkgs/by-name/sh/sharkey/package.nix b/pkgs/by-name/sh/sharkey/package.nix index 0f8494c79341..2db89f5d1838 100644 --- a/pkgs/by-name/sh/sharkey/package.nix +++ b/pkgs/by-name/sh/sharkey/package.nix @@ -2,6 +2,7 @@ stdenv, lib, fetchFromGitLab, + nixosTests, bash, cairo, cctools, @@ -151,6 +152,8 @@ stdenv.mkDerivation (finalAttrs: { runHook postFixup ''; + passthru.tests.sharkey = nixosTests.sharkey; + meta = { description = "Sharkish microblogging platform"; homepage = "https://joinsharkey.org";