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 let
importFiles = files: importFiles = files:
map (m: import m { map (m: import m {
inherit pkgs;
inherit (pkgs) lib; inherit (pkgs) lib;
}) files; }) files;
mergeTests = pkgs.lib.lists.foldl pkgs.lib.trivial.mergeAttrs {}; mergeTests = pkgs.lib.lists.foldl pkgs.lib.trivial.mergeAttrs {};
in mergeTests (importFiles [ in mergeTests (importFiles [
./test/modules/arr.nix
./test/modules/davfs.nix
./test/modules/postgresql.nix ./test/modules/postgresql.nix
]); ]);
}; };

View file

@ -24,6 +24,7 @@ let
settingsFormat = pkgs.formats.json {}; settingsFormat = pkgs.formats.json {};
moreOptions = { moreOptions = {
settings = lib.mkOption { settings = lib.mkOption {
default = {};
type = lib.types.submodule { type = lib.types.submodule {
freeformType = apps.jackett.settingsFormat.type; freeformType = apps.jackett.settingsFormat.type;
options = { options = {
@ -66,6 +67,7 @@ let
appOption = name: c: lib.nameValuePair name (lib.mkOption { appOption = name: c: lib.nameValuePair name (lib.mkOption {
description = "Configuration for ${name}"; description = "Configuration for ${name}";
default = {};
type = lib.types.submodule { type = lib.types.submodule {
options = { options = {
enable = lib.mkEnableOption "selfhostblocks.${name}"; enable = lib.mkEnableOption "selfhostblocks.${name}";
@ -95,7 +97,8 @@ let
}; };
oidcEndpoint = lib.mkOption { oidcEndpoint = lib.mkOption {
type = lib.types.str; type = lib.types.nullOr lib.types.str;
default = null;
description = "OIDC endpoint for SSO"; description = "OIDC endpoint for SSO";
example = "https://authelia.example.com"; example = "https://authelia.example.com";
}; };
@ -125,7 +128,7 @@ in
enable = true; enable = true;
dataDir = "/var/lib/radarr"; dataDir = "/var/lib/radarr";
}; };
users.users.radarr = { users.users.radarr = lib.mkIf cfg.radarr.enable {
extraGroups = [ "media" ]; extraGroups = [ "media" ];
}; };
@ -134,7 +137,7 @@ in
enable = true; enable = true;
dataDir = "/var/lib/sonarr"; dataDir = "/var/lib/sonarr";
}; };
users.users.sonarr = { users.users.sonarr = lib.mkIf cfg.sonarr.enable {
extraGroups = [ "media" ]; extraGroups = [ "media" ];
}; };
@ -142,13 +145,16 @@ in
enable = true; enable = true;
listenPort = cfg.bazarr.port; listenPort = cfg.bazarr.port;
}; };
users.users.bazarr = lib.mkIf cfg.bazarr.enable {
extraGroups = [ "media" ];
};
# Listens on port 8787 # Listens on port 8787
services.readarr = lib.mkIf cfg.readarr.enable { services.readarr = lib.mkIf cfg.readarr.enable {
enable = true; enable = true;
dataDir = "/var/lib/readarr"; dataDir = "/var/lib/readarr";
}; };
users.users.readarr = { users.users.readarr = lib.mkIf cfg.readarr.enable {
extraGroups = [ "media" ]; extraGroups = [ "media" ];
}; };
@ -157,7 +163,7 @@ in
enable = true; enable = true;
dataDir = "/var/lib/lidarr"; dataDir = "/var/lib/lidarr";
}; };
users.users.lidarr = { users.users.lidarr = lib.mkIf cfg.lidarr.enable {
extraGroups = [ "media" ]; extraGroups = [ "media" ];
}; };
@ -166,12 +172,12 @@ in
enable = true; enable = true;
dataDir = "/var/lib/jackett"; dataDir = "/var/lib/jackett";
}; };
shb.arr.jackett.settings = { shb.arr.jackett.settings = lib.mkIf cfg.jackett.enable {
Port = config.shb.arr.jackett.port; Port = config.shb.arr.jackett.port;
AllowExternal = "false"; AllowExternal = "false";
UpdateDisabled = "true"; UpdateDisabled = "true";
}; };
users.users.jackett = { users.users.jackett = lib.mkIf cfg.jackett.enable {
extraGroups = [ "media" ]; extraGroups = [ "media" ];
}; };
systemd.services.jackett.preStart = systemd.services.jackett.preStart =
@ -184,14 +190,16 @@ in
OmdbApiKey = "%OMDBAPIKEY%"; OmdbApiKey = "%OMDBAPIKEY%";
}; };
templatedSettings = (removeAttrs s [ "APIKeyFile" "OmdbApiKeyFile" ]) // templatedfileSettings; 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)) { lib.optionalAttrs (!(isNull s.APIKeyFile)) {
"%APIKEY%" = "$(cat ${s.APIKeyFile})"; "%APIKEY%" = "$(cat ${s.APIKeyFile})";
} // lib.optionalAttrs (!(isNull s.OmdbApiKeyFile)) { } // lib.optionalAttrs (!(isNull s.OmdbApiKeyFile)) {
"%OMDBAPIKEY%" = "$(cat ${s.OmdbApiKeyFile})"; "%OMDBAPIKEY%" = "$(cat ${s.OmdbApiKeyFile})";
} }
); );
in
lib.mkIf cfg.jackett.enable t;
shb.nginx.autheliaProtect = shb.nginx.autheliaProtect =
let let
@ -199,7 +207,7 @@ in
let let
c = cfg.${name}; c = cfg.${name};
in in
{ lib.mkIf (c.oidcEndpoint != null) {
inherit (c) subdomain domain oidcEndpoint; inherit (c) subdomain domain oidcEndpoint;
upstream = "http://127.0.0.1:${toString c.port}"; upstream = "http://127.0.0.1:${toString c.port}";
autheliaRules = [ autheliaRules = [
@ -235,7 +243,7 @@ in
in in
lib.mkMerge (lib.mapAttrsToList backupConfig apps); 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}) [ 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} - -" "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 let
anyOpt = default: lib.mkOption { anyOpt = default: lib.mkOption {
type = lib.types.anything; type = lib.types.anything;
@ -274,6 +274,7 @@ in
port = 1234; port = 1234;
authentication = '' authentication = ''
#type database DBuser origin-address auth-method #type database DBuser origin-address auth-method
local all all peer
# ipv4 # ipv4
host all all 127.0.0.1/32 trust host all all 127.0.0.1/32 trust
# ipv6 # ipv6