check in time

This commit is contained in:
Chris Kruining 2026-04-02 11:37:34 +02:00
parent 4dfcd5cca8
commit a8a639db6e
No known key found for this signature in database
GPG key ID: EB894A3560CCCAD2
39 changed files with 436 additions and 307 deletions

View file

@ -1,6 +1,5 @@
{
exports,
clanLib,
lib,
...
}: {
@ -11,8 +10,8 @@
categories = ["Service" "Media"];
readme = builtins.readFile ./README.md;
exports = {
inputs = ["persistence"];
out = ["servarr"];
inputs = [];
out = ["servarr" "persistence"];
};
};
@ -24,6 +23,16 @@
in {
options = {
enable = mkEnableOption "Enable configured *arr services";
database = {
host = mkOption {
type = types.str;
};
port = mkOption {
type = types.port;
};
};
services = mkOption {
type = types.attrsOf (types.submodule ({name, ...}: {
options = {
@ -53,6 +62,10 @@
...
}: {
exports = mkExports {
persistence.databases =
settings.services
|> lib.attrNames;
servarr.services =
settings.services
|> lib.attrNames
@ -73,8 +86,6 @@
servarr = import ./lib.nix (args // {inherit settings;});
services = settings.services |> lib.attrNames;
service_count = services |> lib.length;
db = exports |> clanLib.getExport {serviceName = "persistence";};
in {
imports = [
(import ./sabnzbd.nix (args
@ -121,16 +132,6 @@
openFirewall = true;
port = 2000 + service_count + 3;
};
postgresql = {
ensureDatabases = services;
ensureUsers =
services
|> lib.map (service: {
name = service;
ensureDBOwnership = true;
});
};
};
};
};

View file

@ -13,6 +13,8 @@
options,
...
}: {
dependencies = ["postgresql"];
files = {
api_key = {
secret = true;
@ -33,7 +35,10 @@
runtimeInputs = with pkgs; [pwgen];
script = ''
pwgen -s 128 1 > $out/api_key
echo ${lib.toUpper service}__AUTH__APIKEY="$(cat $out/api_key)" > $out/config.env
cat << EOL > $out/config.env
${lib.toUpper service}__AUTH__APIKEY="$(cat $out/api_key)"
${lib.toUpper service}__POSTGRES_PASSWORD="$(cat $in/postgresql/${service}_password)"
EOL
'';
};
@ -41,7 +46,9 @@
service,
options,
...
}:
}: let
inherit (builtins) toString;
in
{
enable = true;
openFirewall = true;
@ -58,9 +65,10 @@
port = options.port;
};
# Password provided via environment file
postgres = {
host = "localhost";
port = "5432";
host = settings.database.host;
port = toString settings.database.port;
user = service;
maindb = service;
logdb = service;
@ -72,7 +80,7 @@
group = "media";
});
createSystemdService = {
createSystemdService = args @ {
service,
options,
...
@ -81,7 +89,7 @@
terraformConfiguration = self.inputs.terranix.lib.terranixConfiguration {
system = pkgs.stdenv.hostPlatform.system;
modules = [
(createInfra {inherit service options;})
(createInfra args)
];
};
in {
@ -300,7 +308,7 @@
));
};
in {
createModule = services: {...}: {
createModule = services: args: {
config =
services
|> lib.attrsToList
@ -311,10 +319,10 @@ in {
service = name;
options = value // {port = 2000 + i;};
in {
clan.core.vars.generators.${service} = createGenerator {inherit service options;};
services.${service} = createService {inherit service options;};
clan.core.vars.generators.${service} = createGenerator (args // {inherit service options;});
services.${service} = createService (args // {inherit service options;});
systemd.services."${service}-apply-infra" = lib.mkIf settings.enable (createSystemdService {inherit service options;});
systemd.services."${service}-apply-infra" = lib.mkIf settings.enable (createSystemdService (args // {inherit service options;}));
})
|> lib.mkMerge;
};