Skip to content

Commit 7d42f92

Browse files
committedOct 20, 2024
nixos/scrutiny: use genJqSecretsReplacementSnippet
1 parent 67f803d commit 7d42f92

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed
 

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

+20-3
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ let
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
11-
settingsFormat = pkgs.formats.yaml { };
12+
settingsFormat = pkgs.formats.json { };
1213
in
1314
{
1415
options = {
@@ -36,6 +37,8 @@ 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 containing the attribute `_secret` - a string pointing to a file containing the value the option should be set to.
3942
'';
4043
default = { };
4144
type = submodule {
@@ -177,6 +180,11 @@ in
177180
SCRUTINY_WEB_DATABASE_LOCATION = "/var/lib/scrutiny/scrutiny.db";
178181
SCRUTINY_WEB_SRC_FRONTEND_PATH = "${cfg.package}/share/scrutiny";
179182
};
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+
'';
180188
postStart = ''
181189
for i in $(seq 300); do
182190
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 +199,10 @@ in
191199
'';
192200
serviceConfig = {
193201
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";
195203
Restart = "always";
204+
ConfigurationDirectory = "scrutiny";
205+
ConfigurationDirectoryMode = "0750";
196206
StateDirectory = "scrutiny";
197207
StateDirectoryMode = "0750";
198208
};
@@ -216,9 +226,16 @@ in
216226
COLLECTOR_VERSION = "1";
217227
COLLECTOR_API_ENDPOINT = cfg.collector.settings.api.endpoint;
218228
};
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+
'';
219234
serviceConfig = {
220235
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";
222239
};
223240
startAt = cfg.collector.schedule;
224241
};

0 commit comments

Comments
 (0)
Failed to load comments.