From 2a90b44b84532760e96b487da9273c5c3c9d280d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Av=C3=A9?= Date: Mon, 10 Jun 2024 16:28:16 +0200 Subject: [PATCH] Mon Jun 10 04:28:16 PM CEST 2024 --- home/Aloria.nix | 12 ++----- home/Kell.nix | 11 +----- home/Mallorea.nix | 69 ++++--------------------------------- home/{ => utils}/common.nix | 2 +- home/utils/desktop.nix | 23 +++++++++++++ home/utils/services.nix | 61 ++++++++++++++++++++++++++++++++ 6 files changed, 94 insertions(+), 84 deletions(-) rename home/{ => utils}/common.nix (93%) create mode 100644 home/utils/desktop.nix create mode 100644 home/utils/services.nix diff --git a/home/Aloria.nix b/home/Aloria.nix index 12c9458..b58a83b 100644 --- a/home/Aloria.nix +++ b/home/Aloria.nix @@ -2,17 +2,9 @@ { imports = [ - (import ./common.nix { inherit inputs config pkgs; }) - (import ./hyprland { inherit inputs pkgs; }) - (import ./waybar { inherit inputs pkgs; }) - ./rofi - ./alacritty - ./kitty - ./firefox - ./ssh - ./mpv + (import ./utils/desktop.nix { inherit inputs config pkgs; }) ]; - home.packages = with pkgs; [ telegram-desktop webcord devenv iwgtk element-desktop ]; + programs.ssh.matchBlocks."*".identityFile = "/home/user/.secrets/SSH/Aloria/id_ed25519"; services.hyprpaper = { diff --git a/home/Kell.nix b/home/Kell.nix index 4a8292d..449352a 100644 --- a/home/Kell.nix +++ b/home/Kell.nix @@ -2,17 +2,8 @@ { imports = [ - (import ./common.nix { inherit inputs config pkgs; }) - (import ./hyprland { inherit inputs pkgs; }) - (import ./waybar { inherit inputs pkgs; }) - ./rofi - ./alacritty - ./kitty - ./firefox - ./ssh - ./mpv + (import ./utils/desktop.nix { inherit inputs config pkgs; }) ]; - home.packages = with pkgs; [ telegram-desktop webcord devenv loupe evince ]; programs.ssh.matchBlocks."*".identityFile = "/home/server/.secrets/SSH/Kell/id_ed25519"; services.hyprpaper = { diff --git a/home/Mallorea.nix b/home/Mallorea.nix index 9d0e1d8..bd2905e 100644 --- a/home/Mallorea.nix +++ b/home/Mallorea.nix @@ -1,51 +1,5 @@ { inputs, config, pkgs, ... }: let - notify_script = (pkgs.writers.writePython3Bin "telegram-notify.py" { - libraries = [ pkgs.python3Packages.python-telegram-bot ]; - } '' - import telegram - import asyncio - import sys - import subprocess - - - async def run(): - text = subprocess.check_output( - ["journalctl", "--user", "-u", sys.argv[1], "-b"] - ).decode("utf-8") - - with open("/home/server/mail.log", "a") as f: - f.write("===========================================") - f.write(text) - - bot = telegram.Bot(token="381718873:AAElFmI2BDjumCehhWicuksE0vutrPSkoGA") - chat_id = 125754925 - await bot.send_message( - chat_id, "Mallorea encountered an error in the service: " + sys.argv[1] - ) - - await bot.send_message(chat_id, text) - - - if __name__ == "__main__": - loop = asyncio.get_event_loop() - loop.run_until_complete(asyncio.wait([loop.create_task(run())])) - loop.close() - ''); - mkTimer = name: cfg: { - Install.WantedBy = [ "timers.target" ]; - Timer = { - Persistent = true; - OnCalendar = cfg.when; - Unit = "${name}.service"; - }; - }; - mkService = name: cfg: { - Unit.Description = name; - Unit.OnFailure = "status_notify@%n.service"; - Install = { WantedBy = [ "default.target" ]; }; - Service = { ExecStart = cfg.script; }; - }; scripts = { disk_check = { when = "*-*-* *:00:00"; @@ -120,8 +74,12 @@ in { }; xdg.enable = true; - # home.profileDirectory = "${config.xdg.stateHome}/nix/profile"; - imports = [ (import ./common.nix { inherit inputs config pkgs; }) ./ssh ]; + + imports = [ + (import ./utils/common.nix { inherit inputs config pkgs; }) + (import ./utils/services.nix { inherit pkgs; scripts=scripts; }) + ./ssh + ]; programs.ssh.matchBlocks."*".identityFile = "/home/server/.secrets/SSH/Mallorea/id_ed25519"; home.sessionVariables = { @@ -129,19 +87,4 @@ in { LANG = "en_US.UTF-8"; XDG_RUNTIME_DIR = "/run/user/$(id -u)"; }; - - systemd.user.services = pkgs.lib.mapAttrs mkService scripts - // (pkgs.lib.mapAttrs mkService { - "status_notify@" = { - script = "${notify_script}/bin/telegram-notify.py %i"; - }; - }); - systemd.user.timers = pkgs.lib.mapAttrs mkTimer scripts; - - # Don't forget to enable these timers! Or reboot, after which it should also be activated automatically - # systemctl --user enable --now backup.timer - # systemctl --user enable --now sync_vault.timer - # systemctl --user enable --now mbsync.timer - # systemctl --user enable --now vdirsyncer.timer - # systemctl --user enable --now disk_check.timer } diff --git a/home/common.nix b/home/utils/common.nix similarity index 93% rename from home/common.nix rename to home/utils/common.nix index c08b0b4..b36fa00 100644 --- a/home/common.nix +++ b/home/utils/common.nix @@ -1,7 +1,7 @@ { inputs, config, pkgs, ... }: { - imports = [ ./zsh ./git ./nvim ./email ./lf ./tmux ]; + imports = [ ../zsh ../git ../nvim ../email ../lf ../tmux ]; home.stateVersion = "24.11"; targets.genericLinux.enable = true; diff --git a/home/utils/desktop.nix b/home/utils/desktop.nix new file mode 100644 index 0000000..b5e75fd --- /dev/null +++ b/home/utils/desktop.nix @@ -0,0 +1,23 @@ +{ inputs, config, pkgs, ... }: +{ + imports = [ + (import ./common.nix { inherit inputs config pkgs; }) + (import ../hyprland { inherit inputs pkgs; }) + (import ../waybar { inherit inputs pkgs; }) + ../rofi + ../alacritty + ../kitty + ../firefox + ../ssh + ../mpv + ]; + home.packages = with pkgs; [ + telegram-desktop + webcord + devenv + iwgtk + element-desktop + evince + loupe + ]; +} diff --git a/home/utils/services.nix b/home/utils/services.nix new file mode 100644 index 0000000..7974e89 --- /dev/null +++ b/home/utils/services.nix @@ -0,0 +1,61 @@ +{ pkgs, scripts }: +let + notify_script = (pkgs.writers.writePython3Bin "telegram-notify.py" { + libraries = [ pkgs.python3Packages.python-telegram-bot ]; + } '' + import telegram + import asyncio + import sys + import socket + import subprocess + + + async def run(): + text = subprocess.check_output( + ["journalctl", "--user", "-u", sys.argv[1], "-b"] + ).decode("utf-8") + + with open("/home/server/mail.log", "a") as f: + f.write("===========================================") + f.write(text) + + bot = telegram.Bot(token="381718873:AAElFmI2BDjumCehhWicuksE0vutrPSkoGA") + chat_id = 125754925 + hostname = socket.gethostname() + await bot.send_message(chat_id, f"{hostname} encountered an error in the service: {sys.argv[1]}") + + await bot.send_message(chat_id, text) + + + if __name__ == "__main__": + loop = asyncio.get_event_loop() + loop.run_until_complete(asyncio.wait([loop.create_task(run())])) + loop.close() + ''); + + mkTimer = name: cfg: { + Install.WantedBy = [ "timers.target" ]; + Timer = { + Persistent = true; + OnCalendar = cfg.when; + Unit = "${name}.service"; + }; + }; + mkService = name: cfg: { + Unit.Description = name; + Unit.OnFailure = "status_notify@%n.service"; + Install = { WantedBy = [ "default.target" ]; }; + Service = { ExecStart = cfg.script; }; + }; +in +{ + systemd.user.services = pkgs.lib.mapAttrs mkService scripts + // (pkgs.lib.mapAttrs mkService { + "status_notify@" = { + script = "${notify_script}/bin/telegram-notify.py %i"; + }; + }); + systemd.user.timers = pkgs.lib.mapAttrs mkTimer scripts; + # Don't forget to enable these timers! Or reboot, after which it should also be activated automatically + # systemctl --user enable --now