From 27e5ea18c9ecf664e96f93408835394385607f3f Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Mallo Date: Wed, 23 Jul 2025 14:07:06 +0200 Subject: [PATCH] Add NixOS module to control power policy --- m/module/power-policy.nix | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 m/module/power-policy.nix diff --git a/m/module/power-policy.nix b/m/module/power-policy.nix new file mode 100644 index 00000000..a4df4570 --- /dev/null +++ b/m/module/power-policy.nix @@ -0,0 +1,29 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + cfg = config.power.policy; +in +{ + options = { + power.policy = mkOption { + type = lib.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"; + }; + }; + }; +}