|
5 | 5 | inherit (lib.modules) mkIf mkMerge;
|
6 | 6 | inherit (lib.options) literalExpression mkEnableOption mkOption mkPackageOption;
|
7 | 7 | inherit (lib.types) bool enum nullOr port str submodule;
|
| 8 | + inherit (utils) genJqSecretsReplacementSnippet; |
8 | 9 |
|
9 | 10 | cfg = config.services.scrutiny;
|
10 | 11 | # Define the settings format used for this program
|
11 |
| - settingsFormat = pkgs.formats.yaml { }; |
| 12 | + settingsFormat = pkgs.formats.json { }; |
12 | 13 | in
|
13 | 14 | {
|
14 | 15 | options = {
|
|
36 | 37 | Scrutiny settings to be rendered into the configuration file.
|
37 | 38 |
|
38 | 39 | See https://github.com/AnalogJ/scrutiny/blob/master/example.scrutiny.yaml.
|
| 40 | +
|
| 41 | + Options containing secret data should be set to an attribute set containing the attribute `_secret` - a string pointing to a file containing the value the option should be set to. |
39 | 42 | '';
|
40 | 43 | default = { };
|
41 | 44 | type = submodule {
|
|
177 | 180 | SCRUTINY_WEB_DATABASE_LOCATION = "/var/lib/scrutiny/scrutiny.db";
|
178 | 181 | SCRUTINY_WEB_SRC_FRONTEND_PATH = "${cfg.package}/share/scrutiny";
|
179 | 182 | };
|
| 183 | + preStart = '' |
| 184 | + ${genJqSecretsReplacementSnippet cfg.settings "/etc/scrutiny/config.json"} |
| 185 | + cat /etc/scrutiny/config.json | ${getExe pkgs.yj} -r > /etc/scrutiny/config.yaml |
| 186 | + rm /etc/scrutiny/config.json |
| 187 | + ''; |
180 | 188 | postStart = ''
|
181 | 189 | for i in $(seq 300); do
|
182 | 190 | if "${lib.getExe pkgs.curl}" --fail --silent --head "http://${cfg.settings.web.listen.host}:${toString cfg.settings.web.listen.port}" >/dev/null; then
|
|
191 | 199 | '';
|
192 | 200 | serviceConfig = {
|
193 | 201 | DynamicUser = true;
|
194 |
| - ExecStart = "${getExe cfg.package} start --config ${settingsFormat.generate "scrutiny.yaml" cfg.settings}"; |
| 202 | + ExecStart = "${getExe cfg.package} start --config /etc/scrutiny/config.yaml"; |
195 | 203 | Restart = "always";
|
| 204 | + ConfigurationDirectory = "scrutiny"; |
| 205 | + ConfigurationDirectoryMode = "0750"; |
196 | 206 | StateDirectory = "scrutiny";
|
197 | 207 | StateDirectoryMode = "0750";
|
198 | 208 | };
|
|
216 | 226 | COLLECTOR_VERSION = "1";
|
217 | 227 | COLLECTOR_API_ENDPOINT = cfg.collector.settings.api.endpoint;
|
218 | 228 | };
|
| 229 | + preStart = '' |
| 230 | + ${genJqSecretsReplacementSnippet cfg.settings "/etc/scrutiny-collector/config.json"} |
| 231 | + cat /etc/scrutiny-collector/config.json | ${getExe pkgs.yj} -r > /etc/scrutiny-collector/config.yaml |
| 232 | + rm /etc/scrutiny-collector/config.json |
| 233 | + ''; |
219 | 234 | serviceConfig = {
|
220 | 235 | Type = "oneshot";
|
221 |
| - ExecStart = "${getExe cfg.collector.package} run --config ${settingsFormat.generate "scrutiny-collector.yaml" cfg.collector.settings}"; |
| 236 | + ExecStart = "${getExe cfg.collector.package} run --config /etc/scrutiny-collector/config.yaml"; |
| 237 | + ConfigurationDirectory = "scrutiny-collector"; |
| 238 | + ConfigurationDirectoryMode = "0750"; |
222 | 239 | };
|
223 | 240 | startAt = cfg.collector.schedule;
|
224 | 241 | };
|
|
0 commit comments