Something went wrong. Try again.
lol
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245{ config, lib, pkgs, ...}:
let cfg = config.services.tdarr; enabledNodes = lib.filterAttrs (_: nodeCfg: nodeCfg.enable) cfg.nodes; nodesEnabled = cfg.enable || (enabledNodes != { }); serverEnabled = cfg.enable || cfg.server.enable; nodeConfigFiles = lib.mapAttrs ( nodeId: nodeCfg: pkgs.writeText "Tdarr_Node_Config_${nodeId}.json" ( builtins.toJSON { pathTranslators = nodeCfg.pathTranslators; } ) ) enabledNodes;in{ options.services.tdarr.nodes = lib.mkOption { default = { }; description = "Attribute set of Tdarr processing nodes to run on this machine."; type = lib.types.attrsOf ( lib.types.submodule ( { name, ... }: { options = { enable = lib.mkEnableOption "this Tdarr node" // { default = true; };
package = lib.mkOption { type = lib.types.package; default = cfg.package.node; defaultText = lib.literalExpression "config.services.tdarr.package.node"; description = "Package to use for this Tdarr node."; };
name = lib.mkOption { type = lib.types.str; default = "${config.networking.hostName}-${name}"; defaultText = lib.literalExpression ''"''${config.networking.hostName}-''${name}"''; description = "Display name for this node in the Tdarr web UI."; };
dataDir = lib.mkOption { type = lib.types.path; default = "${cfg.dataDir}/nodes/${name}"; defaultText = lib.literalExpression ''"''${config.services.tdarr.dataDir}/nodes/''${name}"''; description = "Data directory for this node."; };
serverURL = lib.mkOption { type = lib.types.str; default = "http://127.0.0.1:${toString cfg.server.serverPort}"; defaultText = lib.literalExpression ''"http://127.0.0.1:''${toString config.services.tdarr.server.serverPort}"''; description = '' Full URL of the Tdarr server this node connects to.
This is the recommended way to specify the server location. When running a local server, the default value is correct. ''; };
type = lib.mkOption { type = lib.types.enum [ "mapped" "unmapped" ]; default = "mapped"; description = '' Node type.
- `mapped`: Node accesses files directly from the library paths. - `unmapped`: Node receives files over the network API. ''; };
priority = lib.mkOption { type = lib.types.int; default = -1; description = '' Node priority for job assignment.
`-1` means no priority. `0` is the highest priority, `1` is next, and so on. ''; };
pollInterval = lib.mkOption { type = lib.types.ints.unsigned; default = 2000; description = "How often the node checks the server for work, in milliseconds."; };
startPaused = lib.mkOption { type = lib.types.bool; default = false; description = "Whether the node starts in a paused state."; };
maxLogSizeMB = lib.mkOption { type = lib.types.ints.unsigned; default = 10; description = "Maximum log file size in megabytes."; };
cronPluginUpdate = lib.mkOption { type = lib.types.str; default = ""; description = "Cron expression for automatic plugin updates. Empty string disables."; };
pathTranslators = lib.mkOption { type = lib.types.listOf ( lib.types.submodule { options = { server = lib.mkOption { type = lib.types.str; description = "Server-side path for path translation."; }; node = lib.mkOption { type = lib.types.str; description = "Node-side path for path translation."; }; }; } ); default = [ ]; description = '' Path translations between server and node for cross-platform or cross-mount-point file access. ''; example = lib.literalExpression '' [ { server = "/media"; node = "/mnt/media"; } { server = "/cache"; node = "/mnt/cache"; } ] ''; };
workers = { transcodeGPU = lib.mkOption { type = lib.types.ints.unsigned; default = 0; description = "Number of GPU transcode workers. Can be overridden in the web UI."; }; transcodeCPU = lib.mkOption { type = lib.types.ints.unsigned; default = 2; description = "Number of CPU transcode workers. Can be overridden in the web UI."; }; healthcheckGPU = lib.mkOption { type = lib.types.ints.unsigned; default = 0; description = "Number of GPU healthcheck workers. Can be overridden in the web UI."; }; healthcheckCPU = lib.mkOption { type = lib.types.ints.unsigned; default = 1; description = "Number of CPU healthcheck workers. Can be overridden in the web UI."; }; };
environmentFile = lib.mkOption { type = lib.types.nullOr lib.types.path; default = null; description = '' File containing environment variable overrides for this node, in the format accepted by systemd's `EnvironmentFile`.
Useful for passing secrets like `apiKey` without putting them in the Nix store. ''; example = "/run/secrets/tdarr-node-env"; }; }; } ) ); };
config = lib.mkIf nodesEnabled { systemd.tmpfiles.rules = lib.concatMap (nodeId: [ "d ${cfg.dataDir}/nodes/${nodeId} 0750 ${cfg.user} ${cfg.group} -" "d ${cfg.dataDir}/nodes/${nodeId}/configs 0750 ${cfg.user} ${cfg.group} -" "d ${cfg.dataDir}/nodes/${nodeId}/logs 0750 ${cfg.user} ${cfg.group} -" "L+ ${cfg.dataDir}/nodes/${nodeId}/configs/Tdarr_Node_Config.json - - - - ${nodeConfigFiles.${nodeId}}" ]) (builtins.attrNames enabledNodes);
systemd.services = lib.mapAttrs' ( nodeId: nodeCfg: lib.nameValuePair "tdarr-node-${nodeId}" { description = "Tdarr Node - ${nodeCfg.name}"; after = [ "network.target" ] ++ lib.optionals serverEnabled [ "tdarr-server.service" ]; wants = lib.optionals serverEnabled [ "tdarr-server.service" ]; wantedBy = [ "multi-user.target" ]; environment = { nodeName = nodeCfg.name; serverURL = nodeCfg.serverURL; nodeType = nodeCfg.type; priority = toString nodeCfg.priority; cronPluginUpdate = nodeCfg.cronPluginUpdate; maxLogSizeMB = toString nodeCfg.maxLogSizeMB; pollInterval = toString nodeCfg.pollInterval; startPaused = lib.boolToString nodeCfg.startPaused; transcodegpuWorkers = toString nodeCfg.workers.transcodeGPU; transcodecpuWorkers = toString nodeCfg.workers.transcodeCPU; healthcheckgpuWorkers = toString nodeCfg.workers.healthcheckGPU; healthcheckcpuWorkers = toString nodeCfg.workers.healthcheckCPU; rootDataPath = toString nodeCfg.dataDir; }; serviceConfig = { Type = "simple"; User = cfg.user; Group = cfg.group; ExecStart = lib.getExe nodeCfg.package; Restart = "on-failure"; RestartSec = 5; WorkingDirectory = toString nodeCfg.dataDir;
# Hardening NoNewPrivileges = true; PrivateTmp = true; ProtectSystem = "strict"; ProtectHome = true; StateDirectory = lib.mkIf (lib.hasPrefix "/var/lib/" (toString nodeCfg.dataDir)) ( let rel = lib.removePrefix "/var/lib/" (toString nodeCfg.dataDir); in "${rel} ${rel}/configs ${rel}/logs" ); StateDirectoryMode = lib.mkIf (lib.hasPrefix "/var/lib/" (toString nodeCfg.dataDir)) "0750"; ReadWritePaths = lib.optionals (!lib.hasPrefix "/var/lib/" (toString nodeCfg.dataDir)) [ (toString nodeCfg.dataDir) ]; } // lib.optionalAttrs (nodeCfg.environmentFile != null) { EnvironmentFile = nodeCfg.environmentFile; }; } ) enabledNodes; };}