Tue Jun 4 04:16:30 PM CEST 2024

This commit is contained in:
Thomas Avé 2024-06-04 16:16:30 +02:00
parent 2f88658882
commit d6f4ca2f3d
9 changed files with 262 additions and 271 deletions

View File

@ -31,8 +31,8 @@
{ nixpkgs.overlays = [ nur.overlay ]; }
{
hardware.opengl = {
enable = true;
driSupport = true;
enable = true;
driSupport = true;
};
networking.hostName = host;
boot.loader.systemd-boot = {
@ -50,7 +50,7 @@
"hyprland.cachix.org-1:a7pgxzMz7+chwVL3/pzj6jIBMioiJM7ypFP8PwtkuGc="
];
experimental-features = [ "nix-command" "flakes" ];
trusted-users = ["root" "user"];
trusted-users = [ "root" "user" ];
auto-optimise-store = true;
};

View File

@ -12,11 +12,7 @@
./ssh
./mpv
];
home.packages = with pkgs; [
telegram-desktop
webcord
devenv
];
home.packages = with pkgs; [ telegram-desktop webcord devenv ];
services.hyprpaper = {
settings = {

View File

@ -1,146 +1,139 @@
{ 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
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")
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)
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]
)
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)
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";
script = toString (pkgs.writeShellScript "script" ''
REPORT_EMAIL=email@thomasave.be
ZPOOL_STATUS=$(zpool status -x)
if [ "$ZPOOL_STATUS" = "all pools are healthy" ] || [ "$ZPOOL_STATUS" = "no pools available" ]
then
printf 0 > /var/db/zpool.status
else
if [ "$(cat /var/db/zpool.status)" -eq 0 ]
then
zpool status | mail -s "ZPOOL NOT HEALTHY" $REPORT_EMAIL
printf 1 > /var/db/zpool.status
fi
fi
'');
};
vdirsyncer = {
when = "*:0/15";
script = toString (pkgs.writeShellScript "script" ''
${pkgs.vdirsyncer}/bin/vdirsyncer sync imec/pair
'');
};
mbsync = {
when = "*-*-* 00:00:00";
script = toString (pkgs.writeShellScript "script" ''
BASEDIR=/home/server/Containers/mbsync
# python3 $BASEDIR/config/oauth2/mutt_oauth2.py $BASEDIR/data/oauth2/credentials.json
docker exec --user "1000:1000" mbsync-container /home/user/.config/mbsync/run.sh -a
${pkgs.notmuch}/bin/notmuch new
'');
};
sync_vault = {
when = "*-*-* 02:00:00";
script = toString (pkgs.writeShellScript "script" ''
source $HOME/.secrets/Backup/env.sh
for _ in {1..2}; do
OUTPUT=$(echo "$ZFS_PASSPHRASE" | ssh 10.4.0.1 zfs load-key Vault/Thomas/Encrypted 2>&1);
if [ "$OUTPUT" == "Key load error: Key already loaded for 'Vault/Thomas/Encrypted'." ]; then
echo "Key successfully loaded, starting syncoid"
syncoid --no-privilege-elevation --no-sync-snap tank/Storage/Thomas/Workspace 10.4.0.1:Vault/Thomas/Encrypted/Storage/Workspace
syncoid --no-privilege-elevation --no-sync-snap tank/Storage/Thomas 10.4.0.1:Vault/Thomas/Encrypted/Storage/T
syncoid --no-privilege-elevation --no-sync-snap tank/Storage/Niels 10.4.0.1:Vault/Thomas/Encrypted/Storage/N
syncoid --no-privilege-elevation --no-sync-snap tank/Storage/Yolande 10.4.0.1:Vault/Thomas/Encrypted/Storage/Y
syncoid --no-privilege-elevation --no-sync-snap tank/Containers 10.4.0.1:Vault/Thomas/Encrypted/Containers
ssh 10.4.0.1 zfs unload-key Vault/Thomas/Encrypted
${pkgs.curl}/bin/curl https://uptime.thomasave.be/api/push/s39pIIrB0R
exit 0
fi
done
echo "Found output instead: $OUTPUT"
echo "Failed to load key: $OUTPUT" | sendmail
exit 1
'');
};
backup = {
when = "*-*-* 04:00:00";
script = toString (pkgs.writeShellScript "script" ''
${./scripts/files/backup.sh}
${pkgs.curl}/bin/curl https://uptime.thomasave.be/api/push/R6iJcWqGp0
'');
};
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";
};
in
{
};
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";
script = toString (pkgs.writeShellScript "script" ''
REPORT_EMAIL=email@thomasave.be
ZPOOL_STATUS=$(zpool status -x)
if [ "$ZPOOL_STATUS" = "all pools are healthy" ] || [ "$ZPOOL_STATUS" = "no pools available" ]
then
printf 0 > /var/db/zpool.status
else
if [ "$(cat /var/db/zpool.status)" -eq 0 ]
then
zpool status | mail -s "ZPOOL NOT HEALTHY" $REPORT_EMAIL
printf 1 > /var/db/zpool.status
fi
fi
'');
};
vdirsyncer = {
when = "*:0/15";
script = toString (pkgs.writeShellScript "script" ''
${pkgs.vdirsyncer}/bin/vdirsyncer sync imec/pair
'');
};
mbsync = {
when = "*-*-* 00:00:00";
script = toString (pkgs.writeShellScript "script" ''
BASEDIR=/home/server/Containers/mbsync
# python3 $BASEDIR/config/oauth2/mutt_oauth2.py $BASEDIR/data/oauth2/credentials.json
docker exec --user "1000:1000" mbsync-container /home/user/.config/mbsync/run.sh -a
${pkgs.notmuch}/bin/notmuch new
'');
};
sync_vault = {
when = "*-*-* 02:00:00";
script = toString (pkgs.writeShellScript "script" ''
source $HOME/.secrets/Backup/env.sh
for _ in {1..2}; do
OUTPUT=$(echo "$ZFS_PASSPHRASE" | ssh 10.4.0.1 zfs load-key Vault/Thomas/Encrypted 2>&1);
if [ "$OUTPUT" == "Key load error: Key already loaded for 'Vault/Thomas/Encrypted'." ]; then
echo "Key successfully loaded, starting syncoid"
syncoid --no-privilege-elevation --no-sync-snap tank/Storage/Thomas/Workspace 10.4.0.1:Vault/Thomas/Encrypted/Storage/Workspace
syncoid --no-privilege-elevation --no-sync-snap tank/Storage/Thomas 10.4.0.1:Vault/Thomas/Encrypted/Storage/T
syncoid --no-privilege-elevation --no-sync-snap tank/Storage/Niels 10.4.0.1:Vault/Thomas/Encrypted/Storage/N
syncoid --no-privilege-elevation --no-sync-snap tank/Storage/Yolande 10.4.0.1:Vault/Thomas/Encrypted/Storage/Y
syncoid --no-privilege-elevation --no-sync-snap tank/Containers 10.4.0.1:Vault/Thomas/Encrypted/Containers
ssh 10.4.0.1 zfs unload-key Vault/Thomas/Encrypted
${pkgs.curl}/bin/curl https://uptime.thomasave.be/api/push/s39pIIrB0R
exit 0
fi
done
echo "Found output instead: $OUTPUT"
echo "Failed to load key: $OUTPUT" | sendmail
exit 1
'');
};
backup = {
when = "*-*-* 04:00:00";
script = toString (pkgs.writeShellScript "script" ''
${./scripts/files/backup.sh}
${pkgs.curl}/bin/curl https://uptime.thomasave.be/api/push/R6iJcWqGp0
'');
};
};
in {
home.username = "server";
home.homeDirectory = "/home/server";
nix = {
package = pkgs.nix;
settings.use-xdg-base-directories = true;
package = pkgs.nix;
settings.use-xdg-base-directories = true;
};
xdg.enable = true;
# home.profileDirectory = "${config.xdg.stateHome}/nix/profile";
imports = [
(import ./common.nix { inherit inputs config pkgs; })
./ssh
];
imports = [ (import ./common.nix { inherit inputs config pkgs; }) ./ssh ];
home.sessionVariables = {
NIX_PATH = "${config.xdg.stateHome}/nix/profiles/channels/";
LANG = "en_US.UTF-8";
XDG_RUNTIME_DIR="/run/user/$(id -u)";
NIX_PATH = "${config.xdg.stateHome}/nix/profiles/channels/";
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.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

View File

@ -5,9 +5,7 @@
".mailcap".text =
"text/html; w3m -dump -o -document_charset=%{charset} %s; nametemplate=%s.html; copiousoutput";
};
home.packages = with pkgs; [
mailcap
];
home.packages = with pkgs; [ mailcap ];
programs.notmuch = {
enable = true;
@ -155,8 +153,8 @@
};
extraConfig = {
general = {
term = "xterm-256color";
unsafe-accounts-conf = true;
term = "xterm-256color";
unsafe-accounts-conf = true;
};
ui = {
border-char-vertical = "";
@ -168,59 +166,72 @@
dirlist-right = "{{if .Unread}}{{humanReadable .Unread}}{{end}}";
dirlist-tree = true;
};
viewer = { pager = "${pkgs.neovim}/bin/nvim -u ${config.xdg.configHome}/nvim/aerc.lua"; };
viewer = {
pager =
"${pkgs.neovim}/bin/nvim -u ${config.xdg.configHome}/nvim/aerc.lua";
};
compose = { address-book-cmd = ''notmuch address "%s"''; };
multipart-converters = {
"text/html" = "${pkgs.w3m}/bin/w3m -dump -o display_link_number=1 -T text/html";
"text/html" =
"${pkgs.w3m}/bin/w3m -dump -o display_link_number=1 -T text/html";
};
filters = {
"text/plain" = "cat";
"text/calendar" = "${pkgs.gnome.gnome-calendar}/bin/gnome-calendar";
"message/delivery-status" = "cat";
"message/rfc822" = "cat";
"text/html" = "${pkgs.w3m}/bin/w3m -dump -o display_link_number=1 -T text/html";
"text/html" =
"${pkgs.w3m}/bin/w3m -dump -o display_link_number=1 -T text/html";
"application/x-sh" = "${pkgs.bat}/bin/bat -fP -l sh";
};
};
extraAccounts = {
Zoho = {
outgoing = "smtps://email%40thomasave.be@smtp.zoho.com";
outgoing-cred-cmd = "cat ~/.secrets/Aerc/Zoho.key";
source = "maildir:///home/server/Storage/Thomas/Mail/email@thomasave.be/";
check-mail-cmd = "ssh server@10.1 /home/server/Containers/mbsync/sync.sh";
check-mail-timeout = "60s";
default = "Inbox";
from = "\"Thomas Avé\" <email@thomasave.be>";
cache-headers = true;
};
UAntwerpen = {
outgoing = "ssh server@192.168.1.2 /home/server/Containers/mbsync/send.sh";
source = "maildir:///home/server/Storage/Thomas/Mail/Thomas.Ave@uantwerpen.be";
check-mail-cmd = "ssh server@10.1 /home/server/Containers/mbsync/sync.sh";
check-mail-timeout = "60s";
default = "Inbox";
from = "\"Thomas Avé\" <Thomas.Ave@uantwerpen.be>";
cache-headers = true;
};
IMEC = {
outgoing = "smtp+insecure://ave57%40imec.be@smtp.thomasave.be:1025";
outgoing-cred-cmd = "cat ~/.secrets/Aerc/IMEC.key";
source = "maildir:///home/server/Storage/Thomas/Mail/Thomas.Ave@imec.be/";
check-mail-cmd = "ssh server@10.1 /home/server/Containers/mbsync/sync.sh";
check-mail-timeout = "60s";
default = "Inbox";
from = "\"Thomas Avé\" <Thomas.Ave@imec.be>";
cache-headers = true;
};
NotMuch = {
source = "notmuch:///home/server/Storage/Thomas/Mail/";
check-mail-cmd = "ssh server@10.1 /home/server/Containers/mbsync/sync.sh";
check-mail-timeout = "60s";
from = "\"Thomas Avé\" <Thomas.Ave@uantwerpen.be>";
query-map = "${config.xdg.configHome}/aerc/map.conf";
default = "INBOX";
cache-headers = true;
};
Zoho = {
outgoing = "smtps://email%40thomasave.be@smtp.zoho.com";
outgoing-cred-cmd = "cat ~/.secrets/Aerc/Zoho.key";
source =
"maildir:///home/server/Storage/Thomas/Mail/email@thomasave.be/";
check-mail-cmd =
"ssh server@10.1 /home/server/Containers/mbsync/sync.sh";
check-mail-timeout = "60s";
default = "Inbox";
from = ''"Thomas Avé" <email@thomasave.be>'';
cache-headers = true;
};
UAntwerpen = {
outgoing =
"ssh server@192.168.1.2 /home/server/Containers/mbsync/send.sh";
source =
"maildir:///home/server/Storage/Thomas/Mail/Thomas.Ave@uantwerpen.be";
check-mail-cmd =
"ssh server@10.1 /home/server/Containers/mbsync/sync.sh";
check-mail-timeout = "60s";
default = "Inbox";
from = ''"Thomas Avé" <Thomas.Ave@uantwerpen.be>'';
cache-headers = true;
};
IMEC = {
outgoing = "smtp+insecure://ave57%40imec.be@smtp.thomasave.be:1025";
outgoing-cred-cmd = "cat ~/.secrets/Aerc/IMEC.key";
source =
"maildir:///home/server/Storage/Thomas/Mail/Thomas.Ave@imec.be/";
check-mail-cmd =
"ssh server@10.1 /home/server/Containers/mbsync/sync.sh";
check-mail-timeout = "60s";
default = "Inbox";
from = ''"Thomas Avé" <Thomas.Ave@imec.be>'';
cache-headers = true;
};
NotMuch = {
source = "notmuch:///home/server/Storage/Thomas/Mail/";
check-mail-cmd =
"ssh server@10.1 /home/server/Containers/mbsync/sync.sh";
check-mail-timeout = "60s";
from = ''"Thomas Avé" <Thomas.Ave@uantwerpen.be>'';
query-map = "${config.xdg.configHome}/aerc/map.conf";
default = "INBOX";
cache-headers = true;
};
};
};

