ctucx.git: nixfiles

ctucx' nixfiles

commit 6eed8b655ac1f2bf88e6be7a451a64afbbc3f8b1
parent b244b08a642265d1599bea2e186f9b6e6400ac3c
Author: Leah (ctucx) <leah@ctu.cx>
Date: Thu, 3 Feb 2022 14:27:44 +0100

machines/lollo: notify when service fails
9 files changed, 119 insertions(+), 101 deletions(-)
diff --git a/machines/lollo/configuration.nix b/machines/lollo/configuration.nix
@@ -4,6 +4,7 @@
   imports = [
     ./hardware-configuration.nix
     ../../configurations/common.nix
+    ../../configurations/notify-failure.nix
     ../../configurations/services/prometheus-node-exporter.nix
 
     ./router
diff --git a/machines/lollo/router/dnsmasq.nix b/machines/lollo/router/dnsmasq.nix
@@ -8,113 +8,121 @@ let
   };
 
 in {
-  services.resolved.enable = false;
-  services.dnsmasq = {
-    enable      = true;
-    extraConfig = ''
-      local-service
-      no-resolv
-      no-hosts
-      domain-needed
-      bogus-priv
 
+  systemd.services.dnsmasq.onFailure = [ "notify-failure@%i.service" ];
 
-      server=1.1.1.1
-      server=1.0.0.1
-      server=8.8.8.8
-      server=8.8.4.4
+  services = {
 
+    resolved.enable = false;
 
-      local=/home.ctu.cx/
-      domain=home.ctu.cx
+    dnsmasq = {
+      enable      = true;
+      extraConfig = ''
+        local-service
+        no-resolv
+        no-hosts
+        domain-needed
+        bogus-priv
 
-      auth-ttl=600
-      auth-server=home.ctu.cx, wg-pbb
-      auth-zone=home.ctu.cx,           10.0.0.1/24,   195.39.246.32/28,   2a0f:4ac0:acab::1/64
 
-      host-record=home.ctu.cx,                        195.39.246.41,      2a0f:4ac0:acab::1
-      host-record=lollo.ctu.cx,                       195.39.246.41,      2a0f:4ac0:acab::1
-      host-record=lollo.home.ctu.cx,                  195.39.246.41,      2a0f:4ac0:acab::1
-      host-record=legacy.home.ctu.cx,                 195.39.246.41,      2a0f:4ac0:acab::1
-      host-record=dnsmasq.home.ctu.cx,                195.39.246.41,      2a0f:4ac0:acab::1
-      host-record=music.home.ctu.cx,                  195.39.246.41,      2a0f:4ac0:acab::1
-      host-record=influx.home.ctu.cx,                 195.39.246.41,      2a0f:4ac0:acab::1
-      host-record=wiki.home.ctu.cx,                   195.39.246.41,      2a0f:4ac0:acab::1
-      host-record=pbx.home.ctu.cx,                    195.39.246.46
+        server=1.1.1.1
+        server=1.0.0.1
+        server=8.8.8.8
+        server=8.8.4.4
 
-      address=/fritz.box/192.168.178.1
-      address=/lollo/10.0.0.1
 
+        local=/home.ctu.cx/
+        domain=home.ctu.cx
 
-      enable-ra
-      quiet-ra
+        auth-ttl=600
+        auth-server=home.ctu.cx, wg-pbb
+        auth-zone=home.ctu.cx,           10.0.0.1/24,   195.39.246.32/28,   2a0f:4ac0:acab::1/64
 
-      dhcp-authoritative
-      dhcp-rapid-commit
-      dhcp-sequential-ip
+        host-record=home.ctu.cx,                        195.39.246.41,      2a0f:4ac0:acab::1
+        host-record=lollo.ctu.cx,                       195.39.246.41,      2a0f:4ac0:acab::1
+        host-record=lollo.home.ctu.cx,                  195.39.246.41,      2a0f:4ac0:acab::1
+        host-record=legacy.home.ctu.cx,                 195.39.246.41,      2a0f:4ac0:acab::1
+        host-record=dnsmasq.home.ctu.cx,                195.39.246.41,      2a0f:4ac0:acab::1
+        host-record=music.home.ctu.cx,                  195.39.246.41,      2a0f:4ac0:acab::1
+        host-record=influx.home.ctu.cx,                 195.39.246.41,      2a0f:4ac0:acab::1
+        host-record=wiki.home.ctu.cx,                   195.39.246.41,      2a0f:4ac0:acab::1
+        host-record=pbx.home.ctu.cx,                    195.39.246.46
 
-      dhcp-range=private, 10.0.0.100,          10.0.0.200,                           255.255.255.0,                  48h
-      dhcp-range=public,  195.39.246.34,       static,                               255.255.255.240, 195.39.246.47, 48h
-      dhcp-range=         2a0f:4ac0:acab::100, 2a0f:4ac0:acab::01ff, ra-names,slaac, 64,                             48h
+        address=/fritz.box/192.168.178.1
+        address=/lollo/10.0.0.1
 
-      dhcp-option=option6:information-refresh-time, 6h
-      dhcp-option=option6:dns-server,               [2a0f:4ac0:acab::1]
-      dhcp-option=private, option:router,           10.0.0.1
-      dhcp-option=private, option:dns-server,       10.0.0.1
-      dhcp-option=public,  option:router,           195.39.246.41
-      dhcp-option=public,  option:dns-server,       195.39.246.41
 
-      dhcp-host=f4:06:8d:df:1f:e3,                                          accesspoint,      10.0.0.2
-      dhcp-host=2a0f:4ac0:acab::12a,                                        garmin-vivo-3,    10.0.0.210
+        enable-ra
+        quiet-ra
 
-      dhcp-host=id:04:ea:56:f2:b4:6c,                                       isa-x390,         [2a0f:4ac0:acab::36]
-      dhcp-host=04:ea:56:f2:b4:6c,                                          isa-x390,         195.39.246.36
+        dhcp-authoritative
+        dhcp-rapid-commit
+        dhcp-sequential-ip
 
-      dhcp-host=id:ac:67:5d:12:2f:5a,                                       isa-p2max,        [2a0f:4ac0:acab::37]
-      dhcp-host=ac:67:5d:12:2f:5a,                                          isa-p2max,        195.39.246.37
+        dhcp-range=private, 10.0.0.100,          10.0.0.200,                           255.255.255.0,                  48h
+        dhcp-range=public,  195.39.246.34,       static,                               255.255.255.240, 195.39.246.47, 48h
+        dhcp-range=         2a0f:4ac0:acab::100, 2a0f:4ac0:acab::01ff, ra-names,slaac, 64,                             48h
 
-      dhcp-host=id:00:01:00:01:29:1c:39:07:f4:5c:89:c1:dc:b1,               isabelles-mbp,    [2a0f:4ac0:acab::38]
-      dhcp-host=f4:5c:89:c1:dc:b1,                                          isabelles-mbp,    195.39.246.38
+        dhcp-option=option6:information-refresh-time, 6h
+        dhcp-option=option6:dns-server,               [2a0f:4ac0:acab::1]
+        dhcp-option=private, option:router,           10.0.0.1
+        dhcp-option=private, option:dns-server,       10.0.0.1
+        dhcp-option=public,  option:router,           195.39.246.41
+        dhcp-option=public,  option:dns-server,       195.39.246.41
 
-      dhcp-host=id:e8:6a:64:f4:49:e7,                                       stasicontainer,   [2a0f:4ac0:acab::42]
-      dhcp-host=e8:6a:64:f4:49:e7,                                          stasicontainer,   195.39.246.42
+        dhcp-host=f4:06:8d:df:1f:e3,                                          accesspoint,      10.0.0.2
+        dhcp-host=2a0f:4ac0:acab::12a,                                        garmin-vivo-3,    10.0.0.210
 
-      dhcp-host=id:04:ea:56:f3:0b:5b,                                       coladose,         [2a0f:4ac0:acab::43]
-      dhcp-host=04:ea:56:f3:0b:5b, e8:6a:64:d6:e3:33,                       coladose,         195.39.246.43
+        dhcp-host=id:04:ea:56:f2:b4:6c,                                       isa-x390,         [2a0f:4ac0:acab::36]
+        dhcp-host=04:ea:56:f2:b4:6c,                                          isa-x390,         195.39.246.36
 
-      dhcp-host=34:31:c4:46:88:31,                                          fritz7312,        195.39.246.46
-    '';
-  };
+        dhcp-host=id:ac:67:5d:12:2f:5a,                                       isa-p2max,        [2a0f:4ac0:acab::37]
+        dhcp-host=ac:67:5d:12:2f:5a,                                          isa-p2max,        195.39.246.37
+
+        dhcp-host=id:00:01:00:01:29:1c:39:07:f4:5c:89:c1:dc:b1,               isabelles-mbp,    [2a0f:4ac0:acab::38]
+        dhcp-host=f4:5c:89:c1:dc:b1,                                          isabelles-mbp,    195.39.246.38
+
+        dhcp-host=id:e8:6a:64:f4:49:e7,                                       stasicontainer,   [2a0f:4ac0:acab::42]
+        dhcp-host=e8:6a:64:f4:49:e7,                                          stasicontainer,   195.39.246.42
 
-  services.phpfpm.pools.dnsmasq  = {
-    user  = "dnsmasq";
-    group = "dnsmasq";
-    settings = {
-      pm                     = "dynamic";
-      "listen.owner"         = config.services.nginx.user;
-      "pm.max_children"      = 1;
-      "pm.start_servers"     = 1;
-      "pm.min_spare_servers" = 1;
-      "pm.max_spare_servers" = 1;
-      "pm.max_requests"      = 500;
+        dhcp-host=id:04:ea:56:f3:0b:5b,                                       coladose,         [2a0f:4ac0:acab::43]
+        dhcp-host=04:ea:56:f3:0b:5b, e8:6a:64:d6:e3:33,                       coladose,         195.39.246.43
+
+        dhcp-host=34:31:c4:46:88:31,                                          fritz7312,        195.39.246.46
+      '';
     };
-  };
 
-  services.nginx = {
-    enable = true;
-    virtualHosts."dnsmasq.home.ctu.cx" = {
-      enableACME = true;
-      forceSSL   = true;
-      root       = dnsmasq-lease-overview;
-      locations  = {
-        "/".tryFiles           = "$uri $uri/ /index.php?$query_string";
-        "/".index              = "index.php index.html";
-        "~ \.php$".extraConfig = ''
-          fastcgi_pass  unix:${config.services.phpfpm.pools.dnsmasq.socket};
-          fastcgi_index index.php;
-        '';
+    phpfpm.pools.dnsmasq  = {
+      user  = "dnsmasq";
+      group = "dnsmasq";
+      settings = {
+        pm                     = "dynamic";
+        "listen.owner"         = config.services.nginx.user;
+        "pm.max_children"      = 1;
+        "pm.start_servers"     = 1;
+        "pm.min_spare_servers" = 1;
+        "pm.max_spare_servers" = 1;
+        "pm.max_requests"      = 500;
       };
     };
+
+    nginx = {
+      enable = true;
+      virtualHosts."dnsmasq.home.ctu.cx" = {
+        enableACME = true;
+        forceSSL   = true;
+        root       = dnsmasq-lease-overview;
+        locations  = {
+          "/".tryFiles           = "$uri $uri/ /index.php?$query_string";
+          "/".index              = "index.php index.html";
+          "~ \.php$".extraConfig = ''
+            fastcgi_pass  unix:${config.services.phpfpm.pools.dnsmasq.socket};
+            fastcgi_index index.php;
+          '';
+        };
+      };
+    };
+
   };
 
 }
diff --git a/machines/lollo/smarthome/default.nix b/machines/lollo/smarthome/default.nix
@@ -1,4 +1,4 @@
-{ config, lib, pkgs, ... }:
+{ ... }:
 
 {
 
diff --git a/machines/lollo/smarthome/influxdb2.nix b/machines/lollo/smarthome/influxdb2.nix
@@ -1,8 +1,11 @@
-{ config, lib, pkgs, ... }:
+{ pkgs, ... }:
 
 {
 
-  systemd.services.influxdb2.serviceConfig.ExecStartPost = "${pkgs.bash}/bin/bash -c 'until ${pkgs.netcat}/bin/nc -z 127.0.0.1 8086; do sleep 0.2; done'";
+  systemd.services.influxdb2 = {
+    serviceConfig.ExecStartPost = "${pkgs.bash}/bin/bash -c 'until ${pkgs.netcat}/bin/nc -z 127.0.0.1 8086; do sleep 0.2; done'";
+    onFailure                   = [ "notify-failure@%i.service" ];
+  };
 
   services.influxdb2.enable = true;
 
diff --git a/machines/lollo/smarthome/mbusd.nix b/machines/lollo/smarthome/mbusd.nix
@@ -1,4 +1,4 @@
-{ config, lib, pkgs, ... }:
+{ pkgs, ... }:
 
 let
   mbusd = pkgs.stdenv.mkDerivation rec {

@@ -20,10 +20,11 @@ in {
   services.udev.extraRules = ''SUBSYSTEM=="tty", ATTRS{idVendor}=="10c4", ATTRS{serial}=="1337", SYMLINK+="modbus0"'';
 
   systemd.services.mbusd = {
-    wantedBy = [ "multi-user.target" ];
-    requires = [ "network-online.target" "dev-modbus0.device" ];
-    wants    = [ "network-online.target" "dev-modbus0.device" ];
-    after    = [ "network-online.target" "dev-modbus0.device" ];
+    wantedBy  = [ "multi-user.target" ];
+    requires  = [ "network-online.target" "dev-modbus0.device" ];
+    wants     = [ "network-online.target" "dev-modbus0.device" ];
+    after     = [ "network-online.target" "dev-modbus0.device" ];
+    onFailure = [ "notify-failure@%i.service" ];
 
     serviceConfig = {
       ExecStart      = "${mbusd}/bin/mbusd -d -v2 -L - -p /dev/modbus0 -s 9600 -m 8n1 -C 32 -N 3 -R 100 -W 500 -T 60";
diff --git a/machines/lollo/smarthome/serial2tcp.nix b/machines/lollo/smarthome/serial2tcp.nix
@@ -18,10 +18,11 @@ in {
   services.udev.extraRules = ''SUBSYSTEM=="tty", ATTRS{idVendor}=="1a86", ATTRS{idProduct}=="7523", SYMLINK+="tempsensors0"'';
 
   systemd.services.serial2tcp = {
-    wantedBy = [ "multi-user.target" ];
-    requires = [ "network-online.target" "dev-tempsensors0.device" ];
-    wants    = [ "network-online.target" "dev-tempsensors0.device" ];
-    after    = [ "network-online.target" "dev-tempsensors0.device" ];
+    wantedBy  = [ "multi-user.target" ];
+    requires  = [ "network-online.target" "dev-tempsensors0.device" ];
+    wants     = [ "network-online.target" "dev-tempsensors0.device" ];
+    after     = [ "network-online.target" "dev-tempsensors0.device" ];
+    onFailure = [ "notify-failure@%i.service" ];
 
     serviceConfig = {
       ExecStartPre = "${pkgs.coreutils}/bin/stty -F /dev/tempsensors0 raw -echo -echoe -echok speed 9600";
diff --git a/machines/lollo/smarthome/smartied.nix b/machines/lollo/smarthome/smartied.nix
@@ -347,9 +347,10 @@ let
 in {
 
   systemd.services.smartied = {
-    wantedBy = [ "multi-user.target" ];
-    requires = [ "network-online.target" "mbusd.service" "serial2tcp.service" "influxdb2.service" "zigbee2mqtt.service" ];
-    after    = [ "network-online.target" "mbusd.service" "serial2tcp.service" "influxdb2.service" "zigbee2mqtt.service" ];
+    wantedBy  = [ "multi-user.target" ];
+    requires  = [ "network-online.target" "mbusd.service" "serial2tcp.service" "influxdb2.service" "zigbee2mqtt.service" ];
+    after     = [ "network-online.target" "mbusd.service" "serial2tcp.service" "influxdb2.service" "zigbee2mqtt.service" ];
+    onFailure = [ "notify-failure@%i.service" ];
 
     serviceConfig = {
       ExecStart    = "${smartied}/bin/smartied";
diff --git a/machines/lollo/smarthome/zigbee2mqtt.nix b/machines/lollo/smarthome/zigbee2mqtt.nix
@@ -1,4 +1,4 @@
-{ config, lib, pkgs, ... }:
+{ config, pkgs, ... }:
 
 let
   pkgsUnstable = import <nixpkgsUnstable> {};

@@ -7,8 +7,9 @@ let
 in {
 
   systemd.services.zigbee2mqtt = {
-    requires = [ "mosquitto.service" ];
-    after    = [ "mosquitto.service" ];
+    requires  = [ "mosquitto.service" ];
+    after     = [ "mosquitto.service" ];
+    onFailure = [ "notify-failure@%i.service" ];
   };
 
   services = {
diff --git a/machines/lollo/syncthing.nix b/machines/lollo/syncthing.nix
@@ -6,6 +6,8 @@
     ../../configurations/services/syncthing.nix
   ];
 
+  systemd.services.sycnthing.onFailure = [ "notify-failure@%i.service" ];
+
   services = {
     syncthing = {
       guiAddress = "0.0.0.0:8384";