diff --git a/machines/solis/configuration.nix b/machines/solis/configuration.nix index de07dda..48c22ea 100644 --- a/machines/solis/configuration.nix +++ b/machines/solis/configuration.nix @@ -16,23 +16,5 @@ networking.hostName = "solis"; - systemd.timers."backupSyncthing" = { - wantedBy = ["timers.target"]; - timerConfig = { - OnCalendar = "weekly"; - Persistent = true; - }; - }; - - systemd.services."backupSyncthing" = { - script = '' - /home/horseman/nix-config/misc/backup.sh - ''; - serviceConfig = { - Type = "oneshot"; - User = "horseman"; - }; - }; - system.stateVersion = "24.11"; } diff --git a/machines/solis/modules.nix b/machines/solis/modules.nix index d154477..f418171 100644 --- a/machines/solis/modules.nix +++ b/machines/solis/modules.nix @@ -37,5 +37,9 @@ terminal = { zsh.enable = true; }; + + timers = { + backup.enable = true; + }; }; } diff --git a/machines/terra/configuration.nix b/machines/terra/configuration.nix index e471282..a4a6d22 100644 --- a/machines/terra/configuration.nix +++ b/machines/terra/configuration.nix @@ -16,24 +16,5 @@ networking.hostName = "terra"; - systemd.timers."enable-wol" = { - wantedBy = ["timers.target"]; - timerConfig = { - OnBootSec = "5m"; - OnUnitActiveSec = "1m"; - Unit = "enable-wol.service"; - }; - }; - - systemd.services."enable-wol" = { - script = '' - /home/horseman/nix-config/misc/startup.sh - ''; - serviceConfig = { - Type = "oneshot"; - User = "root"; - }; - }; - system.stateVersion = "24.11"; } diff --git a/machines/terra/modules.nix b/machines/terra/modules.nix index 1519f46..8e8ad0a 100644 --- a/machines/terra/modules.nix +++ b/machines/terra/modules.nix @@ -50,5 +50,9 @@ terminal = { zsh.enable = true; }; + + timers = { + wol.enable = true; + }; }; } diff --git a/modules/timers/backup.nix b/modules/timers/backup.nix new file mode 100644 index 0000000..783b622 --- /dev/null +++ b/modules/timers/backup.nix @@ -0,0 +1,40 @@ +{ + inputs, + outputs, + lib, + config, + pkgs, + ... +}: let + inherit (lib) mkEnableOption mkIf mkOption types; + cfg = config.horseman.timers.backup; + homeCfg = config.horseman; +in { + options = { + horseman.timers.backup = { + enable = mkEnableOption "Enables the backup service"; + }; + }; + + config = mkIf cfg.enable { + assert homeCfg.network.syncthing || throw "Syncthing has not been enabled on this machine, refusing to add timer."; + + systemd.timers."backupsyncthing" = { + wantedby = ["timers.target"]; + timerconfig = { + oncalendar = "weekly"; + persistent = true; + }; + }; + + systemd.services."backupsyncthing" = { + script = '' + /home/horseman/nix-config/misc/backup.sh + ''; + serviceconfig = { + type = "oneshot"; + user = "horseman"; + }; + }; + }; +} diff --git a/modules/timers/wol.nix b/modules/timers/wol.nix new file mode 100644 index 0000000..e62e833 --- /dev/null +++ b/modules/timers/wol.nix @@ -0,0 +1,41 @@ +{ + inputs, + outputs, + lib, + config, + pkgs, + ... +}: let + inherit (lib) mkEnableOption mkIf mkOption types; + cfg = config.horseman.timers.wol; + homeCfg = config.horseman; +in { + options = { + horseman.timers.wol = { + enable = mkEnableOption "Enables Wake on LAN on boot"; + }; + }; + + config = mkIf cfg.enable { + assert homeCfg.apps.terminal || throw "wakeonlan has not been not installed on this machine, refusing to add timer."; + + systemd.timers."enable-wol" = { + wantedBy = ["timers.target"]; + timerConfig = { + OnBootSec = "5m"; + OnUnitActiveSec = "1m"; + Unit = "enable-wol.service"; + }; + }; + + systemd.services."enable-wol" = { + script = '' + /home/horseman/nix-config/misc/startup.sh + ''; + serviceConfig = { + Type = "oneshot"; + User = "root"; + }; + }; + }; +}