summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
authorgithub-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>2020-12-11 00:40:21 +0000
committerGitHub <noreply@github.com>2020-12-11 00:40:21 +0000
commit614876ef33547c10a626f86127625941c9afe44a (patch)
tree9d8cc7fd456309539b28b57c53da861e0fca8c3c /nixos
parent79e586aa98a964a117ea62e2be7ca6aaccf6aece (diff)
parentf1f9a55fb4b1d5adeebfff6c5ec58ce445bf5e84 (diff)
downloadnixpkgs-614876ef33547c10a626f86127625941c9afe44a.tar
nixpkgs-614876ef33547c10a626f86127625941c9afe44a.tar.gz
nixpkgs-614876ef33547c10a626f86127625941c9afe44a.tar.bz2
nixpkgs-614876ef33547c10a626f86127625941c9afe44a.tar.lz
nixpkgs-614876ef33547c10a626f86127625941c9afe44a.tar.xz
nixpkgs-614876ef33547c10a626f86127625941c9afe44a.tar.zst
nixpkgs-614876ef33547c10a626f86127625941c9afe44a.zip
Merge master into staging-next
Diffstat (limited to 'nixos')
-rw-r--r--nixos/modules/services/monitoring/prometheus/exporters.nix1
-rw-r--r--nixos/modules/services/monitoring/prometheus/exporters/py-air-control.nix62
-rw-r--r--nixos/modules/services/web-servers/nginx/default.nix23
-rw-r--r--nixos/tests/prometheus-exporters.nix15
4 files changed, 95 insertions, 6 deletions
diff --git a/nixos/modules/services/monitoring/prometheus/exporters.nix b/nixos/modules/services/monitoring/prometheus/exporters.nix
index 995afca96ff..1f8c5aeded1 100644
--- a/nixos/modules/services/monitoring/prometheus/exporters.nix
+++ b/nixos/modules/services/monitoring/prometheus/exporters.nix
@@ -41,6 +41,7 @@ let
     "openvpn"
     "postfix"
     "postgres"
+    "py-air-control"
     "redis"
     "rspamd"
     "rtl_433"
diff --git a/nixos/modules/services/monitoring/prometheus/exporters/py-air-control.nix b/nixos/modules/services/monitoring/prometheus/exporters/py-air-control.nix
new file mode 100644
index 00000000000..d9a627ca2ea
--- /dev/null
+++ b/nixos/modules/services/monitoring/prometheus/exporters/py-air-control.nix
@@ -0,0 +1,62 @@
+{ config, lib, pkgs, options }:
+
+with lib;
+
+let
+  cfg = config.services.prometheus.exporters.py-air-control;
+
+  py-air-control-exporter-env = pkgs.python3.withPackages (pyPkgs: [
+      pyPkgs.py-air-control-exporter
+  ]);
+
+  workingDir = "/var/lib/${cfg.stateDir}";
+
+in
+{
+  port = 9896;
+  extraOpts = {
+    deviceHostname = mkOption {
+      type = types.str;
+      example = "192.168.1.123";
+      description = ''
+        The hostname of the air purification device from which to scrape the metrics.
+      '';
+    };
+    protocol = mkOption {
+      type = types.str;
+      default = "http";
+      description = ''
+        The protocol to use when communicating with the air purification device.
+        Available: [http, coap, plain_coap]
+      '';
+    };
+    stateDir = mkOption {
+      type = types.str;
+      default = "prometheus-py-air-control-exporter";
+      description = ''
+        Directory below <literal>/var/lib</literal> to store runtime data.
+        This directory will be created automatically using systemd's StateDirectory mechanism.
+      '';
+    };
+  };
+  serviceOpts = {
+    serviceConfig = {
+      DynamicUser = false;
+      StateDirectory = cfg.stateDir;
+      WorkingDirectory = workingDir;
+      ExecStart = ''
+        ${py-air-control-exporter-env}/bin/python -c \
+          "from py_air_control_exporter import app; app.create_app().run( \
+              debug=False, \
+              port=${toString cfg.port}, \
+              host='${cfg.listenAddress}', \
+          )"
+      '';
+      Environment = [
+        "PY_AIR_CONTROL_HOST=${cfg.deviceHostname}"
+        "PY_AIR_CONTROL_PROTOCOL=${cfg.protocol}"
+        "HOME=${workingDir}"
+      ];
+    };
+  };
+}
diff --git a/nixos/modules/services/web-servers/nginx/default.nix b/nixos/modules/services/web-servers/nginx/default.nix
index e9630d379f3..62671e9d748 100644
--- a/nixos/modules/services/web-servers/nginx/default.nix
+++ b/nixos/modules/services/web-servers/nginx/default.nix
@@ -390,13 +390,24 @@ in
       };
 
       config = mkOption {
+        type = types.str;
         default = "";
-        description = "
-          Verbatim nginx.conf configuration.
-          This is mutually exclusive with the structured configuration
-          via virtualHosts and the recommendedXyzSettings configuration
-          options. See appendConfig for appending to the generated http block.
-        ";
+        description = ''
+          Verbatim <filename>nginx.conf</filename> configuration.
+          This is mutually exclusive to any other config option for
+          <filename>nginx.conf</filename> except for
+          <itemizedlist>
+          <listitem><para><xref linkend="opt-services.nginx.appendConfig" />
+          </para></listitem>
+          <listitem><para><xref linkend="opt-services.nginx.httpConfig" />
+          </para></listitem>
+          <listitem><para><xref linkend="opt-services.nginx.logError" />
+          </para></listitem>
+          </itemizedlist>
+
+          If additional verbatim config in addition to other options is needed,
+          <xref linkend="opt-services.nginx.appendConfig" /> should be used instead.
+        '';
       };
 
       appendConfig = mkOption {
diff --git a/nixos/tests/prometheus-exporters.nix b/nixos/tests/prometheus-exporters.nix
index 0b9957404f3..3eb4341e39c 100644
--- a/nixos/tests/prometheus-exporters.nix
+++ b/nixos/tests/prometheus-exporters.nix
@@ -530,6 +530,21 @@ let
       '';
     };
 
+    py-air-control = {
+      nodeName = "py_air_control";
+      exporterConfig = {
+        enable = true;
+        deviceHostname = "127.0.0.1";
+      };
+      exporterTest = ''
+        wait_for_unit("prometheus-py-air-control-exporter.service")
+        wait_for_open_port(9896)
+        succeed(
+            "curl -sSf http://localhost:9896/metrics | grep -q 'py_air_control_sampling_error_total'"
+        )
+      '';
+    };
+
     redis = {
       exporterConfig = {
         enable = true;