1
0
Fork 0

add more tests to be able to import shb with default config

This commit is contained in:
ibizaman 2023-11-08 12:27:47 -08:00
parent 9a758fb86e
commit af71513dcf
5 changed files with 113 additions and 14 deletions

View file

@ -42,11 +42,14 @@
let
importFiles = files:
map (m: import m {
inherit pkgs;
inherit (pkgs) lib;
}) files;
mergeTests = pkgs.lib.lists.foldl pkgs.lib.trivial.mergeAttrs {};
in mergeTests (importFiles [
./test/modules/arr.nix
./test/modules/davfs.nix
./test/modules/postgresql.nix
]);
};

View file

@ -24,6 +24,7 @@ let
settingsFormat = pkgs.formats.json {};
moreOptions = {
settings = lib.mkOption {
default = {};
type = lib.types.submodule {
freeformType = apps.jackett.settingsFormat.type;
options = {
@ -66,6 +67,7 @@ let
appOption = name: c: lib.nameValuePair name (lib.mkOption {
description = "Configuration for ${name}";
default = {};
type = lib.types.submodule {
options = {
enable = lib.mkEnableOption "selfhostblocks.${name}";
@ -95,7 +97,8 @@ let
};
oidcEndpoint = lib.mkOption {
type = lib.types.str;
type = lib.types.nullOr lib.types.str;
default = null;
description = "OIDC endpoint for SSO";
example = "https://authelia.example.com";
};
@ -125,7 +128,7 @@ in
enable = true;
dataDir = "/var/lib/radarr";
};
users.users.radarr = {
users.users.radarr = lib.mkIf cfg.radarr.enable {
extraGroups = [ "media" ];
};
@ -134,7 +137,7 @@ in
enable = true;
dataDir = "/var/lib/sonarr";
};
users.users.sonarr = {
users.users.sonarr = lib.mkIf cfg.sonarr.enable {
extraGroups = [ "media" ];
};
@ -142,13 +145,16 @@ in
enable = true;
listenPort = cfg.bazarr.port;
};
users.users.bazarr = lib.mkIf cfg.bazarr.enable {
extraGroups = [ "media" ];
};
# Listens on port 8787
services.readarr = lib.mkIf cfg.readarr.enable {
enable = true;
dataDir = "/var/lib/readarr";
};
users.users.readarr = {
users.users.readarr = lib.mkIf cfg.readarr.enable {
extraGroups = [ "media" ];
};
@ -157,7 +163,7 @@ in
enable = true;
dataDir = "/var/lib/lidarr";
};
users.users.lidarr = {
users.users.lidarr = lib.mkIf cfg.lidarr.enable {
extraGroups = [ "media" ];
};
@ -166,12 +172,12 @@ in
enable = true;
dataDir = "/var/lib/jackett";
};
shb.arr.jackett.settings = {
shb.arr.jackett.settings = lib.mkIf cfg.jackett.enable {
Port = config.shb.arr.jackett.port;
AllowExternal = "false";
UpdateDisabled = "true";
};
users.users.jackett = {
users.users.jackett = lib.mkIf cfg.jackett.enable {
extraGroups = [ "media" ];
};
systemd.services.jackett.preStart =
@ -184,14 +190,16 @@ in
OmdbApiKey = "%OMDBAPIKEY%";
};
templatedSettings = (removeAttrs s [ "APIKeyFile" "OmdbApiKeyFile" ]) // templatedfileSettings;
in
template (apps.jackett.settingsFormat.generate "jackett.json" templatedSettings) "${config.services.jackett.dataDir}/ServerConfig.json" (
t = template (apps.jackett.settingsFormat.generate "jackett.json" templatedSettings) "${config.services.jackett.dataDir}/ServerConfig.json" (
lib.optionalAttrs (!(isNull s.APIKeyFile)) {
"%APIKEY%" = "$(cat ${s.APIKeyFile})";
} // lib.optionalAttrs (!(isNull s.OmdbApiKeyFile)) {
"%OMDBAPIKEY%" = "$(cat ${s.OmdbApiKeyFile})";
}
);
in
lib.mkIf cfg.jackett.enable t;
shb.nginx.autheliaProtect =
let
@ -199,7 +207,7 @@ in
let
c = cfg.${name};
in
{
lib.mkIf (c.oidcEndpoint != null) {
inherit (c) subdomain domain oidcEndpoint;
upstream = "http://127.0.0.1:${toString c.port}";
autheliaRules = [
@ -235,7 +243,7 @@ in
in
lib.mkMerge (lib.mapAttrsToList backupConfig apps);
}
] ++ map (name: {
] ++ map (name: lib.mkIf cfg.${name}.enable {
systemd.tmpfiles.rules = lib.mkIf (lib.hasAttr "dataDir" config.services.${name}) [
"d '${config.services.${name}.dataDir}' 0750 ${config.services.${name}.user} ${config.services.${name}.group} - -"
];

52
test/modules/arr.nix Normal file
View file

@ -0,0 +1,52 @@
{ pkgs, lib, ... }:
let
anyOpt = default: lib.mkOption {
type = lib.types.anything;
inherit default;
};
testConfig = m:
let
cfg = (lib.evalModules {
specialArgs = { inherit pkgs; };
modules = [
{
options = {
systemd = anyOpt {};
shb.backup = anyOpt {};
shb.nginx = anyOpt {};
users = anyOpt {};
services.bazarr = anyOpt {};
services.jackett = anyOpt {};
services.lidarr = anyOpt {};
services.radarr = anyOpt {};
services.readarr = anyOpt {};
services.sonarr = anyOpt {};
};
}
../../modules/arr.nix
m
];
}).config;
in {
inherit (cfg) systemd services users;
shb = { inherit (cfg.shb) backup nginx; };
};
in
{
testArrNoOptions = {
expected = {
systemd.services.jackett = {};
shb.backup = {};
shb.nginx.autheliaProtect = [];
users.users = {};
services.bazarr = {};
services.jackett = {};
services.lidarr = {};
services.radarr = {};
services.readarr = {};
services.sonarr = {};
};
expr = testConfig {};
};
}

35
test/modules/davfs.nix Normal file
View file

@ -0,0 +1,35 @@
{ pkgs, lib, ... }:
let
anyOpt = default: lib.mkOption {
type = lib.types.anything;
inherit default;
};
testConfig = m:
let
cfg = (lib.evalModules {
specialArgs = { inherit pkgs; };
modules = [
{
options = {
systemd = anyOpt {};
services = anyOpt {};
};
}
../../modules/davfs.nix
m
];
}).config;
in {
inherit (cfg) systemd services;
};
in
{
testDavfsNoOptions = {
expected = {
services.davfs2.enable = false;
systemd.mounts = [];
};
expr = testConfig {};
};
}

View file

@ -1,4 +1,4 @@
{ lib }:
{ lib, ... }:
let
anyOpt = default: lib.mkOption {
type = lib.types.anything;
@ -274,10 +274,11 @@ in
port = 1234;
authentication = ''
#type database DBuser origin-address auth-method
local all all peer
# ipv4
host all all 127.0.0.1/32 trust
host all all 127.0.0.1/32 trust
# ipv6
host all all ::1/128 trust
host all all ::1/128 trust
'';
};
systemd.services.postgresql.postStart = "";