1{
2 config,
3 lib,
4 pkgs,
5 options,
6 ...
7}:
8
9let
10 cfg = config.services.prometheus.exporters.script;
11 inherit (lib)
12 mkOption
13 types
14 literalExpression
15 concatStringsSep
16 ;
17 settingsFormat = pkgs.formats.yaml { };
18 configFile = settingsFormat.generate "script-exporter.yaml" cfg.settings;
19in
20{
21 port = 9172;
22 extraOpts = {
23 settings = mkOption {
24 type = (pkgs.formats.yaml { }).type;
25 default = { };
26 example = literalExpression ''
27 {
28 scripts = [
29 { name = "sleep"; command = [ "sleep" ]; args = [ "5" ]; }
30 ];
31 }
32 '';
33 description = ''
34 Free-form configuration for script_exporter, expressed as a Nix attrset and rendered to YAML.
35
36 **Migration note:**
37 The previous format using `script = "sleep 5"` is no longer supported. You must use `command` (list) and `args` (list), e.g. `{ command = [ "sleep" ]; args = [ "5" ]; }`.
38
39 See the official documentation for all available options: <https://github.com/ricoberger/script_exporter#configuration-file>
40 '';
41 };
42 };
43 serviceOpts = {
44 serviceConfig = {
45 ExecStart = ''
46 ${pkgs.prometheus-script-exporter}/bin/script_exporter \
47 --web.listen-address ${cfg.listenAddress}:${toString cfg.port} \
48 --config.files ${configFile} \
49 ${concatStringsSep " \\\n " cfg.extraFlags}
50 '';
51 NoNewPrivileges = true;
52 ProtectHome = true;
53 ProtectSystem = "strict";
54 ProtectKernelTunables = true;
55 ProtectKernelModules = true;
56 ProtectControlGroups = true;
57 };
58 };
59}