nixos/peering-manager: use settingsFormat

Yureka d490800f 2287c3e6

+64 -33
+64 -33
nixos/modules/services/web-apps/peering-manager.nix
··· 2 3 let 4 cfg = config.services.peering-manager; 5 - configFile = pkgs.writeTextFile { 6 - name = "configuration.py"; 7 - text = '' 8 - ALLOWED_HOSTS = ['*'] 9 - DATABASE = { 10 - 'NAME': 'peering-manager', 11 - 'USER': 'peering-manager', 12 - 'HOST': '/run/postgresql', 13 - } 14 15 - # Redis database settings. Redis is used for caching and for queuing background tasks such as webhook events. A separate 16 - # configuration exists for each. Full connection details are required in both sections, and it is strongly recommended 17 - # to use two separate database IDs. 18 - REDIS = { 19 - 'tasks': { 20 - 'UNIX_SOCKET_PATH': '${config.services.redis.servers.peering-manager.unixSocket}', 21 - 'DATABASE': 0, 22 - }, 23 - 'caching': { 24 - 'UNIX_SOCKET_PATH': '${config.services.redis.servers.peering-manager.unixSocket}', 25 - 'DATABASE': 1, 26 - } 27 - } 28 29 - with open("${cfg.secretKeyFile}", "r") as file: 30 - SECRET_KEY = file.readline() 31 - '' + lib.optionalString (cfg.peeringdbApiKeyFile != null) '' 32 - with open("${cfg.peeringdbApiKeyFile}", "r") as file: 33 - PEERINGDB_API_KEY = file.readline() 34 - '' + '' 35 - 36 - ${cfg.extraConfig} 37 - ''; 38 - }; 39 pkg = (pkgs.peering-manager.overrideAttrs (old: { 40 postInstall = '' 41 ln -s ${configFile} $out/opt/peering-manager/peering_manager/configuration.py ··· 106 ''; 107 }; 108 109 extraConfig = mkOption { 110 type = types.lines; 111 default = ""; ··· 135 }; 136 137 config = lib.mkIf cfg.enable { 138 - services.peering-manager.plugins = lib.mkIf cfg.enableLdap (ps: [ ps.django-auth-ldap ]); 139 140 system.build.peeringManagerPkg = pkg; 141
··· 2 3 let 4 cfg = config.services.peering-manager; 5 6 + pythonFmt = pkgs.formats.pythonVars {}; 7 + settingsFile = pythonFmt.generate "peering-manager-settings.py" cfg.settings; 8 + extraConfigFile = pkgs.writeTextFile { 9 + name = "peering-manager-extraConfig.py"; 10 + text = cfg.extraConfig; 11 + }; 12 + configFile = pkgs.concatText "configuration.py" [ settingsFile extraConfigFile ]; 13 14 pkg = (pkgs.peering-manager.overrideAttrs (old: { 15 postInstall = '' 16 ln -s ${configFile} $out/opt/peering-manager/peering_manager/configuration.py ··· 81 ''; 82 }; 83 84 + settings = lib.mkOption { 85 + description = lib.mdDoc '' 86 + Configuration options to set in `configuration.py`. 87 + See the [documentation](https://peering-manager.readthedocs.io/en/stable/configuration/optional-settings/) for more possible options. 88 + ''; 89 + 90 + default = { }; 91 + 92 + type = lib.types.submodule { 93 + freeformType = pythonFmt.type; 94 + 95 + options = { 96 + ALLOWED_HOSTS = lib.mkOption { 97 + type = with lib.types; listOf str; 98 + default = ["*"]; 99 + description = lib.mdDoc '' 100 + A list of valid fully-qualified domain names (FQDNs) and/or IP 101 + addresses that can be used to reach the peering manager service. 102 + ''; 103 + }; 104 + }; 105 + }; 106 + }; 107 + 108 extraConfig = mkOption { 109 type = types.lines; 110 default = ""; ··· 134 }; 135 136 config = lib.mkIf cfg.enable { 137 + services.peering-manager = { 138 + settings = { 139 + DATABASE = { 140 + NAME = "peering-manager"; 141 + USER = "peering-manager"; 142 + HOST = "/run/postgresql"; 143 + }; 144 + 145 + # Redis database settings. Redis is used for caching and for queuing background tasks such as webhook events. A separate 146 + # configuration exists for each. Full connection details are required in both sections, and it is strongly recommended 147 + # to use two separate database IDs. 148 + REDIS = { 149 + tasks = { 150 + UNIX_SOCKET_PATH = config.services.redis.servers.peering-manager.unixSocket; 151 + DATABASE = 0; 152 + }; 153 + caching = { 154 + UNIX_SOCKET_PATH = config.services.redis.servers.peering-manager.unixSocket; 155 + DATABASE = 1; 156 + }; 157 + }; 158 + }; 159 + 160 + extraConfig = '' 161 + with open("${cfg.secretKeyFile}", "r") as file: 162 + SECRET_KEY = file.readline() 163 + '' + lib.optionalString (cfg.peeringdbApiKeyFile != null) '' 164 + with open("${cfg.peeringdbApiKeyFile}", "r") as file: 165 + PEERINGDB_API_KEY = file.readline() 166 + ''; 167 + 168 + plugins = lib.mkIf cfg.enableLdap (ps: [ ps.django-auth-ldap ]); 169 + }; 170 171 system.build.peeringManagerPkg = pkg; 172