mirror of
https://github.com/LnL7/nix-darwin.git
synced 2024-12-14 11:57:34 +00:00
48 lines
1 KiB
Nix
48 lines
1 KiB
Nix
|
{ 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.
|
||
|
'';
|
||
|
};
|
||
|
|
||
|
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) ''
|
||
|
systemsetup -setRestartPowerFailure \
|
||
|
'${onOff cfg.restartAfterPowerFailure}' &> /dev/null
|
||
|
''}
|
||
|
|
||
|
${lib.optionalString (cfg.restartAfterFreeze != null) ''
|
||
|
systemsetup -setRestartFreeze \
|
||
|
'${onOff cfg.restartAfterFreeze}' &> /dev/null
|
||
|
''}
|
||
|
'';
|
||
|
|
||
|
};
|
||
|
}
|