rework stirling-pdf to be more generic with test

This commit is contained in:
2025-07-31 10:40:31 +07:00
parent c5c8e0050d
commit 5109c3f4fa
6 changed files with 88 additions and 34 deletions

View File

@@ -8,7 +8,6 @@
{ {
clan = { clan = {
modules = { modules = {
stirling-pdf = ../modules/clan/stirling-pdf;
victoria-metrics = ../modules/clan/victoria-metrics; victoria-metrics = ../modules/clan/victoria-metrics;
}; };
inventory = { inventory = {

View File

@@ -0,0 +1,26 @@
{ config, ... }:
let
stDomain = "${config.clan.core.vars.generators.b4l-stirling-pdf.files.subdomain.value}.${config.networking.fqdn}";
in
{
clan.core.vars.generators.b4l-stirling-pdf = {
files.subdomain.secret = false;
prompts = {
subdomain = {
persist = true;
type = "line";
description = "Sub-domain for Stirling PDF app. Default:(pdf)";
};
};
script = ''cat $prompts/subdomain || echo -n "pdf" > $out/subdomain'';
};
services.nginx.virtualHosts."${stDomain}" = {
forceSSL = true;
useACMEHost = "${config.networking.fqdn}";
locations."/" = {
proxyPass = "http://localhost:${builtins.toString config.services.stirling-pdf.environment.SERVER_PORT}";
};
};
}

View File

@@ -1,4 +1,4 @@
{ lib, ... }: { ... }:
{ {
_class = "clan.service"; _class = "clan.service";
manifest.name = "stirling-pdf"; manifest.name = "stirling-pdf";
@@ -6,43 +6,18 @@
manifest.categories = [ "System" ]; manifest.categories = [ "System" ];
roles.default = { roles.default = {
interface.options = { perInstance.nixosModule =
domain = lib.mkOption {
type = lib.types.str;
default = "pdf";
description = "Sub domain or Stirling PDF service";
};
};
perInstance =
{ {
settings, lib,
... ...
}: }:
{ {
nixosModule = services.stirling-pdf = {
{ enable = lib.mkDefault true;
config, environment = {
... SERVER_PORT = lib.mkDefault 8080;
}:
let
domain = "${settings.domain}.${config.networking.fqdn}";
in
{
services.stirling-pdf = {
enable = true;
environment = {
SERVER_PORT = 8080;
};
};
services.nginx.virtualHosts."${domain}" = {
forceSSL = true;
useACMEHost = "${config.networking.fqdn}";
locations."/" = {
proxyPass = "http://localhost:${builtins.toString config.services.stirling-pdf.environment.SERVER_PORT}";
};
};
}; };
};
}; };
}; };
} }

View File

@@ -0,0 +1,19 @@
{ lib, ... }:
let
module = lib.modules.importApply ./default.nix { };
in
{
clan.modules = {
stirling-pdf = module;
};
perSystem =
{ ... }:
{
clan.nixosTests.stirling-pdf = {
imports = [ ./tests/vm/default.nix ];
clan.modules."@clan/stirling-pdf" = module;
};
};
}

View File

@@ -0,0 +1,34 @@
{
...
}:
{
name = "service-stirling-pdf";
clan = {
directory = ./.;
inventory = {
machines.server = { };
instances = {
actual-budget-test = {
module.name = "@clan/stirling-pdf";
module.input = "self";
roles.default.machines."server".settings = { };
};
};
};
};
nodes = {
server = { };
};
testScript = ''
start_all()
server.wait_for_unit("stirling-pdf")
server.succeed("systemctl status stirling-pdf")
'';
}

View File

@@ -0,0 +1 @@
pdf