Skip to content

Commit eca4c6e

Browse files
committedMar 20, 2025
nixos/scrutiny: use genJqSecretsReplacementSnippet
1 parent 29c7ade commit eca4c6e

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed
 

‎nixos/modules/services/monitoring/scrutiny.nix

+24-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
{ config, lib, pkgs, ... }:
1+
{ config, lib, pkgs, utils, ... }:
22
let
33
inherit (lib) maintainers;
44
inherit (lib.meta) getExe;
55
inherit (lib.modules) mkIf mkMerge;
66
inherit (lib.options) literalExpression mkEnableOption mkOption mkPackageOption;
77
inherit (lib.types) bool enum nullOr port str submodule;
8+
inherit (utils) genJqSecretsReplacementSnippet;
89

910
cfg = config.services.scrutiny;
1011
# Define the settings format used for this program
@@ -36,6 +37,11 @@ in
3637
Scrutiny settings to be rendered into the configuration file.
3738
3839
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.
3945
'';
4046
default = { };
4147
type = submodule {
@@ -130,6 +136,11 @@ in
130136
Collector settings to be rendered into the collector configuration file.
131137
132138
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.
133144
'';
134145
default = { };
135146
type = submodule {
@@ -177,6 +188,9 @@ in
177188
SCRUTINY_WEB_DATABASE_LOCATION = "/var/lib/scrutiny/scrutiny.db";
178189
SCRUTINY_WEB_SRC_FRONTEND_PATH = "${cfg.package}/share/scrutiny";
179190
};
191+
preStart = ''
192+
${genJqSecretsReplacementSnippet cfg.settings "/run/scrutiny/config.yaml"}
193+
'';
180194
postStart = ''
181195
for i in $(seq 300); do
182196
if "${lib.getExe pkgs.curl}" --fail --silent --head "http://${cfg.settings.web.listen.host}:${toString cfg.settings.web.listen.port}" >/dev/null; then
@@ -191,8 +205,10 @@ in
191205
'';
192206
serviceConfig = {
193207
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";
195209
Restart = "always";
210+
RuntimeDirectory = "scrutiny";
211+
RuntimeDirectoryMode = "0700";
196212
StateDirectory = "scrutiny";
197213
StateDirectoryMode = "0750";
198214
};
@@ -216,9 +232,14 @@ in
216232
COLLECTOR_VERSION = "1";
217233
COLLECTOR_API_ENDPOINT = cfg.collector.settings.api.endpoint;
218234
};
235+
preStart = ''
236+
${genJqSecretsReplacementSnippet cfg.collector.settings "/run/scrutiny-collector/config.yaml"}
237+
'';
219238
serviceConfig = {
220239
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";
222243
};
223244
startAt = cfg.collector.schedule;
224245
};

0 commit comments

Comments
 (0)
Failed to load comments.