Skip to content

Commit

Permalink
Merge pull request #1241 from gnammix/power_conditional_setRestartPow…
Browse files Browse the repository at this point in the history
…erFailure

power: restartAfterPowerFailure option is carried out conditionally
  • Loading branch information
Enzime authored Jan 4, 2025
2 parents 6a1fdb2 + 492a720 commit 3feaf37
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions modules/power/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ in
default = null;
description = ''
Whether to restart the computer after a power failure.
Option is not supported on all devices.
'';
};

Expand Down
10 changes: 10 additions & 0 deletions modules/system/checks.nix
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,15 @@ let
exit 2
fi
'';

# some mac devices, notably notebook do not support restartAfterPowerFailure option
restartAfterPowerFailureIsSupported = ''
if sudo /usr/sbin/systemsetup -getRestartPowerFailure | grep -q "Not supported"; then
printf >&2 "�[1;31merror: restarting after power failure is not supported on your machine�[0m\n" >&2
printf >&2 "Please ensure that `power.restartAfterPowerFailure` is not set.\n" >&2
exit 2
fi
'';
in

{
Expand Down Expand Up @@ -357,6 +366,7 @@ in
(mkIf cfg.verifyNixPath nixPath)
oldSshAuthorizedKeysDirectory
(mkIf config.homebrew.enable homebrewInstalled)
(mkIf (config.power.restartAfterPowerFailure != null) restartAfterPowerFailureIsSupported)
];

system.activationScripts.checks.text = ''
Expand Down

0 comments on commit 3feaf37

Please sign in to comment.