From 8e273fedcf4342a0c0823378b127b437d98cf7c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Charlotte=20=F0=9F=A6=9D=20Delenk?= Date: Mon, 12 Sep 2022 11:03:10 +0100 Subject: [PATCH] notify on service failures --- config/programs/fluffychat.nix | 31 +++++----- config/programs/ims.nix | 2 +- .../vim/modules/languages/default.nix | 14 +++-- config/services/akkoma/default.nix | 45 +++++++------- config/services/monitoring.nix | 18 ++++++ modules/systemd-email-notify.nix | 58 +++++++++++++++++++ 6 files changed, 126 insertions(+), 42 deletions(-) create mode 100644 config/services/monitoring.nix create mode 100644 modules/systemd-email-notify.nix diff --git a/config/programs/fluffychat.nix b/config/programs/fluffychat.nix index 57db4ec6..915d166b 100644 --- a/config/programs/fluffychat.nix +++ b/config/programs/fluffychat.nix @@ -1,17 +1,17 @@ -{ lib -, fetchFromGitLab -, flutter -, olm -, imagemagick -, jack2 -, alsa-lib -, libpulseaudio -, fribidi -, libgcrypt -, libgpg-error -, makeDesktopItem +{ + lib, + fetchFromGitLab, + flutter, + olm, + imagemagick, + jack2, + alsa-lib, + libpulseaudio, + fribidi, + libgcrypt, + libgpg-error, + makeDesktopItem, }: - flutter.mkFlutterApp rec { pname = "fluffychat"; version = "1.6.1"; @@ -31,7 +31,7 @@ flutter.mkFlutterApp rec { icon = "fluffychat"; desktopName = "Fluffychat"; genericName = "Chat with your friends (matrix client)"; - categories = [ "Chat" "Network" "InstantMessaging" ]; + categories = ["Chat" "Network" "InstantMessaging"]; }; buildInputs = [ @@ -89,8 +89,7 @@ flutter.mkFlutterApp rec { description = "Chat with your friends (matrix client)"; homepage = "https://fluffychat.im/"; license = licenses.agpl3Plus; - maintainers = with maintainers; [ mkg20001 ]; + maintainers = with maintainers; [mkg20001]; platforms = platforms.linux; }; } - diff --git a/config/programs/ims.nix b/config/programs/ims.nix index 26a20348..9fa5f9d6 100644 --- a/config/programs/ims.nix +++ b/config/programs/ims.nix @@ -4,7 +4,7 @@ nixpkgs-fluffychat, ... }: let - pkgs-fluffychat = import nixpkgs-fluffychat { inherit (pkgs) system; }; + pkgs-fluffychat = import nixpkgs-fluffychat {inherit (pkgs) system;}; in { home.packages = with pkgs; [ (pkgs-fluffychat.callPackage ./fluffychat.nix {}) diff --git a/config/programs/vim/modules/languages/default.nix b/config/programs/vim/modules/languages/default.nix index 5e4417b9..195aa841 100644 --- a/config/programs/vim/modules/languages/default.nix +++ b/config/programs/vim/modules/languages/default.nix @@ -1,6 +1,11 @@ # Largely copied from a great blog post: # https://sharksforarms.dev/posts/neovim-rust/ -{ pkgs, lib, config, ... }: +{ + pkgs, + lib, + config, + ... +}: with lib; { vim.opt = { completeopt = "menuone,noinsert,noselect"; @@ -15,15 +20,14 @@ with lib; { }; vim.keybindings.keybindings-shortened = { - "K" = { command = "lua vim.lsp.buf.hover()"; }; + "K" = {command = "lua vim.lsp.buf.hover()";}; }; vim.g.lightline.component_expand.lsp_status = "LspStatus"; - vim.g.lightline.active.right = mkAfter [ [ "lsp_status" ] ]; + vim.g.lightline.active.right = mkAfter [["lsp_status"]]; # https://discourse.nixos.org/t/rust-src-not-found-and-other-misadventures-of-developing-rust-on-nixos/11570/2 - output.makeWrapper = - "--set RUST_SRC_PATH ${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}"; + output.makeWrapper = "--set RUST_SRC_PATH ${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}"; output.config_file = '' set shortmess+=c diff --git a/config/services/akkoma/default.nix b/config/services/akkoma/default.nix index 6862b462..aaed4d35 100644 --- a/config/services/akkoma/default.nix +++ b/config/services/akkoma/default.nix @@ -1,29 +1,34 @@ -{ pkgs, nix-packages, config, ... }: -let static_dir = pkgs.stdenvNoCC.mkDerivation { - name = "akkoma-static"; - src = pkgs.emptyDirectory; - nativeBuildInputs = with pkgs; [xorg.lndir]; - akkoma_fe = nix-packages.packages.${pkgs.system}.akkoma-fe; - akkoma_admin_fe = nix-packages.packages.${pkgs.system}.akkoma-admin-fe; - dontUnpack = false; - installPhase = '' - mkdir -p $out/frontends/pleroma-fe/stable - lndir $akkoma_fe $out/frontends/pleroma-fe/stable - mkdir -p $out/frontends/admin-fe/stable - lndir $akkoma_admin_fe $out/frontends/admin-fe/stable - ''; -}; -akkconfig = builtins.replaceStrings ["%AKKOMA_STATIC_DIR%"] ["${static_dir}"] (builtins.readFile ./akkoma.exs); -in{ +{ + pkgs, + nix-packages, + config, + ... +}: let + static_dir = pkgs.stdenvNoCC.mkDerivation { + name = "akkoma-static"; + src = pkgs.emptyDirectory; + nativeBuildInputs = with pkgs; [xorg.lndir]; + akkoma_fe = nix-packages.packages.${pkgs.system}.akkoma-fe; + akkoma_admin_fe = nix-packages.packages.${pkgs.system}.akkoma-admin-fe; + dontUnpack = false; + installPhase = '' + mkdir -p $out/frontends/pleroma-fe/stable + lndir $akkoma_fe $out/frontends/pleroma-fe/stable + mkdir -p $out/frontends/admin-fe/stable + lndir $akkoma_admin_fe $out/frontends/admin-fe/stable + ''; + }; + akkconfig = builtins.replaceStrings ["%AKKOMA_STATIC_DIR%"] ["${static_dir}"] (builtins.readFile ./akkoma.exs); +in { services.pleroma = { enable = true; package = nix-packages.packages.${pkgs.system}.akkoma; - configs = [ akkconfig ]; + configs = [akkconfig]; user = "akkoma"; group = "akkoma"; secretConfigFile = config.sops.secrets."services/akkoma.exs".path; }; - systemd.services.pleroma.path = with pkgs; [ exiftool imagemagick ffmpeg ]; + systemd.services.pleroma.path = with pkgs; [exiftool imagemagick ffmpeg]; services.postgresql.ensureDatabases = ["akkoma"]; services.postgresql.ensureUsers = [ { @@ -31,7 +36,7 @@ in{ ensurePermissions = {"DATABASE akkoma" = "ALL PRIVILEGES";}; } ]; - sops.secrets."services/akkoma.exs" = { owner = "akkoma"; }; + sops.secrets."services/akkoma.exs" = {owner = "akkoma";}; services.caddy.virtualHosts."akko.chir.rs" = { useACMEHost = "chir.rs"; extraConfig = '' diff --git a/config/services/monitoring.nix b/config/services/monitoring.nix new file mode 100644 index 00000000..939333b3 --- /dev/null +++ b/config/services/monitoring.nix @@ -0,0 +1,18 @@ +{pkgs, ...}: { + imports = [../../modules/systemd-email-notify.nix]; + programs.msmtp = { + enable = true; + accounts = { + notif = { + auth = true; + tls = true; + host = "mail.chir.rs"; + from = "notification@chir.rs"; + user = "lotte@chir.rs"; + passwordeval = "cat /run/secrets/email/lotte@chir.rs"; + }; + }; + }; + systemd.email-notify.mailFrom = "notif@chir.rs"; + systemd.email-notify.mailTo = "lotte@chir.rs"; +} diff --git a/modules/systemd-email-notify.nix b/modules/systemd-email-notify.nix new file mode 100644 index 00000000..25465faf --- /dev/null +++ b/modules/systemd-email-notify.nix @@ -0,0 +1,58 @@ +# Taken from https://github.com/pSub/configs/blob/master/nixops/configurations/server.pascal-wittmann.de/modules/systemd-email-notify.nix +{ + config, + lib, + pkgs, + ... +}: +with lib; let + sendmail = + pkgs.writeScript "sendmail" + '' + #!/bin/sh + + ${pkgs.system-sendmail}/bin/sendmail -t <