View File

@ -66,9 +66,7 @@ in {
home.packages = with pkgs; [ wl-clipboard ];
services.cliphist = {
enable = true;
};
services.cliphist = { enable = true; };
services.hyprpaper = {
enable = true;
@ -202,7 +200,7 @@ in {
"$mainMod, SPACE, togglesplit, # dwindle"
"CONTROL_L ALT_L, L, exec, ${swaylock}"
''
$mainMod, C, exec, cliphist list | awk '{print $0, "\0icon\x1fcom.github.davidmhewitt.clipped"; }' | ${rofi} -dmenu -display-columns 2 | cliphist decode | wl-copy''
$mainMod, C, exec, cliphist list | awk '{print $0, "\0icon\x1fcom.github.davidmhewitt.clipped"; }' | ${rofi} -dmenu -display-columns 2 | cliphist decode | wl-copy''
"$mainMod, Y, exec, ${rofi-ykman}/bin/rofi-ykman"
"$mainMod, N, exec, ${./files/rofi-ssh.sh}"

View File

@ -5,38 +5,38 @@
enable = true;
shellIntegration.enableZshIntegration = true;
font = {
name = "Iosevka Extended";
size = 15;
name = "Iosevka Extended";
size = 15;
};
settings = {
cursor_shape = "block";
cursor_beam_thickness = 10;
scrollback_lines = 100000;
cursor_shape = "block";
cursor_beam_thickness = 10;
scrollback_lines = 100000;
# Theme
background = "#000010";
foreground = "#F8F8F2";
cursor = "#bbbbbb";
selection_background = "#b4d5ff";
color0 = "#121212";
color8 = "#545454";
color1 = "#fa2573";
color9 = "#f5669c";
color2 = "#97e123";
color10 = "#b0e05e";
color3 = "#dfd460";
color11 = "#fef26c";
color4 = "#0f7fcf";
color12 = "#00afff";
color5 = "#8700ff";
color13 = "#af87ff";
color6 = "#42a7cf";
color14 = "#50cdfe";
color7 = "#bbbbbb";
color15 = "#ffffff";
selection_foreground = "#121212";
background_opacity = "0.3";
# Theme
background = "#000010";
foreground = "#F8F8F2";
cursor = "#bbbbbb";
selection_background = "#b4d5ff";
color0 = "#121212";
color8 = "#545454";
color1 = "#fa2573";
color9 = "#f5669c";
color2 = "#97e123";
color10 = "#b0e05e";
color3 = "#dfd460";
color11 = "#fef26c";
color4 = "#0f7fcf";
color12 = "#00afff";
color5 = "#8700ff";
color13 = "#af87ff";
color6 = "#42a7cf";
color14 = "#50cdfe";
color7 = "#bbbbbb";
color15 = "#ffffff";
selection_foreground = "#121212";
background_opacity = "0.3";
};
};
}

View File

@ -1,11 +1,9 @@
{ config, pkgs, ... }:
{
home.file."${config.xdg.configHome}/mpv" = {
source = ./files;
recursive = true;
};
programs.mpv = {
enable = true;
};
home.file."${config.xdg.configHome}/mpv" = {
source = ./files;
recursive = true;
};
programs.mpv = { enable = true; };
}

View File

@ -1,58 +1,57 @@
{ inputs, config, pkgs, ... }:
let
tmux-themepack = pkgs.tmuxPlugins.mkTmuxPlugin {
tmux-themepack = pkgs.tmuxPlugins.mkTmuxPlugin {
pluginName = "tmux-themepack";
rtpFilePath = "themepack.tmux";
version = "unstable-2019-12-22";
src = pkgs.fetchFromGitHub {
owner = "jimeh";
repo = "tmux-themepack";
rev = "7c59902f64dcd7ea356e891274b21144d1ea5948";
sha256 = "sha256-c5EGBrKcrqHWTKpCEhxYfxPeERFrbTuDfcQhsUAbic4=";
owner = "jimeh";
repo = "tmux-themepack";
rev = "7c59902f64dcd7ea356e891274b21144d1ea5948";
sha256 = "sha256-c5EGBrKcrqHWTKpCEhxYfxPeERFrbTuDfcQhsUAbic4=";
};
};
in
{
programs.tmux = {
shell = "${pkgs.zsh}/bin/zsh";
terminal = "screen-256color";
enable = true;
clock24 = true;
shortcut = "a";
escapeTime = 0;
newSession = true;
mouse = true;
keyMode = "vi";
plugins = [
pkgs.tmuxPlugins.vim-tmux-navigator
pkgs.tmuxPlugins.better-mouse-mode
pkgs.tmuxPlugins.yank
{
plugin = tmux-themepack;
extraConfig = ''
set -g @themepack "powerline/double/blue"
set-window-option -g status-left " #S "
set-window-option -g status-right " #{prefix_highlight} \"#(hostname)\" %H:%M %d-%b-%y "
set-window-option -g window-status-format " #I: #W "
set-window-option -g window-status-current-format " #I: #W "
'';
}
];
in {
programs.tmux = {
shell = "${pkgs.zsh}/bin/zsh";
terminal = "screen-256color";
enable = true;
clock24 = true;
shortcut = "a";
escapeTime = 0;
newSession = true;
mouse = true;
keyMode = "vi";
plugins = [
pkgs.tmuxPlugins.vim-tmux-navigator
pkgs.tmuxPlugins.better-mouse-mode
pkgs.tmuxPlugins.yank
{
plugin = tmux-themepack;
extraConfig = ''
set-window-option -g mode-keys vi
bind-key -T copy-mode-vi 'v' send -X begin-selection
bind-key -T copy-mode-vi 'y' send -X copy-selection
bind | split-window -h -c "#{pane_current_path}"
bind - split-window -v -c "#{pane_current_path}"
bind c new-window -c "#{pane_current_path}"
unbind '"'
unbind %
set-option -g xterm-keys on
set -g @themepack "powerline/double/blue"
set-window-option -g status-left " #S "
set-window-option -g status-right " #{prefix_highlight} \"#(hostname)\" %H:%M %d-%b-%y "
set-window-option -g window-status-format " #I: #W "
set-window-option -g window-status-current-format " #I: #W "
'';
};
}
];
extraConfig = ''
set-window-option -g mode-keys vi
bind-key -T copy-mode-vi 'v' send -X begin-selection
bind-key -T copy-mode-vi 'y' send -X copy-selection
bind | split-window -h -c "#{pane_current_path}"
bind - split-window -v -c "#{pane_current_path}"
bind c new-window -c "#{pane_current_path}"
unbind '"'
unbind %
set-option -g xterm-keys on
'';
};
}

View File

@ -23,17 +23,13 @@
TERM = "screen-256color";
PYTHONDONTWRITEBYTECODE = "1";
GOPATH = "${config.xdg.dataHome}/go";
DIRENV_LOG_FORMAT="";
DIRENV_LOG_FORMAT = "";
};
programs.direnv = {
enable = true;
enableZshIntegration = true; # see note on other shells below
nix-direnv.enable = true;
config = {
global = {
hiden_env_diff = true;
};
};
enable = true;
enableZshIntegration = true; # see note on other shells below
nix-direnv.enable = true;
config = { global = { hiden_env_diff = true; }; };
};
programs.command-not-found.enable = true;
programs.zoxide = {