From 14737a967691173be76e0c1a77167210b8c2d266 Mon Sep 17 00:00:00 2001 From: Michael Hoang Date: Fri, 16 May 2025 11:05:30 +1000 Subject: [PATCH] defaults: add `com.apple.iCal` for managing Calendar.app --- modules/module-list.nix | 1 + modules/system/defaults-write.nix | 5 +- modules/system/defaults/iCal.nix | 52 +++++++++++++++++++ .../system-defaults-write/activate-user.txt | 15 ++++++ tests/system-defaults-write.nix | 3 ++ 5 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 modules/system/defaults/iCal.nix diff --git a/modules/module-list.nix b/modules/module-list.nix index f0b1d3d..15f6f39 100644 --- a/modules/module-list.nix +++ b/modules/module-list.nix @@ -23,6 +23,7 @@ ./system/defaults/dock.nix ./system/defaults/finder.nix ./system/defaults/hitoolbox.nix + ./system/defaults/iCal.nix ./system/defaults/screencapture.nix ./system/defaults/screensaver.nix ./system/defaults/alf.nix diff --git a/modules/system/defaults-write.nix b/modules/system/defaults-write.nix index a00b0e4..41911a9 100644 --- a/modules/system/defaults-write.nix +++ b/modules/system/defaults-write.nix @@ -27,6 +27,7 @@ let dock = defaultsToList "com.apple.dock" dockFiltered; finder = defaultsToList "com.apple.finder" cfg.finder; hitoolbox = defaultsToList "com.apple.HIToolbox" cfg.hitoolbox; + iCal = defaultsToList "com.apple.iCal" cfg.iCal; magicmouse = defaultsToList "com.apple.AppleMultitouchMouse" cfg.magicmouse; magicmouseBluetooth = defaultsToList "com.apple.driver.AppleMultitouchMouse.mouse" cfg.magicmouse; screencapture = defaultsToList "com.apple.screencapture" cfg.screencapture; @@ -37,7 +38,7 @@ let universalaccess = defaultsToList "com.apple.universalaccess" cfg.universalaccess; ActivityMonitor = defaultsToList "com.apple.ActivityMonitor" cfg.ActivityMonitor; WindowManager = defaultsToList "com.apple.WindowManager" cfg.WindowManager; - controlcenter = defaultsToList "~/Library/Preferences/ByHost/com.apple.controlcenter" cfg.controlcenter; + controlcenter = defaultsToList "~/Library/Preferences/ByHost/com.apple.controlcenter" cfg.controlcenter; CustomUserPreferences = flatten (mapAttrsToList (name: value: defaultsToList name value) cfg.CustomUserPreferences); CustomSystemPreferences = flatten (mapAttrsToList (name: value: defaultsToList name value) cfg.CustomSystemPreferences); @@ -83,6 +84,7 @@ in dock finder hitoolbox + iCal magicmouse magicmouseBluetooth screencapture @@ -108,6 +110,7 @@ in ${concatStringsSep "\n" dock} ${concatStringsSep "\n" finder} ${concatStringsSep "\n" hitoolbox} + ${concatStringsSep "\n" iCal} ${concatStringsSep "\n" magicmouse} ${concatStringsSep "\n" magicmouseBluetooth} ${concatStringsSep "\n" screencapture} diff --git a/modules/system/defaults/iCal.nix b/modules/system/defaults/iCal.nix new file mode 100644 index 0000000..13f1458 --- /dev/null +++ b/modules/system/defaults/iCal.nix @@ -0,0 +1,52 @@ +{ lib, ... }: + +{ + options = { + system.defaults.iCal."first day of week" = lib.mkOption { + type = lib.types.nullOr (lib.types.enum [ + "System Setting" + "Sunday" + "Monday" + "Tuesday" + "Wednesday" + "Thursday" + "Friday" + "Saturday" + ]); + apply = key: if key == null then null else { + "System Setting" = 0; + "Sunday" = 1; + "Monday" = 2; + "Tuesday" = 3; + "Wednesday" = 4; + "Thursday" = 5; + "Friday" = 6; + "Saturday" = 7; + }.${key}; + default = null; + description = '' + Set the day to start week on in the Calendar. The default is "System Setting". + + System Setting means inherit the value from Language & Region. + ''; + }; + + system.defaults.iCal.CalendarSidebarShown = lib.mkOption { + type = lib.types.nullOr lib.types.bool; + default = null; + description = '' + Show calendar list. The default is false. + + This requires restarting `Calendar.app` to show. + ''; + }; + + system.defaults.iCal."TimeZone support enabled" = lib.mkOption { + type = lib.types.nullOr lib.types.bool; + default = null; + description = '' + Turn on time zone support. The default is false. + ''; + }; + }; +} diff --git a/tests/fixtures/system-defaults-write/activate-user.txt b/tests/fixtures/system-defaults-write/activate-user.txt index d93321e..9f48668 100644 --- a/tests/fixtures/system-defaults-write/activate-user.txt +++ b/tests/fixtures/system-defaults-write/activate-user.txt @@ -458,6 +458,21 @@ defaults write com.apple.HIToolbox 'AppleFnUsageType' $' 2 ' +defaults write com.apple.iCal 'CalendarSidebarShown' $' + + + +' +defaults write com.apple.iCal 'TimeZone support enabled' $' + + + +' +defaults write com.apple.iCal 'first day of week' $' + + +4 +' defaults write com.apple.screencapture 'include-date' $' diff --git a/tests/system-defaults-write.nix b/tests/system-defaults-write.nix index 35ff853..6b06dd2 100644 --- a/tests/system-defaults-write.nix +++ b/tests/system-defaults-write.nix @@ -99,6 +99,9 @@ system.defaults.finder.ShowMountedServersOnDesktop = false; system.defaults.finder.ShowRemovableMediaOnDesktop = false; system.defaults.hitoolbox.AppleFnUsageType = "Show Emoji & Symbols"; + system.defaults.iCal."first day of week" = "Wednesday"; + system.defaults.iCal.CalendarSidebarShown = true; + system.defaults.iCal."TimeZone support enabled" = true; system.defaults.screencapture.location = "/tmp"; system.defaults.screencapture.target = "file"; system.defaults.screencapture.include-date = true;