2024-06-03 20:09:38 +02:00
|
|
|
{ inputs, config, pkgs, ... }:
|
|
|
|
let
|
|
|
|
mkTimer = { name, interval, serviceScript }:
|
|
|
|
let
|
|
|
|
timerName = "${name}-timer";
|
|
|
|
serviceName = "${name}-service";
|
|
|
|
in
|
|
|
|
{
|
|
|
|
systemd.timers.${timerName} = {
|
|
|
|
wantedBy = [ "timers.target" ];
|
|
|
|
timerConfig = {
|
|
|
|
OnBootSec = interval;
|
|
|
|
OnUnitActiveSec = interval;
|
|
|
|
Unit = "${serviceName}.service";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.services.${serviceName} = {
|
|
|
|
script = ''
|
|
|
|
set -eu
|
|
|
|
${serviceScript}
|
|
|
|
'';
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "oneshot";
|
|
|
|
User = "root";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2024-06-03 21:04:20 +02:00
|
|
|
disk_timer = mkTimer {
|
2024-06-03 20:09:38 +02:00
|
|
|
name = "disk_check";
|
|
|
|
interval = "1h";
|
|
|
|
serviceScript = toString (pkgs.writeShellScript "disk_check" ''
|
|
|
|
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
|
|
|
|
'');
|
2024-06-03 21:04:20 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
in
|
|
|
|
{
|
|
|
|
home.username = "server";
|
|
|
|
home.homeDirectory = "/home/server";
|
|
|
|
nix = {
|
|
|
|
package = pkgs.nix;
|
|
|
|
settings.use-xdg-base-directories = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
# home.profileDirectory = "${config.xdg.stateHome}/nix/profile";
|
|
|
|
imports = [
|
|
|
|
(import ./common.nix { inherit inputs config pkgs; })
|
|
|
|
./ssh
|
|
|
|
];
|
|
|
|
home.sessionVariables = {
|
|
|
|
NIX_PATH = "${config.xdg.stateHome}/nix/profiles/channels/";
|
|
|
|
LANG = "en_US.UTF-8";
|
|
|
|
};
|
2024-06-03 20:09:38 +02:00
|
|
|
}
|