testsAndMisc/linux_configuration/nix-poc/modules/arch-parity/system-maintenance.nix
Krzysztof kuhy Rudnicki 42a66a1419 refactor(linux_configuration/scripts): split all scripts into single_use/ and periodic_background/
- Move all linux_configuration scripts into two semantic categories:
  - single_use/: scripts run once manually (fresh install, fixes, setup)
  - periodic_background/: scripts run by systemd timers or daemons
- Preserve existing subdirectory structure within each category
- Fix lib/common.sh source paths for new directory depths
- Fix CONFIG_DIR depth in setup_periodic_system.sh and check_and_enable_services.sh
- Update all references in tests, fresh-install/main.sh, nix modules, and docs
- Fix check_polling_antipatterns.sh false positives (||, regex |, case patterns, jq strings)
- Fix pre-existing mypy exclusion path and type annotations for moved tools/ directory
- Rewrite check_polling_antipatterns.sh using awk (no bash regex loops); add require_serial: true
2026-05-15 00:32:35 +02:00

120 lines
3.6 KiB
Nix

{ config, lib, pkgs, ... }:
let
cfg = config.linuxConfigPoc;
repo = toString cfg.repoPath;
commonScriptPath = with pkgs; [
bash
coreutils
curl
findutils
gawk
gnugrep
gnused
procps
util-linux
];
in {
config = lib.mkIf cfg.enable {
systemd.services.periodic-system-maintenance = {
description = "Periodic System Maintenance (Pacman Wrapper & Hosts File)";
after = [ "network-online.target" ];
wants = [ "network-online.target" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
Type = "oneshot";
User = "root";
ExecStart = "${repo}/scripts/periodic_background/system-maintenance/bin/periodic-system-maintenance.sh";
StandardOutput = "journal";
StandardError = "journal";
TimeoutStartSec = "300";
TimeoutStopSec = "30";
Restart = "no";
};
path = commonScriptPath;
};
systemd.timers.periodic-system-maintenance = {
description = "Run Periodic System Maintenance every hour";
wantedBy = [ "timers.target" ];
timerConfig = {
OnCalendar = "hourly";
OnBootSec = "5min";
RandomizedDelaySec = "300";
Persistent = true;
};
unitConfig = {
Requires = "periodic-system-maintenance.service";
};
};
systemd.services.periodic-system-startup = {
description = "System Maintenance on Startup (Pacman Wrapper & Hosts File)";
after = [ "network-online.target" "systemd-resolved.service" ];
wants = [ "network-online.target" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
Type = "oneshot";
User = "root";
ExecStart = "${repo}/scripts/periodic_background/system-maintenance/bin/periodic-system-maintenance.sh";
StandardOutput = "journal";
StandardError = "journal";
RemainAfterExit = true;
TimeoutStartSec = "300";
TimeoutStopSec = "30";
};
path = commonScriptPath;
};
systemd.services.hosts-file-monitor = {
description = "Hosts File Monitor and Auto-Restore Service";
after = [ "network-online.target" ];
wants = [ "network-online.target" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
Type = "simple";
User = "root";
ExecStart = "${repo}/scripts/periodic_background/system-maintenance/bin/hosts-file-monitor.sh";
Restart = "always";
RestartSec = "10";
StandardOutput = "journal";
StandardError = "journal";
NoNewPrivileges = false;
PrivateTmp = true;
MemoryMax = "50M";
CPUQuota = "10%";
};
path = commonScriptPath;
};
systemd.services.auto-system-update = {
description = "Automatic System Update (pacman + yay AUR)";
after = [ "network-online.target" ];
wants = [ "network-online.target" ];
serviceConfig = {
Type = "oneshot";
User = "root";
ExecStart = "${repo}/scripts/periodic_background/system-maintenance/bin/auto-system-update.sh";
StandardOutput = "journal";
StandardError = "journal";
TimeoutStartSec = "1800";
TimeoutStopSec = "30";
Restart = "no";
};
path = commonScriptPath;
};
systemd.timers.auto-system-update = {
description = "Run Automatic System Update daily";
wantedBy = [ "timers.target" ];
timerConfig = {
OnCalendar = "*-*-* 04:00:00";
RandomizedDelaySec = "1800";
Persistent = true;
};
unitConfig = {
Requires = "auto-system-update.service";
};
};
};
}