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