1
0
Fork 0
selfhostblocks/test/modules/nginx.nix

78 lines
1.9 KiB
Nix
Raw Normal View History

{ pkgs, lib, ... }:
let
anyOpt = default: lib.mkOption {
type = lib.types.anything;
inherit default;
};
testConfig = m:
let
cfg = (lib.evalModules {
specialArgs = { inherit pkgs; };
modules = [
{
options = {
assertions = anyOpt [];
networking = anyOpt {};
security = anyOpt {};
services = anyOpt {};
shb.authelia = anyOpt {};
2024-01-12 08:22:46 +01:00
systemd = anyOpt {};
users = anyOpt {};
};
}
2024-01-12 08:22:46 +01:00
../../modules/blocks/ssl.nix
../../modules/blocks/nginx.nix
m
];
}).config;
in lib.attrsets.filterAttrsRecursive (n: v: n != "extraConfig") {
inherit (cfg) services;
shb = { inherit (cfg.shb) nginx; };
};
in
{
testNoOptions = {
expected = {
shb.nginx = {
accessLog = false;
2024-05-25 00:01:45 +02:00
vhosts = [];
debugLog = false;
};
services.nginx.enable = true;
};
expr = testConfig {};
};
testAuth = {
expected = {
2024-01-12 08:22:46 +01:00
nginx.enable = true;
nginx.virtualHosts."my.example.com" = {
forceSSL = true;
locations."/" = {};
locations."/authelia" = {};
2024-01-12 08:22:46 +01:00
sslCertificate = "/var/lib/certs/selfsigned/example.com.cert";
sslCertificateKey = "/var/lib/certs/selfsigned/example.com.key";
};
};
2024-01-12 08:22:46 +01:00
expr = (testConfig ({ config, ... }: {
shb.certs.cas.selfsigned.myca = {};
shb.certs.certs.selfsigned."example.com" = {
ca = config.shb.certs.cas.selfsigned.myca;
domain = "example.com";
};
2024-05-25 00:01:45 +02:00
shb.nginx.vhosts = [{
subdomain = "my";
domain = "example.com";
2024-01-12 08:22:46 +01:00
ssl = config.shb.certs.certs.selfsigned."example.com";
upstream = "http://127.0.0.1:1234";
authEndpoint = "hello";
autheliaRules = [{}];
}];
2024-01-12 08:22:46 +01:00
})).services;
};
}