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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

PhilipBorgesen
Copy link

@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
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
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
Author

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.

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.

None yet

2 participants