2023-11-19 00:52:02 +01:00
|
|
|
{ config, lib, ... }:
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.power;
|
|
|
|
|
|
|
|
types = lib.types;
|
|
|
|
|
|
|
|
onOff = cond: if cond then "on" else "off";
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
power.restartAfterPowerFailure = lib.mkOption {
|
|
|
|
type = types.nullOr types.bool;
|
|
|
|
default = null;
|
|
|
|
description = ''
|
|
|
|
Whether to restart the computer after a power failure.
|
2024-12-27 21:36:31 +01:00
|
|
|
|
|
|
|
Option is not supported on all devices.
|
2023-11-19 00:52:02 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
power.restartAfterFreeze = lib.mkOption {
|
|
|
|
type = types.nullOr types.bool;
|
|
|
|
default = null;
|
|
|
|
description = ''
|
|
|
|
Whether to restart the computer after a system freeze.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = {
|
|
|
|
|
|
|
|
system.activationScripts.power.text = ''
|
|
|
|
echo "configuring power..." >&2
|
|
|
|
|
|
|
|
${lib.optionalString (cfg.restartAfterPowerFailure != null) ''
|
2024-12-29 12:13:54 +01:00
|
|
|
systemsetup -setRestartPowerFailure \
|
|
|
|
'${onOff cfg.restartAfterPowerFailure}' &> /dev/null
|
2023-11-19 00:52:02 +01:00
|
|
|
''}
|
|
|
|
|
|
|
|
${lib.optionalString (cfg.restartAfterFreeze != null) ''
|
|
|
|
systemsetup -setRestartFreeze \
|
|
|
|
'${onOff cfg.restartAfterFreeze}' &> /dev/null
|
|
|
|
''}
|
|
|
|
'';
|
|
|
|
|
|
|
|
};
|
|
|
|
}
|