Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Power related options (sleep, wake-on-lan, restart after power failure, ...) #813

Merged
merged 2 commits into from
Oct 25, 2024

Conversation

PhilipBorgesen
Copy link
Contributor

@PhilipBorgesen PhilipBorgesen commented Nov 19, 2023

Hey there, I've recently picked up nix-darwin to configure a Mac Mini M2 as a home server.
I need to configure some power related options that nix-darwin currently does not offer, so I would like to contribute them.

This pull request adds:

  • networking.wakeOnLan.enable
  • power.restartAfterPowerFailure
  • power.restartAfterFreeze
  • power.sleep.computer
  • power.sleep.display
  • power.sleep.harddisk
  • power.sleep.allowSleepByPowerButton

The options are implemented by means of the systemsetup command that also is used for the time.timezone option.
I believe this is the command that System Settings uses behind the screen.

I've tried to guess where it made most sense to add the new options.
I've added a new power module; maybe it would make more sense to place the restartXXX and sleep options under system instead. I'm prepared to move them elsewhere as per your feedback.

Thanks for creating nix-darwin!

@@ -94,6 +95,16 @@ in
default = [];
description = lib.mdDoc "The list of search paths used when resolving domain names.";
};

networking.wakeOnLan = mkOption {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Name of option and placement inspired by the NixOS option: networking.interfaces.<name>.wakeOnLan.enable

@@ -117,6 +128,10 @@ in
''}

${setNetworkServices}

${optionalString (cfg.wakeOnLan != null) ''
systemsetup -setWakeOnNetworkAccess '${onOff cfg.wakeOnLan}' &> /dev/null
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The systemsetup stdout and stderr are silenced:

  • The changed value is echoed on stdout, e.g. setwakeonnetworkaccess: On.
  • An error is reported on stderr, but the command succeeds as reflected by the corresponding get command and System Settings. Example error: 2023-11-18 15:47:54.640 systemsetup[4589:139580] ### Error:-99 File:/AppleInternal/Library/BuildRoots/11aa8fb2-5f4b-11ee-bc7f-926038f30c31/Library/Caches/com.apple.xbs/Sources/Admin/InternetServices.m Line:379

The above observations apply to the new power and power.sleep options as well.

Copy link
Contributor Author

@PhilipBorgesen PhilipBorgesen Nov 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see the silencing matches the work done here: #781

@mattpolzin
Copy link
Contributor

@Enzime I hope you don't mind if I ping you on this to get your thoughts. Not my PR but configuring power management would be nice for me now that I am considering retiring my old Mac to be headless.

@anderslundstedt
Copy link

Any progress on this?

modules/power/default.nix Outdated Show resolved Hide resolved
modules/power/sleep.nix Outdated Show resolved Hide resolved
@PhilipBorgesen PhilipBorgesen force-pushed the power-related-options branch 2 times, most recently from 2604d65 to 4c40a38 Compare October 23, 2024 07:43
Copy link
Collaborator

@Enzime Enzime left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also add some tests?

modules/power/default.nix Outdated Show resolved Hide resolved
modules/power/default.nix Outdated Show resolved Hide resolved
modules/power/default.nix Outdated Show resolved Hide resolved
modules/power/sleep.nix Outdated Show resolved Hide resolved
modules/power/sleep.nix Outdated Show resolved Hide resolved
@PhilipBorgesen
Copy link
Contributor Author

Tests added

Copy link
Collaborator

@Enzime Enzime left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Thanks for the contribution

@Enzime Enzime merged commit 8c67575 into LnL7:master Oct 25, 2024
5 of 6 checks passed
@PhilipBorgesen PhilipBorgesen deleted the power-related-options branch October 25, 2024 02:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants