From 0f1d12cb34c1b0c375141973a5ccdf81ebbb58f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Thu, 20 Jul 2023 09:31:26 +0300 Subject: [PATCH] unitstatus: pre-defined service units now exist --- hosts/hel1-a/configuration.nix | 148 +++++++++++----------------- modules/base/unitstatus/default.nix | 82 +++++++-------- modules/base/zfsborg/default.nix | 64 +++++++----- 3 files changed, 130 insertions(+), 164 deletions(-) diff --git a/hosts/hel1-a/configuration.nix b/hosts/hel1-a/configuration.nix index 7e37b98..1ed30ce 100644 --- a/hosts/hel1-a/configuration.nix +++ b/hosts/hel1-a/configuration.nix @@ -6,29 +6,6 @@ myData, ... }: let - backup_paths = { - var_lib = { - mountpoint = "/var/lib"; - zfs_name = "rpool/nixos/var/lib"; - paths = [ - "/var/lib/.snapshot-latest/gitea" - "/var/lib/.snapshot-latest/headscale" - "/var/lib/.snapshot-latest/matrix-synapse" - ]; - backup_at = "*-*-* 00:11:00"; - }; - var_log = { - mountpoint = "/var/log"; - zfs_name = "rpool/nixos/var/log"; - paths = ["/var/log/.snapshot-latest/caddy/"]; - patterns = [ - "+ /var/log/.snapshot-latest/caddy/access-jakstys.lt.log-*.zst" - "- *" - ]; - backup_at = "*-*-* 00:10:00"; - }; - }; - turn_cert_dir = "/var/lib/caddy/.local/share/caddy/certificates/acme-v02.api.letsencrypt.org-directory/turn.jakstys.lt"; gitea_uidgid = 995; @@ -106,7 +83,7 @@ in { enable = true; email = "motiejus+alerts@jakstys.lt"; # see TODO in base/unitstatus/default.nix - #units = ["zfs-scrub"]; + units = ["zfs-scrub" "nixos-upgrade"]; }; }; }; @@ -531,79 +508,68 @@ in { "d /run/matrix-synapse 0700 matrix-synapse matrix-synapse -" ]; - systemd.services = - { - coturn = { - preStart = '' - ln -sf ''${CREDENTIALS_DIRECTORY}/tls-key.pem /run/coturn/tls-key.pem - ln -sf ''${CREDENTIALS_DIRECTORY}/tls-cert.pem /run/coturn/tls-cert.pem - ''; - unitConfig.ConditionPathExists = [ - "${turn_cert_dir}/turn.jakstys.lt.key" - "${turn_cert_dir}/turn.jakstys.lt.crt" - ]; - serviceConfig.LoadCredential = [ - "static-auth-secret:${config.age.secrets.turn-static-auth-secret.path}" - "tls-key.pem:${turn_cert_dir}/turn.jakstys.lt.key" - "tls-cert.pem:${turn_cert_dir}/turn.jakstys.lt.crt" - ]; - }; + systemd.services = { + coturn = { + preStart = '' + ln -sf ''${CREDENTIALS_DIRECTORY}/tls-key.pem /run/coturn/tls-key.pem + ln -sf ''${CREDENTIALS_DIRECTORY}/tls-cert.pem /run/coturn/tls-cert.pem + ''; + unitConfig.ConditionPathExists = [ + "${turn_cert_dir}/turn.jakstys.lt.key" + "${turn_cert_dir}/turn.jakstys.lt.crt" + ]; + serviceConfig.LoadCredential = [ + "static-auth-secret:${config.age.secrets.turn-static-auth-secret.path}" + "tls-key.pem:${turn_cert_dir}/turn.jakstys.lt.key" + "tls-cert.pem:${turn_cert_dir}/turn.jakstys.lt.crt" + ]; + }; - headscale = { - unitConfig.StartLimitIntervalSec = "5m"; + headscale = { + unitConfig.StartLimitIntervalSec = "5m"; - # Allow restarts for up to a minute. A start - # itself may take a while, thus the window of restart - # is higher. - unitConfig.StartLimitBurst = 50; - serviceConfig.RestartSec = 1; - }; + # Allow restarts for up to a minute. A start + # itself may take a while, thus the window of restart + # is higher. + unitConfig.StartLimitBurst = 50; + serviceConfig.RestartSec = 1; + }; - matrix-synapse = let - # TODO https://github.com/NixOS/nixpkgs/pull/222336 replace with `preStart` - secretsScript = pkgs.writeShellScript "write-secrets" '' - set -euo pipefail - umask 077 - ln -sf ''${CREDENTIALS_DIRECTORY}/jakstys_lt_signing_key /run/matrix-synapse/jakstys_lt_signing_key - cat > /run/matrix-synapse/secrets.yaml < /run/matrix-synapse/secrets.yaml <.unitConfig.OnFailure' to point to this one. # - assert postfix is configured options.mj.base.unitstatus = with lib.types; { enable = lib.mkEnableOption "alert by email on unit failure"; email = lib.mkOption {type = str;}; - #units = lib.mkOption {type = lisOf str;}; + units = lib.mkOption {type = listOf str;}; }; - config = - lib.mkIf config.mj.base.unitstatus.enable { - systemd.services."unit-status-mail@" = let - # https://northernlightlabs.se/2014-07-05/systemd-status-mail-on-unit-failure.html - script = pkgs.writeShellScript "unit-status-mail" '' - set -e - MAILTO="${config.mj.base.unitstatus.email}" - UNIT=$1 - EXTRA="" - for e in "''${@:2}"; do - EXTRA+="$e"$'\n' - done - UNITSTATUS=$(${pkgs.systemd}/bin/systemctl status "$UNIT") - ${pkgs.postfix}/bin/sendmail $MAILTO <