2024-03-04 02:01:00 +01:00
|
|
|
{ pkgs, lib, ... }:
|
2024-03-05 05:36:47 +01:00
|
|
|
let
|
2024-03-20 06:50:41 +01:00
|
|
|
pkgs' = pkgs;
|
|
|
|
|
2024-07-12 13:01:26 +02:00
|
|
|
testLib = pkgs.callPackage ../common.nix {};
|
|
|
|
|
2024-06-07 07:22:44 +02:00
|
|
|
subdomain = "a";
|
|
|
|
domain = "example.com";
|
|
|
|
fqdn = "${subdomain}.${domain}";
|
|
|
|
|
2024-07-12 13:01:26 +02:00
|
|
|
commonTestScript = testLib.accessScript {
|
|
|
|
inherit fqdn;
|
|
|
|
hasSSL = { node, ... }: !(isNull node.config.shb.audiobookshelf.ssl);
|
|
|
|
waitForServices = { ... }: [
|
|
|
|
"audiobookshelf.service"
|
|
|
|
"nginx.service"
|
|
|
|
];
|
|
|
|
waitForPorts = { node, ... }: [
|
|
|
|
node.config.shb.audiobookshelf.webPort
|
|
|
|
];
|
|
|
|
# TODO: Test login
|
|
|
|
# extraScript = { ... }: ''
|
|
|
|
# '';
|
|
|
|
};
|
2024-03-04 02:01:00 +01:00
|
|
|
|
2024-06-07 07:22:44 +02:00
|
|
|
base = {
|
|
|
|
imports = [
|
|
|
|
(pkgs'.path + "/nixos/modules/profiles/headless.nix")
|
|
|
|
(pkgs'.path + "/nixos/modules/profiles/qemu-guest.nix")
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
shb.backup = lib.mkOption { type = lib.types.anything; };
|
|
|
|
};
|
|
|
|
}
|
|
|
|
../../modules/services/audiobookshelf.nix
|
|
|
|
];
|
2024-03-04 02:01:00 +01:00
|
|
|
|
2024-06-07 07:22:44 +02:00
|
|
|
# Nginx port.
|
|
|
|
networking.firewall.allowedTCPPorts = [ 80 443 ];
|
2024-03-04 02:01:00 +01:00
|
|
|
};
|
|
|
|
|
2024-06-07 07:22:44 +02:00
|
|
|
certs = { config, ... }: {
|
|
|
|
imports = [
|
|
|
|
../../modules/blocks/ssl.nix
|
|
|
|
];
|
|
|
|
|
|
|
|
shb.certs = {
|
|
|
|
cas.selfsigned.myca = {
|
|
|
|
name = "My CA";
|
|
|
|
};
|
|
|
|
certs.selfsigned = {
|
|
|
|
n = {
|
|
|
|
ca = config.shb.certs.cas.selfsigned.myca;
|
|
|
|
domain = "*.${domain}";
|
|
|
|
group = "nginx";
|
2024-03-04 02:01:00 +01:00
|
|
|
};
|
|
|
|
};
|
2024-06-07 07:22:44 +02:00
|
|
|
};
|
2024-03-04 02:01:00 +01:00
|
|
|
|
2024-06-07 07:22:44 +02:00
|
|
|
systemd.services.nginx.after = [ config.shb.certs.certs.selfsigned.n.systemdService ];
|
|
|
|
systemd.services.nginx.requires = [ config.shb.certs.certs.selfsigned.n.systemdService ];
|
|
|
|
};
|
2024-03-04 02:01:00 +01:00
|
|
|
|
2024-06-07 07:22:44 +02:00
|
|
|
basic = {
|
|
|
|
shb.audiobookshelf = {
|
|
|
|
enable = true;
|
|
|
|
inherit subdomain domain;
|
|
|
|
};
|
|
|
|
};
|
2024-03-04 02:01:00 +01:00
|
|
|
|
2024-06-07 07:22:44 +02:00
|
|
|
https = { config, ... }: {
|
|
|
|
shb.audiobookshelf = {
|
|
|
|
ssl = config.shb.certs.certs.selfsigned.n;
|
2024-03-04 02:01:00 +01:00
|
|
|
};
|
2024-06-07 07:22:44 +02:00
|
|
|
};
|
2024-03-04 02:01:00 +01:00
|
|
|
|
2024-06-07 07:22:44 +02:00
|
|
|
sso = { config, ... }: {
|
|
|
|
imports = [
|
|
|
|
../../modules/blocks/authelia.nix
|
|
|
|
../../modules/blocks/ldap.nix
|
|
|
|
../../modules/blocks/postgresql.nix
|
|
|
|
];
|
|
|
|
|
|
|
|
shb.ldap = {
|
|
|
|
enable = true;
|
|
|
|
inherit domain;
|
|
|
|
subdomain = "ldap";
|
|
|
|
ldapPort = 3890;
|
|
|
|
webUIListenPort = 17170;
|
|
|
|
dcdomain = "dc=example,dc=com";
|
|
|
|
ldapUserPasswordFile = pkgs.writeText "ldapUserPassword" "ldapUserPassword";
|
|
|
|
jwtSecretFile = pkgs.writeText "jwtSecret" "jwtSecret";
|
|
|
|
};
|
2024-03-04 02:01:00 +01:00
|
|
|
|
2024-06-07 07:22:44 +02:00
|
|
|
shb.authelia = {
|
|
|
|
enable = true;
|
|
|
|
inherit domain;
|
|
|
|
subdomain = "auth";
|
|
|
|
ssl = config.shb.certs.certs.selfsigned.n;
|
2024-03-04 02:01:00 +01:00
|
|
|
|
2024-06-07 07:22:44 +02:00
|
|
|
ldapEndpoint = "ldap://127.0.0.1:${builtins.toString config.shb.ldap.ldapPort}";
|
|
|
|
dcdomain = config.shb.ldap.dcdomain;
|
2024-03-04 02:01:00 +01:00
|
|
|
|
2024-06-07 07:22:44 +02:00
|
|
|
secrets = {
|
2024-03-04 02:01:00 +01:00
|
|
|
jwtSecretFile = pkgs.writeText "jwtSecret" "jwtSecret";
|
2024-06-07 07:22:44 +02:00
|
|
|
ldapAdminPasswordFile = pkgs.writeText "ldapUserPassword" "ldapUserPassword";
|
|
|
|
sessionSecretFile = pkgs.writeText "sessionSecret" "sessionSecret";
|
|
|
|
storageEncryptionKeyFile = pkgs.writeText "storageEncryptionKey" "storageEncryptionKey";
|
|
|
|
identityProvidersOIDCHMACSecretFile = pkgs.writeText "identityProvidersOIDCHMACSecret" "identityProvidersOIDCHMACSecret";
|
|
|
|
identityProvidersOIDCIssuerPrivateKeyFile = (pkgs.runCommand "gen-private-key" {} ''
|
|
|
|
mkdir $out
|
|
|
|
${pkgs.openssl}/bin/openssl genrsa -out $out/private.pem 4096
|
|
|
|
'') + "/private.pem";
|
2024-03-04 02:01:00 +01:00
|
|
|
};
|
2024-06-07 07:22:44 +02:00
|
|
|
};
|
2024-03-04 02:01:00 +01:00
|
|
|
|
2024-06-07 07:22:44 +02:00
|
|
|
shb.audiobookshelf = {
|
|
|
|
authEndpoint = "https://${config.shb.authelia.subdomain}.${config.shb.authelia.domain}";
|
|
|
|
ssoSecretFile = pkgs.writeText "ssoSecretFile" "ssoSecretFile";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
in
|
|
|
|
{
|
|
|
|
basic = pkgs.testers.runNixOSTest {
|
|
|
|
name = "audiobookshelf-basic";
|
|
|
|
|
|
|
|
nodes.server = lib.mkMerge [
|
|
|
|
base
|
|
|
|
basic
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
shb.authelia = lib.mkOption { type = lib.types.anything; };
|
2024-03-04 02:01:00 +01:00
|
|
|
};
|
2024-06-07 07:22:44 +02:00
|
|
|
}
|
|
|
|
];
|
2024-03-04 02:01:00 +01:00
|
|
|
|
2024-06-07 07:22:44 +02:00
|
|
|
nodes.client = {};
|
|
|
|
|
|
|
|
testScript = commonTestScript;
|
|
|
|
};
|
|
|
|
|
|
|
|
https = pkgs.testers.runNixOSTest {
|
|
|
|
name = "audiobookshelf-https";
|
|
|
|
|
|
|
|
nodes.server = lib.mkMerge [
|
|
|
|
base
|
|
|
|
certs
|
|
|
|
basic
|
|
|
|
https
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
shb.authelia = lib.mkOption { type = lib.types.anything; };
|
2024-03-04 02:01:00 +01:00
|
|
|
};
|
2024-06-07 07:22:44 +02:00
|
|
|
}
|
|
|
|
];
|
2024-03-04 02:01:00 +01:00
|
|
|
|
2024-06-07 07:22:44 +02:00
|
|
|
nodes.client = {};
|
2024-03-04 02:01:00 +01:00
|
|
|
|
2024-06-07 07:22:44 +02:00
|
|
|
testScript = commonTestScript;
|
|
|
|
};
|
|
|
|
|
|
|
|
sso = pkgs.testers.runNixOSTest {
|
|
|
|
name = "audiobookshelf-sso";
|
|
|
|
|
|
|
|
nodes.server = lib.mkMerge [
|
|
|
|
base
|
|
|
|
certs
|
|
|
|
basic
|
|
|
|
https
|
|
|
|
sso
|
|
|
|
];
|
2024-03-04 02:01:00 +01:00
|
|
|
|
|
|
|
nodes.client = {};
|
|
|
|
|
2024-03-05 05:36:47 +01:00
|
|
|
testScript = commonTestScript;
|
2024-03-04 02:01:00 +01:00
|
|
|
};
|
|
|
|
}
|