at 25.11-pre 2.8 kB view raw
1{ lib, pkgs }: 2{ 3 mkServarrSettingsOptions = 4 name: port: 5 lib.mkOption { 6 type = lib.types.submodule { 7 freeformType = (pkgs.formats.ini { }).type; 8 options = { 9 update = { 10 mechanism = lib.mkOption { 11 type = 12 with lib.types; 13 nullOr (enum [ 14 "external" 15 "builtIn" 16 "script" 17 ]); 18 description = "which update mechanism to use"; 19 default = "external"; 20 }; 21 automatically = lib.mkOption { 22 type = lib.types.bool; 23 description = "Automatically download and install updates."; 24 default = false; 25 }; 26 }; 27 server = { 28 port = lib.mkOption { 29 type = lib.types.int; 30 description = "Port Number"; 31 default = port; 32 }; 33 }; 34 log = { 35 analyticsEnabled = lib.mkOption { 36 type = lib.types.bool; 37 description = "Send Anonymous Usage Data"; 38 default = false; 39 }; 40 }; 41 }; 42 }; 43 example = lib.options.literalExpression '' 44 { 45 update.mechanism = "internal"; 46 server = { 47 urlbase = "localhost"; 48 port = ${toString port}; 49 bindaddress = "*"; 50 }; 51 } 52 ''; 53 default = { }; 54 description = '' 55 Attribute set of arbitrary config options. 56 Please consult the documentation at the [wiki](https://wiki.servarr.com/useful-tools#using-environment-variables-for-config). 57 58 WARNING: this configuration is stored in the world-readable Nix store! 59 For secrets use [](#opt-services.${name}.environmentFiles). 60 ''; 61 }; 62 63 mkServarrEnvironmentFiles = 64 name: 65 lib.mkOption { 66 type = lib.types.listOf lib.types.path; 67 default = [ ]; 68 description = '' 69 Environment file to pass secret configuration values. 70 Each line must follow the `${lib.toUpper name}__SECTION__KEY=value` pattern. 71 Please consult the documentation at the [wiki](https://wiki.servarr.com/useful-tools#using-environment-variables-for-config). 72 ''; 73 }; 74 75 mkServarrSettingsEnvVars = 76 name: settings: 77 lib.pipe settings [ 78 (lib.mapAttrsRecursive ( 79 path: value: 80 lib.optionalAttrs (value != null) { 81 name = lib.toUpper "${name}__${lib.concatStringsSep "__" path}"; 82 value = toString (if lib.isBool value then lib.boolToString value else value); 83 } 84 )) 85 (lib.collect (x: lib.isString x.name or false && lib.isString x.value or false)) 86 lib.listToAttrs 87 ]; 88}