LnL7 / nix-darwin

nix modules for darwin
MIT License
3.19k stars 457 forks source link

Night Shift schedule #1046

Open DimitarNestorov opened 2 months ago

DimitarNestorov commented 2 months ago

It would be awesome if nix-darwin could schedule Night Shift. The preferences are located in /var/root/Library/Preferences/com.apple.CoreBrightness.plist

Some scripts I found online that set the Night Shift schedule:

https://gist.github.com/thomasfinch/14bd3181799734c872d2ad3b207cc01c#file-nightshiftcontrol-sh

https://github.com/LukeChannings/dotfiles/blob/7cb3171b5354761c9aef7b6f1094019ef8701a17/install.macos#L413-L433


EDIT: I think I figured it out but it would be awesome if I didn't have to figure out the user UUID myself:

{
  system.defaults = {
    CustomSystemPreferences = {
      "/var/root/Library/Preferences/com.apple.CoreBrightness.plist" = let
        userId = builtins.readFile (pkgs.runCommand "user-id" {} "/usr/bin/dscl . -read /Users/dimitar GeneratedUID | /usr/bin/sed 's/GeneratedUID: //' | /usr/bin/tr -d \\\\n > $out");
      in {
        "CBUser-${userId}" = {
          CBBlueLightReductionCCTTargetRaw = "3433.05";
          CBBlueReductionStatus = {
            AutoBlueReductionEnabled = 1;
            BlueLightReductionAlgoOverride = 0;
            BlueLightReductionDisableScheduleAlertCounter = 3;
            BlueLightReductionSchedule = {
              DayStartHour = 7;
              DayStartMinute = 0;
              NightStartHour = 22;
              NightStartMinute = 0;
            };
            BlueReductionAvailable = 1;
            BlueReductionEnabled = 0;
            BlueReductionMode = 1;
            BlueReductionSunScheduleAllowed = 1;
            Version = 1;
          };
          CBColorAdaptationEnabled = 1;
        };
      };
    };
  };
}
kimjongbing commented 1 month ago

this would be amazing to add