|
1 |
| -{ config, lib, pkgs, ... }: |
| 1 | +{ config, lib, pkgs, utils, ... }: |
2 | 2 | let
|
3 | 3 | inherit (lib) maintainers;
|
4 | 4 | inherit (lib.meta) getExe;
|
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
|
|
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 |
| 42 | + containing the attribute `_secret`. This attribute should be a string |
| 43 | + or structured JSON with `quote = false;`, pointing to a file that |
| 44 | + contains the value the option should be set to. |
39 | 45 | '';
|
40 | 46 | default = { };
|
41 | 47 | type = submodule {
|
|
130 | 136 | Collector settings to be rendered into the collector configuration file.
|
131 | 137 |
|
132 | 138 | See <https://github.com/AnalogJ/scrutiny/blob/master/example.collector.yaml>.
|
| 139 | +
|
| 140 | + Options containing secret data should be set to an attribute set |
| 141 | + containing the attribute `_secret`. This attribute should be a string |
| 142 | + or structured JSON with `quote = false;`, pointing to a file that |
| 143 | + contains the value the option should be set to. |
133 | 144 | '';
|
134 | 145 | default = { };
|
135 | 146 | type = submodule {
|
|
177 | 188 | SCRUTINY_WEB_DATABASE_LOCATION = "/var/lib/scrutiny/scrutiny.db";
|
178 | 189 | SCRUTINY_WEB_SRC_FRONTEND_PATH = "${cfg.package}/share/scrutiny";
|
179 | 190 | };
|
| 191 | + preStart = '' |
| 192 | + ${genJqSecretsReplacementSnippet cfg.settings "/run/scrutiny/config.yaml"} |
| 193 | + ''; |
180 | 194 | postStart = ''
|
181 | 195 | for i in $(seq 300); do
|
182 | 196 | if "${lib.getExe pkgs.curl}" --fail --silent --head "http://${cfg.settings.web.listen.host}:${toString cfg.settings.web.listen.port}" >/dev/null; then
|
|
191 | 205 | '';
|
192 | 206 | serviceConfig = {
|
193 | 207 | DynamicUser = true;
|
194 |
| - ExecStart = "${getExe cfg.package} start --config ${settingsFormat.generate "scrutiny.yaml" cfg.settings}"; |
| 208 | + ExecStart = "${getExe cfg.package} start --config /run/scrutiny/config.yaml"; |
195 | 209 | Restart = "always";
|
| 210 | + RuntimeDirectory = "scrutiny"; |
| 211 | + RuntimeDirectoryMode = "0700"; |
196 | 212 | StateDirectory = "scrutiny";
|
197 | 213 | StateDirectoryMode = "0750";
|
198 | 214 | };
|
|
216 | 232 | COLLECTOR_VERSION = "1";
|
217 | 233 | COLLECTOR_API_ENDPOINT = cfg.collector.settings.api.endpoint;
|
218 | 234 | };
|
| 235 | + preStart = '' |
| 236 | + ${genJqSecretsReplacementSnippet cfg.collector.settings "/run/scrutiny-collector/config.yaml"} |
| 237 | + ''; |
219 | 238 | serviceConfig = {
|
220 | 239 | Type = "oneshot";
|
221 |
| - ExecStart = "${getExe cfg.collector.package} run --config ${settingsFormat.generate "scrutiny-collector.yaml" cfg.collector.settings}"; |
| 240 | + ExecStart = "${getExe cfg.collector.package} run --config /run/scrutiny-collector/config.yaml"; |
| 241 | + RuntimeDirectory = "scrutiny-collector"; |
| 242 | + RuntimeDirectoryMode = "0700"; |
222 | 243 | };
|
223 | 244 | startAt = cfg.collector.schedule;
|
224 | 245 | };
|
|
0 commit comments