diff --git a/m/common/base.nix b/m/common/base.nix index bb0e4e22..cdd1dc19 100644 --- a/m/common/base.nix +++ b/m/common/base.nix @@ -3,6 +3,7 @@ # Includes the basic configuration for an Intel server. imports = [ ./base/agenix.nix + ./base/always-power-on.nix ./base/august-shutdown.nix ./base/boot.nix ./base/env.nix diff --git a/m/common/base/always-power-on.nix b/m/common/base/always-power-on.nix new file mode 100644 index 00000000..cdee12c6 --- /dev/null +++ b/m/common/base/always-power-on.nix @@ -0,0 +1,8 @@ +{ + imports = [ + ../../module/power-policy.nix + ]; + + # Turn on as soon as we have power + power.policy = "always-on"; +} diff --git a/m/common/base/august-shutdown.nix b/m/common/base/august-shutdown.nix index 624340c4..7f79c849 100644 --- a/m/common/base/august-shutdown.nix +++ b/m/common/base/august-shutdown.nix @@ -1,12 +1,12 @@ { - # Shutdown all machines on August 2nd at 11:00 AM, so we can protect the + # Shutdown all machines on August 3rd at 22:00, so we can protect the # hardware from spurious electrical peaks on the yearly electrical cut for # manteinance that starts on August 4th. systemd.timers.august-shutdown = { - description = "Shutdown on August 2nd for maintenance"; + description = "Shutdown on August 3rd for maintenance"; wantedBy = [ "timers.target" ]; timerConfig = { - OnCalendar = "*-08-02 11:00:00"; + OnCalendar = "*-08-03 22:00:00"; RandomizedDelaySec = "10min"; Unit = "systemd-poweroff.service"; }; diff --git a/m/fox/configuration.nix b/m/fox/configuration.nix index fd5cdc8b..436a85ec 100644 --- a/m/fox/configuration.nix +++ b/m/fox/configuration.nix @@ -8,6 +8,10 @@ ../module/nvidia.nix ]; + # Don't turn off on August as UPC has different dates. + # Fox works fine on power cuts. + systemd.timers.august-shutdown.enable = false; + # Select the this using the ID to avoid mismatches boot.loader.grub.device = "/dev/disk/by-id/wwn-0x500a07514b0c1103"; diff --git a/m/module/power-policy.nix b/m/module/power-policy.nix new file mode 100644 index 00000000..87c04140 --- /dev/null +++ b/m/module/power-policy.nix @@ -0,0 +1,31 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + cfg = config.power.policy; +in +{ + options = { + power.policy = mkOption { + type = types.nullOr (types.enum [ "always-on" "previous" "always-off" ]); + default = null; + description = "Set power policy to use via IPMI."; + }; + }; + + config = mkIf (cfg != null) { + systemd.services."power-policy" = { + description = "Set power policy to use via IPMI"; + wantedBy = [ "multi-user.target" ]; + serviceConfig = { + ExecStart = "${pkgs.ipmitool}/bin/ipmitool chassis policy ${cfg}"; + Type = "oneshot"; + Restart = "on-failure"; + RestartSec = "5s"; + StartLimitBurst = "10"; + StartLimitIntervalSec = "10m"; + }; + }; + }; +}