From a47dd2ce661c5cf1e1c2bbec4377f13e4600b7bb Mon Sep 17 00:00:00 2001 From: angel <78835633+Iamanaws@users.noreply.github.com> Date: Fri, 21 Feb 2025 12:44:13 -0800 Subject: [PATCH 1/8] controlcenter: add new options and update existing mappings - Added new options for AccessibilityShortcuts, Battery (enum mode), Hearing, KeyboardBrightness, MusicRecognition, and updated UserSwitcher. - Updated existing options (Display, FocusModes, NowPlaying, ScreenMirroring, Sound) to use enum types with refined mapping values. --- modules/system/defaults/controlcenter.nix | 314 +++++++++++++++--- .../system-defaults-write/activate-user.txt | 57 +++- tests/system-defaults-write.nix | 29 +- 3 files changed, 337 insertions(+), 63 deletions(-) diff --git a/modules/system/defaults/controlcenter.nix b/modules/system/defaults/controlcenter.nix index 91532fa9..80fa4c8b 100644 --- a/modules/system/defaults/controlcenter.nix +++ b/modules/system/defaults/controlcenter.nix @@ -3,41 +3,24 @@ { options = { - system.defaults.controlcenter.BatteryShowPercentage = lib.mkOption { - type = lib.types.nullOr lib.types.bool; - default = null; + system.defaults.controlcenter.AccessibilityShortcuts = lib.mkOption { + type = lib.types.nullOr (lib.types.enum [ "both" "menuBar" "controlCenter" "hide" ]); + default = null; + apply = v: + if v == null then null + else if v == "both" then 3 + else if v == "menuBar" then 6 + else if v == "controlCenter" then 9 + else if v == "hide" then 12 + else 12; description = '' - Apple menu > System Preferences > Control Center > Battery + Apple menu > System Preferences > Control Center > Accessibility Shortcuts - Show a battery percentage in menu bar. Default is null. - ''; - }; - - system.defaults.controlcenter.Sound = lib.mkOption { - type = lib.types.nullOr lib.types.bool; - apply = v: if v == null then null else if v == true then 18 else 24; - default = null; - description = '' - Apple menu > System Preferences > Control Center > Sound - - Show a sound control in menu bar . Default is null. - - 18 = Display icon in menu bar - 24 = Hide icon in menu bar - ''; - }; - - system.defaults.controlcenter.Bluetooth = lib.mkOption { - type = lib.types.nullOr lib.types.bool; - apply = v: if v == null then null else if v == true then 18 else 24; - default = null; - description = '' - Apple menu > System Preferences > Control Center > Bluetooth - - Show a bluetooth control in menu bar. Default is null. - - 18 = Display icon in menu bar - 24 = Hide icon in menu bar + Options: + both - Show in Menu Bar and Control Center (3) + menuBar - Show in Menu Bar only (6) + controlCenter - Show in Control Center only (1 or 9) + hide - Don't Show (2, 4, 8, or 12) ''; }; @@ -50,50 +33,273 @@ Show a AirDrop control in menu bar. Default is null. - 18 = Display icon in menu bar - 24 = Hide icon in menu bar + 18 = Show in Menu Bar + 24 = Don't Show in Menu Bar + ''; + }; + + system.defaults.controlcenter.Battery = lib.mkOption { + type = lib.types.nullOr (lib.types.enum [ "both" "menuBar" "controlCenter" "hide" ]); + default = null; + apply = v: + if v == null then null + else if v == "both" then 3 + else if v == "menuBar" then 4 + else if v == "controlCenter" then 9 + else if v == "hide" then 12 + else 4; + description = '' + Apple menu > System Preferences > Control Center > Battery + + Options: + both - Show in Menu Bar and Control Center (3) + menuBar - Show in Menu Bar only (6) + controlCenter - Show in Control Center only (1 or 9) + hide - Don't Show (2, 4, 8, or 12) + ''; + }; + + system.defaults.controlcenter.BatteryShowEnergyMode = lib.mkOption { + type = lib.types.nullOr lib.types.bool; + default = null; + description = '' + Apple menu > System Preferences > Control Center > Battery + + Show a battery energy mode. Default is null. + + false - "When Active" + true - "Always" + ''; + }; + + system.defaults.controlcenter.BatteryShowPercentage = lib.mkOption { + type = lib.types.nullOr lib.types.bool; + default = null; + description = '' + Apple menu > System Preferences > Control Center > Battery + + Show a battery percentage in menu bar. Default is null. + ''; + }; + + system.defaults.controlcenter.Bluetooth = lib.mkOption { + type = lib.types.nullOr lib.types.bool; + apply = v: if v == null then null else if v == true then 18 else 24; + default = null; + description = '' + Apple menu > System Preferences > Control Center > Bluetooth + + Show a bluetooth control in menu bar. Default is null. + + 18 = Show in Menu Bar + 24 = Don't Show in Menu Bar ''; }; system.defaults.controlcenter.Display = lib.mkOption { - type = lib.types.nullOr lib.types.bool; - apply = v: if v == null then null else if v == true then 18 else 24; - default = null; + type = lib.types.nullOr (lib.types.enum [ "whenActive" "hide" "always" ]); + apply = v: + if v == null then null + else if v == "always" then 18 + else if v == "hide" then 8 + else if v == "whenActive" then 2 + else 2; + default = null; description = '' - Apple menu > System Preferences > Control Center > Display + Apple menu > System Preferences > Control Center > Display - Show a Screen Brightness control in menu bar. Default is null. - - 18 = Display icon in menu bar - 24 = Hide icon in menu bar + Options: + whenActive - Show When Active (2) + hide - Don't Show in Menu Bar (8) + always - Always Show in Menu Bar (18) ''; }; system.defaults.controlcenter.FocusModes = lib.mkOption { - type = lib.types.nullOr lib.types.bool; - apply = v: if v == null then null else if v == true then 18 else 24; - default = null; + type = lib.types.nullOr (lib.types.enum [ "whenActive" "hide" "always" ]); + apply = v: + if v == null then null + else if v == "always" then 18 + else if v == "hide" then 8 + else if v == "whenActive" then 2 + else 2; + default = null; description = '' - Apple menu > System Preferences > Control Center > Focus + Apple menu > System Preferences > Control Center > Focus - Show a Focus control in menu bar. Default is null. + Options: + whenActive - Show When Active (2) + hide - Don't Show in Menu Bar (8) + always - Always Show in Menu Bar (18) + ''; + }; - 18 = Display icon in menu bar - 24 = Hide icon in menu bar + system.defaults.controlcenter.Hearing = lib.mkOption { + type = lib.types.nullOr (lib.types.enum [ "both" "menuBar" "controlCenter" "hide" ]); + default = null; + apply = v: + if v == null then null + else if v == "both" then 3 + else if v == "menuBar" then 6 + else if v == "controlCenter" then 9 + else if v == "hide" then 12 + else 12; + description = '' + Apple menu > System Preferences > Control Center > Hearing + + Options: + both - Show in Menu Bar and Control Center (3) + menuBar - Show in Menu Bar only (6) + controlCenter - Show in Control Center only (1 or 9) + hide - Don't Show (2, 4, 8, or 12) + ''; + }; + + system.defaults.controlcenter.KeyboardBrightness = lib.mkOption { + type = lib.types.nullOr (lib.types.enum [ "both" "menuBar" "controlCenter" "hide" ]); + default = null; + apply = v: + if v == null then null + else if v == "both" then 3 + else if v == "menuBar" then 6 + else if v == "controlCenter" then 9 + else if v == "hide" then 12 + else 12; + description = '' + Apple menu > System Preferences > Control Center > Keyboard Brightness + + Options: + both - Show in Menu Bar and Control Center (3) + menuBar - Show in Menu Bar only (6) + controlCenter - Show in Control Center only (1 or 9) + hide - Don't Show (2, 4, 8, or 12) + ''; + }; + + system.defaults.controlcenter.MusicRecognition = lib.mkOption { + type = lib.types.nullOr (lib.types.enum [ "both" "menuBar" "controlCenter" "hide" ]); + default = null; + apply = v: + if v == null then null + else if v == "both" then 3 + else if v == "menuBar" then 6 + else if v == "controlCenter" then 9 + else if v == "hide" then 12 + else 12; + description = '' + Apple menu > System Preferences > Control Center > Music Recognition + + Options: + both - Show in Menu Bar and Control Center (3) + menuBar - Show in Menu Bar only (6) + controlCenter - Show in Control Center only (1 or 9) + hide - Don't Show (2, 4, 8, or 12) ''; }; system.defaults.controlcenter.NowPlaying = lib.mkOption { + type = lib.types.nullOr (lib.types.enum [ "whenActive" "hide" "always" ]); + apply = v: + if v == null then null + else if v == "always" then 18 + else if v == "hide" then 8 + else if v == "whenActive" then 2 + else 2; + default = null; + description = '' + Apple menu > System Preferences > Control Center > Now Playing + + Options: + whenActive - Show When Active (2) + hide - Don't Show in Menu Bar (8) + always - Always Show in Menu Bar (18) + ''; + }; + + system.defaults.controlcenter.ScreenMirroring = lib.mkOption { + type = lib.types.nullOr (lib.types.enum [ "whenActive" "hide" "always" ]); + apply = v: + if v == null then null + else if v == "always" then 18 + else if v == "hide" then 8 + else if v == "whenActive" then 2 + else 2; + default = null; + description = '' + Apple menu > System Preferences > Control Center > Screen Mirroring + + Options: + whenActive - Show When Active (2) + hide - Don't Show in Menu Bar (8) + always - Always Show in Menu Bar (18) + ''; + }; + + system.defaults.controlcenter.Sound = lib.mkOption { + type = lib.types.nullOr (lib.types.enum [ "whenActive" "hide" "always" ]); + apply = v: + if v == null then null + else if v == "always" then 18 + else if v == "hide" then 8 + else if v == "whenActive" then 2 + else 2; + default = null; + description = '' + Apple menu > System Preferences > Control Center > Sound + + Options: + whenActive - Show When Active (2) + hide - Don't Show in Menu Bar (8) + always - Always Show in Menu Bar (18) + ''; + }; + + system.defaults.controlcenter.StageManager = lib.mkOption { + type = lib.types.nullOr lib.types.bool; + apply = v: if v == null then null else if v == true then 2 else 8; + default = null; + description = '' + Apple menu > System Preferences > Control Center > Stage Manager + + Show a Wi-Fi control in menu bar. Default is null. + + 2 = Show in Menu Bar + 8 = Don't Show in Menu Bar + ''; + }; + + system.defaults.controlcenter.UserSwitcher = lib.mkOption { + type = lib.types.nullOr (lib.types.enum [ "both" "menuBar" "controlCenter" "hide" ]); + apply = v: + if v == null then null + else if v == "both" then 19 + else if v == "menuBar" then 22 + else if v == "controlCenter" then 25 + else if v == "hide" then 28 + else 28; + default = null; + description = '' + Apple menu > System Preferences > Control Center > Fast User Switching + + Options: + both - Show in Menu Bar and Control Center (19) + menuBar - Show in Menu Bar (22) + controlCenter - Show in Control Center (25) + hide - Don't Show (28) + ''; + }; + + system.defaults.controlcenter.WiFi = lib.mkOption { type = lib.types.nullOr lib.types.bool; apply = v: if v == null then null else if v == true then 18 else 24; default = null; description = '' - Apple menu > System Preferences > Control Center > Now Playing + Apple menu > System Preferences > Control Center > Wi-Fi - Show a Now Playing control in menu bar. Default is null. + Show a Wi-Fi control in menu bar. Default is null. - 18 = Display icon in menu bar - 24 = Hide icon in menu bar + 18 = Show in Menu Bar + 24 = Don't Show in Menu Bar ''; }; }; diff --git a/tests/fixtures/system-defaults-write/activate-user.txt b/tests/fixtures/system-defaults-write/activate-user.txt index d93321ef..7762bfe2 100644 --- a/tests/fixtures/system-defaults-write/activate-user.txt +++ b/tests/fixtures/system-defaults-write/activate-user.txt @@ -616,11 +616,26 @@ defaults write com.apple.WindowManager 'StandardHideWidgets' $' ' +defaults write ~/Library/Preferences/ByHost/com.apple.controlcenter 'AccessibilityShortcuts' $' + + +3 +' defaults write ~/Library/Preferences/ByHost/com.apple.controlcenter 'AirDrop' $' 18 ' +defaults write ~/Library/Preferences/ByHost/com.apple.controlcenter 'Battery' $' + + +4 +' +defaults write ~/Library/Preferences/ByHost/com.apple.controlcenter 'BatteryShowEnergyMode' $' + + + +' defaults write ~/Library/Preferences/ByHost/com.apple.controlcenter 'BatteryShowPercentage' $' @@ -634,20 +649,56 @@ defaults write ~/Library/Preferences/ByHost/com.apple.controlcenter 'Bluetooth' defaults write ~/Library/Preferences/ByHost/com.apple.controlcenter 'Display' $' -24 +2 ' defaults write ~/Library/Preferences/ByHost/com.apple.controlcenter 'FocusModes' $' -24 +2 +' +defaults write ~/Library/Preferences/ByHost/com.apple.controlcenter 'Hearing' $' + + +3 +' +defaults write ~/Library/Preferences/ByHost/com.apple.controlcenter 'KeyboardBrightness' $' + + +6 +' +defaults write ~/Library/Preferences/ByHost/com.apple.controlcenter 'MusicRecognition' $' + + +6 ' defaults write ~/Library/Preferences/ByHost/com.apple.controlcenter 'NowPlaying' $' 18 ' +defaults write ~/Library/Preferences/ByHost/com.apple.controlcenter 'ScreenMirroring' $' + + +2 +' defaults write ~/Library/Preferences/ByHost/com.apple.controlcenter 'Sound' $' -24 +8 ' +defaults write ~/Library/Preferences/ByHost/com.apple.controlcenter 'StageManager' $' + + +2 +' +defaults write ~/Library/Preferences/ByHost/com.apple.controlcenter 'UserSwitcher' $' + + +19 +' +defaults write ~/Library/Preferences/ByHost/com.apple.controlcenter 'WiFi' $' + + +18 +' + diff --git a/tests/system-defaults-write.nix b/tests/system-defaults-write.nix index 35ff8532..dc06dbbc 100644 --- a/tests/system-defaults-write.nix +++ b/tests/system-defaults-write.nix @@ -128,13 +128,30 @@ system.defaults.WindowManager.EnableTiledWindowMargins = true; system.defaults.WindowManager.StandardHideWidgets = true; system.defaults.WindowManager.StageManagerHideWidgets = true; - system.defaults.controlcenter.BatteryShowPercentage = true; - system.defaults.controlcenter.Sound = false; - system.defaults.controlcenter.Bluetooth = true; + system.defaults.CustomUserPreferences = { + "NSGlobalDomain" = { "TISRomanSwitchState" = 1; }; + "com.apple.Safari" = { + "com.apple.Safari.ContentPageGroupIdentifier.WebKit2DeveloperExtrasEnabled" = + true; + }; + }; + system.defaults.controlcenter.AccessibilityShortcuts = "both"; system.defaults.controlcenter.AirDrop = true; - system.defaults.controlcenter.Display = false; - system.defaults.controlcenter.FocusModes = false; - system.defaults.controlcenter.NowPlaying = true; + system.defaults.controlcenter.Battery = "menuBar"; + system.defaults.controlcenter.BatteryShowEnergyMode = false; + system.defaults.controlcenter.BatteryShowPercentage = true; + system.defaults.controlcenter.Bluetooth = true; + system.defaults.controlcenter.Display = "hide"; + system.defaults.controlcenter.FocusModes = "hide"; + system.defaults.controlcenter.Hearing = "both"; + system.defaults.controlcenter.KeyboardBrightness = "menuBar"; + system.defaults.controlcenter.MusicRecognition = "menuBar"; + system.defaults.controlcenter.NowPlaying = "always"; + system.defaults.controlcenter.ScreenMirroring = "whenActive"; + system.defaults.controlcenter.Sound = "hide"; + system.defaults.controlcenter.StageManager = true; + system.defaults.controlcenter.UserSwitcher = "both"; + system.defaults.controlcenter.WiFi = true; test = lib.strings.concatMapStringsSep "\n" (x: '' echo >&2 "checking defaults write in /${x}" From 66b344d2b298e91ecc5554b90db2565c88133a49 Mon Sep 17 00:00:00 2001 From: angel <78835633+Iamanaws@users.noreply.github.com> Date: Fri, 21 Feb 2025 13:31:35 -0800 Subject: [PATCH 2/8] controlcenter: add Spotlight option --- modules/system/defaults/controlcenter.nix | 13 +++++++++++++ .../system-defaults-write/activate-user.txt | 5 +++++ tests/system-defaults-write.nix | 1 + 3 files changed, 19 insertions(+) diff --git a/modules/system/defaults/controlcenter.nix b/modules/system/defaults/controlcenter.nix index 80fa4c8b..1598437b 100644 --- a/modules/system/defaults/controlcenter.nix +++ b/modules/system/defaults/controlcenter.nix @@ -254,6 +254,19 @@ ''; }; + system.defaults.controlcenter.Spotlight = lib.mkOption { + type = lib.types.nullOr lib.types.bool; + default = null; + description = '' + Apple menu > System Preferences > Control Center > Menu Bar Only > Spotlight + + Show Spotlight in menu bar. Default is null. + + false - "Don't Show in Menu Bar" + true - "Show in Menu Bar" + ''; + }; + system.defaults.controlcenter.StageManager = lib.mkOption { type = lib.types.nullOr lib.types.bool; apply = v: if v == null then null else if v == true then 2 else 8; diff --git a/tests/fixtures/system-defaults-write/activate-user.txt b/tests/fixtures/system-defaults-write/activate-user.txt index 7762bfe2..40e2f919 100644 --- a/tests/fixtures/system-defaults-write/activate-user.txt +++ b/tests/fixtures/system-defaults-write/activate-user.txt @@ -686,6 +686,11 @@ defaults write ~/Library/Preferences/ByHost/com.apple.controlcenter 'Sound' $' 8 ' +defaults write ~/Library/Preferences/ByHost/com.apple.Spotlight 'MenuItemHidden' $' + + + +' defaults write ~/Library/Preferences/ByHost/com.apple.controlcenter 'StageManager' $' diff --git a/tests/system-defaults-write.nix b/tests/system-defaults-write.nix index dc06dbbc..fe009d01 100644 --- a/tests/system-defaults-write.nix +++ b/tests/system-defaults-write.nix @@ -149,6 +149,7 @@ system.defaults.controlcenter.NowPlaying = "always"; system.defaults.controlcenter.ScreenMirroring = "whenActive"; system.defaults.controlcenter.Sound = "hide"; + system.defaults.controlcenter.Spotlight = true; system.defaults.controlcenter.StageManager = true; system.defaults.controlcenter.UserSwitcher = "both"; system.defaults.controlcenter.WiFi = true; From cd52486229fa29961417e36d60736197c457368f Mon Sep 17 00:00:00 2001 From: angel <78835633+Iamanaws@users.noreply.github.com> Date: Fri, 21 Feb 2025 13:33:48 -0800 Subject: [PATCH 3/8] controlcenter: add functions to handle apply, mkEnumApply and mkBoolApply --- modules/system/defaults/controlcenter.nix | 324 +++++++++++----------- 1 file changed, 160 insertions(+), 164 deletions(-) diff --git a/modules/system/defaults/controlcenter.nix b/modules/system/defaults/controlcenter.nix index 1598437b..bff6de00 100644 --- a/modules/system/defaults/controlcenter.nix +++ b/modules/system/defaults/controlcenter.nix @@ -1,19 +1,24 @@ { config, lib, ... }: - -{ +let + mkEnumApply = mapping: default: v: + if v == null then null + else if mapping ? v then mapping.${v} else default; + mkBoolApply = mapping: v: + if v == null then null + else if v then mapping.true else mapping.false; +in { options = { system.defaults.controlcenter.AccessibilityShortcuts = lib.mkOption { - type = lib.types.nullOr (lib.types.enum [ "both" "menuBar" "controlCenter" "hide" ]); - default = null; - apply = v: - if v == null then null - else if v == "both" then 3 - else if v == "menuBar" then 6 - else if v == "controlCenter" then 9 - else if v == "hide" then 12 - else 12; - description = '' + type = lib.types.nullOr (lib.types.enum [ "both" "menuBar" "controlCenter" "hide" ]); + default = null; + apply = mkEnumApply { + both = 3; + menuBar = 6; + controlCenter = 9; + hide = 12; + } 12; + description = '' Apple menu > System Preferences > Control Center > Accessibility Shortcuts Options: @@ -21,34 +26,33 @@ menuBar - Show in Menu Bar only (6) controlCenter - Show in Control Center only (1 or 9) hide - Don't Show (2, 4, 8, or 12) - ''; + ''; }; system.defaults.controlcenter.AirDrop = lib.mkOption { - type = lib.types.nullOr lib.types.bool; - apply = v: if v == null then null else if v == true then 18 else 24; - default = null; - description = '' - Apple menu > System Preferences > Control Center > AirDrop + type = lib.types.nullOr lib.types.bool; + default = null; + apply = mkBoolApply { true = 18; false = 24; }; + description = '' + Apple menu > System Preferences > Control Center > AirDrop - Show a AirDrop control in menu bar. Default is null. + Show a AirDrop control in menu bar. Default is null. - 18 = Show in Menu Bar - 24 = Don't Show in Menu Bar - ''; + 18 = Show in Menu Bar + 24 = Don't Show in Menu Bar + ''; }; system.defaults.controlcenter.Battery = lib.mkOption { - type = lib.types.nullOr (lib.types.enum [ "both" "menuBar" "controlCenter" "hide" ]); - default = null; - apply = v: - if v == null then null - else if v == "both" then 3 - else if v == "menuBar" then 4 - else if v == "controlCenter" then 9 - else if v == "hide" then 12 - else 4; - description = '' + type = lib.types.nullOr (lib.types.enum [ "both" "menuBar" "controlCenter" "hide" ]); + default = null; + apply = mkEnumApply { + both = 3; + menuBar = 4; + controlCenter = 9; + hide = 12; + } 4; + description = '' Apple menu > System Preferences > Control Center > Battery Options: @@ -56,95 +60,92 @@ menuBar - Show in Menu Bar only (6) controlCenter - Show in Control Center only (1 or 9) hide - Don't Show (2, 4, 8, or 12) - ''; + ''; }; system.defaults.controlcenter.BatteryShowEnergyMode = lib.mkOption { - type = lib.types.nullOr lib.types.bool; - default = null; - description = '' + type = lib.types.nullOr lib.types.bool; + default = null; + description = '' Apple menu > System Preferences > Control Center > Battery Show a battery energy mode. Default is null. false - "When Active" true - "Always" - ''; + ''; }; system.defaults.controlcenter.BatteryShowPercentage = lib.mkOption { - type = lib.types.nullOr lib.types.bool; - default = null; - description = '' - Apple menu > System Preferences > Control Center > Battery + type = lib.types.nullOr lib.types.bool; + default = null; + description = '' + Apple menu > System Preferences > Control Center > Battery - Show a battery percentage in menu bar. Default is null. - ''; + Show a battery percentage in menu bar. Default is null. + ''; }; system.defaults.controlcenter.Bluetooth = lib.mkOption { - type = lib.types.nullOr lib.types.bool; - apply = v: if v == null then null else if v == true then 18 else 24; - default = null; - description = '' - Apple menu > System Preferences > Control Center > Bluetooth + type = lib.types.nullOr lib.types.bool; + default = null; + apply = mkBoolApply { true = 18; false = 24; }; + description = '' + Apple menu > System Preferences > Control Center > Bluetooth - Show a bluetooth control in menu bar. Default is null. + Show a bluetooth control in menu bar. Default is null. - 18 = Show in Menu Bar - 24 = Don't Show in Menu Bar - ''; + 18 = Show in Menu Bar + 24 = Don't Show in Menu Bar + ''; }; system.defaults.controlcenter.Display = lib.mkOption { - type = lib.types.nullOr (lib.types.enum [ "whenActive" "hide" "always" ]); - apply = v: - if v == null then null - else if v == "always" then 18 - else if v == "hide" then 8 - else if v == "whenActive" then 2 - else 2; - default = null; - description = '' + type = lib.types.nullOr (lib.types.enum [ "whenActive" "hide" "always" ]); + default = null; + apply = mkEnumApply { + always = 18; + hide = 8; + whenActive = 2; + } 2; + description = '' Apple menu > System Preferences > Control Center > Display Options: whenActive - Show When Active (2) hide - Don't Show in Menu Bar (8) always - Always Show in Menu Bar (18) - ''; + ''; }; system.defaults.controlcenter.FocusModes = lib.mkOption { - type = lib.types.nullOr (lib.types.enum [ "whenActive" "hide" "always" ]); - apply = v: - if v == null then null - else if v == "always" then 18 - else if v == "hide" then 8 - else if v == "whenActive" then 2 - else 2; - default = null; - description = '' + type = lib.types.nullOr (lib.types.enum [ "whenActive" "hide" "always" ]); + default = null; + apply = mkEnumApply { + always = 18; + hide = 8; + whenActive = 2; + } 2; + description = '' Apple menu > System Preferences > Control Center > Focus Options: whenActive - Show When Active (2) hide - Don't Show in Menu Bar (8) always - Always Show in Menu Bar (18) - ''; + ''; }; system.defaults.controlcenter.Hearing = lib.mkOption { - type = lib.types.nullOr (lib.types.enum [ "both" "menuBar" "controlCenter" "hide" ]); - default = null; - apply = v: - if v == null then null - else if v == "both" then 3 - else if v == "menuBar" then 6 - else if v == "controlCenter" then 9 - else if v == "hide" then 12 - else 12; - description = '' + type = lib.types.nullOr (lib.types.enum [ "both" "menuBar" "controlCenter" "hide" ]); + default = null; + apply = mkEnumApply { + both = 3; + menuBar = 6; + controlCenter = 9; + hide = 12; + } 12; + description = '' Apple menu > System Preferences > Control Center > Hearing Options: @@ -152,20 +153,19 @@ menuBar - Show in Menu Bar only (6) controlCenter - Show in Control Center only (1 or 9) hide - Don't Show (2, 4, 8, or 12) - ''; + ''; }; system.defaults.controlcenter.KeyboardBrightness = lib.mkOption { - type = lib.types.nullOr (lib.types.enum [ "both" "menuBar" "controlCenter" "hide" ]); - default = null; - apply = v: - if v == null then null - else if v == "both" then 3 - else if v == "menuBar" then 6 - else if v == "controlCenter" then 9 - else if v == "hide" then 12 - else 12; - description = '' + type = lib.types.nullOr (lib.types.enum [ "both" "menuBar" "controlCenter" "hide" ]); + default = null; + apply = mkEnumApply { + both = 3; + menuBar = 6; + controlCenter = 9; + hide = 12; + } 12; + description = '' Apple menu > System Preferences > Control Center > Keyboard Brightness Options: @@ -173,20 +173,19 @@ menuBar - Show in Menu Bar only (6) controlCenter - Show in Control Center only (1 or 9) hide - Don't Show (2, 4, 8, or 12) - ''; + ''; }; system.defaults.controlcenter.MusicRecognition = lib.mkOption { - type = lib.types.nullOr (lib.types.enum [ "both" "menuBar" "controlCenter" "hide" ]); - default = null; - apply = v: - if v == null then null - else if v == "both" then 3 - else if v == "menuBar" then 6 - else if v == "controlCenter" then 9 - else if v == "hide" then 12 - else 12; - description = '' + type = lib.types.nullOr (lib.types.enum [ "both" "menuBar" "controlCenter" "hide" ]); + default = null; + apply = mkEnumApply { + both = 3; + menuBar = 6; + controlCenter = 9; + hide = 12; + } 12; + description = '' Apple menu > System Preferences > Control Center > Music Recognition Options: @@ -194,64 +193,61 @@ menuBar - Show in Menu Bar only (6) controlCenter - Show in Control Center only (1 or 9) hide - Don't Show (2, 4, 8, or 12) - ''; + ''; }; system.defaults.controlcenter.NowPlaying = lib.mkOption { - type = lib.types.nullOr (lib.types.enum [ "whenActive" "hide" "always" ]); - apply = v: - if v == null then null - else if v == "always" then 18 - else if v == "hide" then 8 - else if v == "whenActive" then 2 - else 2; - default = null; - description = '' + type = lib.types.nullOr (lib.types.enum [ "whenActive" "hide" "always" ]); + default = null; + apply = mkEnumApply { + always = 18; + hide = 8; + whenActive = 2; + } 2; + description = '' Apple menu > System Preferences > Control Center > Now Playing Options: whenActive - Show When Active (2) hide - Don't Show in Menu Bar (8) always - Always Show in Menu Bar (18) - ''; + ''; }; system.defaults.controlcenter.ScreenMirroring = lib.mkOption { - type = lib.types.nullOr (lib.types.enum [ "whenActive" "hide" "always" ]); - apply = v: - if v == null then null - else if v == "always" then 18 - else if v == "hide" then 8 - else if v == "whenActive" then 2 - else 2; - default = null; - description = '' + type = lib.types.nullOr (lib.types.enum [ "whenActive" "hide" "always" ]); + default = null; + apply = mkEnumApply { + always = 18; + hide = 8; + whenActive = 2; + } 2; + description = '' Apple menu > System Preferences > Control Center > Screen Mirroring Options: whenActive - Show When Active (2) hide - Don't Show in Menu Bar (8) always - Always Show in Menu Bar (18) - ''; + ''; }; system.defaults.controlcenter.Sound = lib.mkOption { - type = lib.types.nullOr (lib.types.enum [ "whenActive" "hide" "always" ]); - apply = v: - if v == null then null - else if v == "always" then 18 - else if v == "hide" then 8 - else if v == "whenActive" then 2 - else 2; - default = null; - description = '' + type = lib.types.nullOr (lib.types.enum [ "whenActive" "hide" "always" ]); + default = null; + apply = mkEnumApply { + always = 18; + hide = 8; + whenActive = 2; + } 2; + description = '' Apple menu > System Preferences > Control Center > Sound Options: whenActive - Show When Active (2) hide - Don't Show in Menu Bar (8) always - Always Show in Menu Bar (18) - ''; + ''; }; system.defaults.controlcenter.Spotlight = lib.mkOption { @@ -268,30 +264,29 @@ }; system.defaults.controlcenter.StageManager = lib.mkOption { - type = lib.types.nullOr lib.types.bool; - apply = v: if v == null then null else if v == true then 2 else 8; - default = null; - description = '' - Apple menu > System Preferences > Control Center > Stage Manager + type = lib.types.nullOr lib.types.bool; + default = null; + apply = mkBoolApply { true = 2; false = 8; }; + description = '' + Apple menu > System Preferences > Control Center > Stage Manager - Show a Wi-Fi control in menu bar. Default is null. + Show a Wi-Fi control in menu bar. Default is null. - 2 = Show in Menu Bar - 8 = Don't Show in Menu Bar - ''; + 2 = Show in Menu Bar + 8 = Don't Show in Menu Bar + ''; }; system.defaults.controlcenter.UserSwitcher = lib.mkOption { - type = lib.types.nullOr (lib.types.enum [ "both" "menuBar" "controlCenter" "hide" ]); - apply = v: - if v == null then null - else if v == "both" then 19 - else if v == "menuBar" then 22 - else if v == "controlCenter" then 25 - else if v == "hide" then 28 - else 28; - default = null; - description = '' + type = lib.types.nullOr (lib.types.enum [ "both" "menuBar" "controlCenter" "hide" ]); + default = null; + apply = mkEnumApply { + both = 19; + menuBar = 22; + controlCenter = 25; + hide = 28; + } 28; + description = '' Apple menu > System Preferences > Control Center > Fast User Switching Options: @@ -299,21 +294,22 @@ menuBar - Show in Menu Bar (22) controlCenter - Show in Control Center (25) hide - Don't Show (28) - ''; + ''; }; system.defaults.controlcenter.WiFi = lib.mkOption { - type = lib.types.nullOr lib.types.bool; - apply = v: if v == null then null else if v == true then 18 else 24; - default = null; - description = '' - Apple menu > System Preferences > Control Center > Wi-Fi + type = lib.types.nullOr lib.types.bool; + default = null; + apply = mkBoolApply { true = 18; false = 24; }; + description = '' + Apple menu > System Preferences > Control Center > Wi-Fi - Show a Wi-Fi control in menu bar. Default is null. + Show a Wi-Fi control in menu bar. Default is null. - 18 = Show in Menu Bar - 24 = Don't Show in Menu Bar - ''; + 18 = Show in Menu Bar + 24 = Don't Show in Menu Bar + ''; }; + }; } From 85d8a5f20a7ae549fd72fd4785061b0c04790e98 Mon Sep 17 00:00:00 2001 From: angel <78835633+Iamanaws@users.noreply.github.com> Date: Fri, 21 Feb 2025 13:34:53 -0800 Subject: [PATCH 4/8] controlcenter: format with nixfmt-rfc-style --- modules/system/defaults/controlcenter.nix | 321 ++++++++++++++-------- 1 file changed, 208 insertions(+), 113 deletions(-) diff --git a/modules/system/defaults/controlcenter.nix b/modules/system/defaults/controlcenter.nix index bff6de00..9b455209 100644 --- a/modules/system/defaults/controlcenter.nix +++ b/modules/system/defaults/controlcenter.nix @@ -1,16 +1,34 @@ { config, lib, ... }: let - mkEnumApply = mapping: default: v: - if v == null then null - else if mapping ? v then mapping.${v} else default; - mkBoolApply = mapping: v: - if v == null then null - else if v then mapping.true else mapping.false; -in { + mkEnumApply = + mapping: default: v: + if v == null then + null + else if mapping ? v then + mapping.${v} + else + default; + mkBoolApply = + mapping: v: + if v == null then + null + else if v then + mapping.true + else + mapping.false; +in +{ options = { system.defaults.controlcenter.AccessibilityShortcuts = lib.mkOption { - type = lib.types.nullOr (lib.types.enum [ "both" "menuBar" "controlCenter" "hide" ]); + type = lib.types.nullOr ( + lib.types.enum [ + "both" + "menuBar" + "controlCenter" + "hide" + ] + ); default = null; apply = mkEnumApply { both = 3; @@ -19,32 +37,42 @@ in { hide = 12; } 12; description = '' - Apple menu > System Preferences > Control Center > Accessibility Shortcuts + Apple menu > System Preferences > Control Center > Accessibility Shortcuts - Options: - both - Show in Menu Bar and Control Center (3) - menuBar - Show in Menu Bar only (6) - controlCenter - Show in Control Center only (1 or 9) - hide - Don't Show (2, 4, 8, or 12) + Options: + both - Show in Menu Bar and Control Center (3) + menuBar - Show in Menu Bar only (6) + controlCenter - Show in Control Center only (1 or 9) + hide - Don't Show (2, 4, 8, or 12) ''; }; system.defaults.controlcenter.AirDrop = lib.mkOption { type = lib.types.nullOr lib.types.bool; default = null; - apply = mkBoolApply { true = 18; false = 24; }; + apply = mkBoolApply { + true = 18; + false = 24; + }; description = '' - Apple menu > System Preferences > Control Center > AirDrop + Apple menu > System Preferences > Control Center > AirDrop - Show a AirDrop control in menu bar. Default is null. + Show a AirDrop control in menu bar. Default is null. - 18 = Show in Menu Bar - 24 = Don't Show in Menu Bar + 18 = Show in Menu Bar + 24 = Don't Show in Menu Bar ''; }; system.defaults.controlcenter.Battery = lib.mkOption { - type = lib.types.nullOr (lib.types.enum [ "both" "menuBar" "controlCenter" "hide" ]); + type = lib.types.nullOr ( + lib.types.enum [ + "both" + "menuBar" + "controlCenter" + "hide" + ] + ); default = null; apply = mkEnumApply { both = 3; @@ -53,13 +81,13 @@ in { hide = 12; } 4; description = '' - Apple menu > System Preferences > Control Center > Battery + Apple menu > System Preferences > Control Center > Battery - Options: - both - Show in Menu Bar and Control Center (3) - menuBar - Show in Menu Bar only (6) - controlCenter - Show in Control Center only (1 or 9) - hide - Don't Show (2, 4, 8, or 12) + Options: + both - Show in Menu Bar and Control Center (3) + menuBar - Show in Menu Bar only (6) + controlCenter - Show in Control Center only (1 or 9) + hide - Don't Show (2, 4, 8, or 12) ''; }; @@ -67,12 +95,12 @@ in { type = lib.types.nullOr lib.types.bool; default = null; description = '' - Apple menu > System Preferences > Control Center > Battery + Apple menu > System Preferences > Control Center > Battery - Show a battery energy mode. Default is null. + Show a battery energy mode. Default is null. - false - "When Active" - true - "Always" + false - "When Active" + true - "Always" ''; }; @@ -80,28 +108,37 @@ in { type = lib.types.nullOr lib.types.bool; default = null; description = '' - Apple menu > System Preferences > Control Center > Battery + Apple menu > System Preferences > Control Center > Battery - Show a battery percentage in menu bar. Default is null. + Show a battery percentage in menu bar. Default is null. ''; }; system.defaults.controlcenter.Bluetooth = lib.mkOption { type = lib.types.nullOr lib.types.bool; default = null; - apply = mkBoolApply { true = 18; false = 24; }; + apply = mkBoolApply { + true = 18; + false = 24; + }; description = '' - Apple menu > System Preferences > Control Center > Bluetooth + Apple menu > System Preferences > Control Center > Bluetooth - Show a bluetooth control in menu bar. Default is null. + Show a bluetooth control in menu bar. Default is null. - 18 = Show in Menu Bar - 24 = Don't Show in Menu Bar + 18 = Show in Menu Bar + 24 = Don't Show in Menu Bar ''; }; system.defaults.controlcenter.Display = lib.mkOption { - type = lib.types.nullOr (lib.types.enum [ "whenActive" "hide" "always" ]); + type = lib.types.nullOr ( + lib.types.enum [ + "whenActive" + "hide" + "always" + ] + ); default = null; apply = mkEnumApply { always = 18; @@ -109,17 +146,23 @@ in { whenActive = 2; } 2; description = '' - Apple menu > System Preferences > Control Center > Display + Apple menu > System Preferences > Control Center > Display - Options: - whenActive - Show When Active (2) - hide - Don't Show in Menu Bar (8) - always - Always Show in Menu Bar (18) + Options: + whenActive - Show When Active (2) + hide - Don't Show in Menu Bar (8) + always - Always Show in Menu Bar (18) ''; }; system.defaults.controlcenter.FocusModes = lib.mkOption { - type = lib.types.nullOr (lib.types.enum [ "whenActive" "hide" "always" ]); + type = lib.types.nullOr ( + lib.types.enum [ + "whenActive" + "hide" + "always" + ] + ); default = null; apply = mkEnumApply { always = 18; @@ -127,17 +170,24 @@ in { whenActive = 2; } 2; description = '' - Apple menu > System Preferences > Control Center > Focus + Apple menu > System Preferences > Control Center > Focus - Options: - whenActive - Show When Active (2) - hide - Don't Show in Menu Bar (8) - always - Always Show in Menu Bar (18) + Options: + whenActive - Show When Active (2) + hide - Don't Show in Menu Bar (8) + always - Always Show in Menu Bar (18) ''; }; system.defaults.controlcenter.Hearing = lib.mkOption { - type = lib.types.nullOr (lib.types.enum [ "both" "menuBar" "controlCenter" "hide" ]); + type = lib.types.nullOr ( + lib.types.enum [ + "both" + "menuBar" + "controlCenter" + "hide" + ] + ); default = null; apply = mkEnumApply { both = 3; @@ -146,18 +196,25 @@ in { hide = 12; } 12; description = '' - Apple menu > System Preferences > Control Center > Hearing + Apple menu > System Preferences > Control Center > Hearing - Options: - both - Show in Menu Bar and Control Center (3) - menuBar - Show in Menu Bar only (6) - controlCenter - Show in Control Center only (1 or 9) - hide - Don't Show (2, 4, 8, or 12) + Options: + both - Show in Menu Bar and Control Center (3) + menuBar - Show in Menu Bar only (6) + controlCenter - Show in Control Center only (1 or 9) + hide - Don't Show (2, 4, 8, or 12) ''; }; system.defaults.controlcenter.KeyboardBrightness = lib.mkOption { - type = lib.types.nullOr (lib.types.enum [ "both" "menuBar" "controlCenter" "hide" ]); + type = lib.types.nullOr ( + lib.types.enum [ + "both" + "menuBar" + "controlCenter" + "hide" + ] + ); default = null; apply = mkEnumApply { both = 3; @@ -166,18 +223,25 @@ in { hide = 12; } 12; description = '' - Apple menu > System Preferences > Control Center > Keyboard Brightness + Apple menu > System Preferences > Control Center > Keyboard Brightness - Options: - both - Show in Menu Bar and Control Center (3) - menuBar - Show in Menu Bar only (6) - controlCenter - Show in Control Center only (1 or 9) - hide - Don't Show (2, 4, 8, or 12) + Options: + both - Show in Menu Bar and Control Center (3) + menuBar - Show in Menu Bar only (6) + controlCenter - Show in Control Center only (1 or 9) + hide - Don't Show (2, 4, 8, or 12) ''; }; system.defaults.controlcenter.MusicRecognition = lib.mkOption { - type = lib.types.nullOr (lib.types.enum [ "both" "menuBar" "controlCenter" "hide" ]); + type = lib.types.nullOr ( + lib.types.enum [ + "both" + "menuBar" + "controlCenter" + "hide" + ] + ); default = null; apply = mkEnumApply { both = 3; @@ -186,18 +250,24 @@ in { hide = 12; } 12; description = '' - Apple menu > System Preferences > Control Center > Music Recognition + Apple menu > System Preferences > Control Center > Music Recognition - Options: - both - Show in Menu Bar and Control Center (3) - menuBar - Show in Menu Bar only (6) - controlCenter - Show in Control Center only (1 or 9) - hide - Don't Show (2, 4, 8, or 12) + Options: + both - Show in Menu Bar and Control Center (3) + menuBar - Show in Menu Bar only (6) + controlCenter - Show in Control Center only (1 or 9) + hide - Don't Show (2, 4, 8, or 12) ''; }; system.defaults.controlcenter.NowPlaying = lib.mkOption { - type = lib.types.nullOr (lib.types.enum [ "whenActive" "hide" "always" ]); + type = lib.types.nullOr ( + lib.types.enum [ + "whenActive" + "hide" + "always" + ] + ); default = null; apply = mkEnumApply { always = 18; @@ -205,17 +275,23 @@ in { whenActive = 2; } 2; description = '' - Apple menu > System Preferences > Control Center > Now Playing + Apple menu > System Preferences > Control Center > Now Playing - Options: - whenActive - Show When Active (2) - hide - Don't Show in Menu Bar (8) - always - Always Show in Menu Bar (18) + Options: + whenActive - Show When Active (2) + hide - Don't Show in Menu Bar (8) + always - Always Show in Menu Bar (18) ''; }; system.defaults.controlcenter.ScreenMirroring = lib.mkOption { - type = lib.types.nullOr (lib.types.enum [ "whenActive" "hide" "always" ]); + type = lib.types.nullOr ( + lib.types.enum [ + "whenActive" + "hide" + "always" + ] + ); default = null; apply = mkEnumApply { always = 18; @@ -223,17 +299,23 @@ in { whenActive = 2; } 2; description = '' - Apple menu > System Preferences > Control Center > Screen Mirroring + Apple menu > System Preferences > Control Center > Screen Mirroring - Options: - whenActive - Show When Active (2) - hide - Don't Show in Menu Bar (8) - always - Always Show in Menu Bar (18) + Options: + whenActive - Show When Active (2) + hide - Don't Show in Menu Bar (8) + always - Always Show in Menu Bar (18) ''; }; system.defaults.controlcenter.Sound = lib.mkOption { - type = lib.types.nullOr (lib.types.enum [ "whenActive" "hide" "always" ]); + type = lib.types.nullOr ( + lib.types.enum [ + "whenActive" + "hide" + "always" + ] + ); default = null; apply = mkEnumApply { always = 18; @@ -241,44 +323,54 @@ in { whenActive = 2; } 2; description = '' - Apple menu > System Preferences > Control Center > Sound + Apple menu > System Preferences > Control Center > Sound - Options: - whenActive - Show When Active (2) - hide - Don't Show in Menu Bar (8) - always - Always Show in Menu Bar (18) + Options: + whenActive - Show When Active (2) + hide - Don't Show in Menu Bar (8) + always - Always Show in Menu Bar (18) ''; }; system.defaults.controlcenter.Spotlight = lib.mkOption { - type = lib.types.nullOr lib.types.bool; - default = null; - description = '' - Apple menu > System Preferences > Control Center > Menu Bar Only > Spotlight + type = lib.types.nullOr lib.types.bool; + default = null; + description = '' + Apple menu > System Preferences > Control Center > Menu Bar Only > Spotlight - Show Spotlight in menu bar. Default is null. + Show Spotlight in menu bar. Default is null. - false - "Don't Show in Menu Bar" - true - "Show in Menu Bar" - ''; + false - "Don't Show in Menu Bar" + true - "Show in Menu Bar" + ''; }; system.defaults.controlcenter.StageManager = lib.mkOption { type = lib.types.nullOr lib.types.bool; default = null; - apply = mkBoolApply { true = 2; false = 8; }; + apply = mkBoolApply { + true = 2; + false = 8; + }; description = '' - Apple menu > System Preferences > Control Center > Stage Manager + Apple menu > System Preferences > Control Center > Stage Manager - Show a Wi-Fi control in menu bar. Default is null. + Show a Wi-Fi control in menu bar. Default is null. - 2 = Show in Menu Bar - 8 = Don't Show in Menu Bar + 2 = Show in Menu Bar + 8 = Don't Show in Menu Bar ''; }; system.defaults.controlcenter.UserSwitcher = lib.mkOption { - type = lib.types.nullOr (lib.types.enum [ "both" "menuBar" "controlCenter" "hide" ]); + type = lib.types.nullOr ( + lib.types.enum [ + "both" + "menuBar" + "controlCenter" + "hide" + ] + ); default = null; apply = mkEnumApply { both = 19; @@ -287,27 +379,30 @@ in { hide = 28; } 28; description = '' - Apple menu > System Preferences > Control Center > Fast User Switching + Apple menu > System Preferences > Control Center > Fast User Switching - Options: - both - Show in Menu Bar and Control Center (19) - menuBar - Show in Menu Bar (22) - controlCenter - Show in Control Center (25) - hide - Don't Show (28) + Options: + both - Show in Menu Bar and Control Center (19) + menuBar - Show in Menu Bar (22) + controlCenter - Show in Control Center (25) + hide - Don't Show (28) ''; }; system.defaults.controlcenter.WiFi = lib.mkOption { type = lib.types.nullOr lib.types.bool; default = null; - apply = mkBoolApply { true = 18; false = 24; }; + apply = mkBoolApply { + true = 18; + false = 24; + }; description = '' - Apple menu > System Preferences > Control Center > Wi-Fi + Apple menu > System Preferences > Control Center > Wi-Fi - Show a Wi-Fi control in menu bar. Default is null. + Show a Wi-Fi control in menu bar. Default is null. - 18 = Show in Menu Bar - 24 = Don't Show in Menu Bar + 18 = Show in Menu Bar + 24 = Don't Show in Menu Bar ''; }; From 8d74ae9ac51a025f6ce97f98cc85eaf1ee0aec03 Mon Sep 17 00:00:00 2001 From: angel <78835633+Iamanaws@users.noreply.github.com> Date: Fri, 21 Feb 2025 14:27:16 -0800 Subject: [PATCH 5/8] controlcenter: change defaults tests/system-defaults-write --- tests/system-defaults-write.nix | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/system-defaults-write.nix b/tests/system-defaults-write.nix index fe009d01..958d2061 100644 --- a/tests/system-defaults-write.nix +++ b/tests/system-defaults-write.nix @@ -138,17 +138,17 @@ system.defaults.controlcenter.AccessibilityShortcuts = "both"; system.defaults.controlcenter.AirDrop = true; system.defaults.controlcenter.Battery = "menuBar"; - system.defaults.controlcenter.BatteryShowEnergyMode = false; + system.defaults.controlcenter.BatteryShowEnergyMode = true; system.defaults.controlcenter.BatteryShowPercentage = true; system.defaults.controlcenter.Bluetooth = true; - system.defaults.controlcenter.Display = "hide"; - system.defaults.controlcenter.FocusModes = "hide"; + system.defaults.controlcenter.Display = "whenActive"; + system.defaults.controlcenter.FocusModes = "whenActive"; system.defaults.controlcenter.Hearing = "both"; system.defaults.controlcenter.KeyboardBrightness = "menuBar"; system.defaults.controlcenter.MusicRecognition = "menuBar"; system.defaults.controlcenter.NowPlaying = "always"; system.defaults.controlcenter.ScreenMirroring = "whenActive"; - system.defaults.controlcenter.Sound = "hide"; + system.defaults.controlcenter.Sound = "whenActive"; system.defaults.controlcenter.Spotlight = true; system.defaults.controlcenter.StageManager = true; system.defaults.controlcenter.UserSwitcher = "both"; From 8508b13f8013f7fa33c3ef91bf0fe161f49c74f2 Mon Sep 17 00:00:00 2001 From: angel <78835633+Iamanaws@users.noreply.github.com> Date: Fri, 21 Feb 2025 14:53:38 -0800 Subject: [PATCH 6/8] Spotligh: move from controlcenter to separate module --- modules/module-list.nix | 1 + modules/system/defaults-write.nix | 3 +++ modules/system/defaults/Spotlight.nix | 18 ++++++++++++++++++ modules/system/defaults/controlcenter.nix | 13 ------------- .../system-defaults-write/activate-user.txt | 11 +++++------ tests/system-defaults-write.nix | 2 +- 6 files changed, 28 insertions(+), 20 deletions(-) create mode 100644 modules/system/defaults/Spotlight.nix diff --git a/modules/module-list.nix b/modules/module-list.nix index d01bbdb9..61e99042 100644 --- a/modules/module-list.nix +++ b/modules/module-list.nix @@ -15,6 +15,7 @@ ./system/applications.nix ./system/defaults-write.nix ./system/defaults/controlcenter.nix + ./system/defaults/Spotlight.nix ./system/defaults/LaunchServices.nix ./system/defaults/NSGlobalDomain.nix ./system/defaults/GlobalPreferences.nix diff --git a/modules/system/defaults-write.nix b/modules/system/defaults-write.nix index a00b0e42..5c2f5943 100644 --- a/modules/system/defaults-write.nix +++ b/modules/system/defaults-write.nix @@ -38,6 +38,7 @@ let ActivityMonitor = defaultsToList "com.apple.ActivityMonitor" cfg.ActivityMonitor; WindowManager = defaultsToList "com.apple.WindowManager" cfg.WindowManager; controlcenter = defaultsToList "~/Library/Preferences/ByHost/com.apple.controlcenter" cfg.controlcenter; + Spotlight = defaultsToList "~/Library/Preferences/ByHost/com.apple.Spotlight" cfg.Spotlight; CustomUserPreferences = flatten (mapAttrsToList (name: value: defaultsToList name value) cfg.CustomUserPreferences); CustomSystemPreferences = flatten (mapAttrsToList (name: value: defaultsToList name value) cfg.CustomSystemPreferences); @@ -95,6 +96,7 @@ in CustomUserPreferences WindowManager controlcenter + Spotlight ] '' # Set defaults @@ -120,6 +122,7 @@ in ${concatStringsSep "\n" CustomUserPreferences} ${concatStringsSep "\n" WindowManager} ${concatStringsSep "\n" controlcenter} + ${concatStringsSep "\n" Spotlight} ${optionalString (length dock > 0) '' # Only restart Dock if current user is logged in diff --git a/modules/system/defaults/Spotlight.nix b/modules/system/defaults/Spotlight.nix new file mode 100644 index 00000000..526d0d31 --- /dev/null +++ b/modules/system/defaults/Spotlight.nix @@ -0,0 +1,18 @@ +{ config, lib, ... }: + +{ + options = { + system.defaults.Spotlight.MenuItemHidden = lib.mkOption { + type = lib.types.nullOr lib.types.bool; + default = null; + description = '' + Apple menu > System Preferences > Control Center > Menu Bar Only > Spotlight + + Show Spotlight in menu bar. Default is null. + + false - "Don't Show in Menu Bar" + true - "Show in Menu Bar" + ''; + }; + }; +} diff --git a/modules/system/defaults/controlcenter.nix b/modules/system/defaults/controlcenter.nix index 9b455209..27f87705 100644 --- a/modules/system/defaults/controlcenter.nix +++ b/modules/system/defaults/controlcenter.nix @@ -332,19 +332,6 @@ in ''; }; - system.defaults.controlcenter.Spotlight = lib.mkOption { - type = lib.types.nullOr lib.types.bool; - default = null; - description = '' - Apple menu > System Preferences > Control Center > Menu Bar Only > Spotlight - - Show Spotlight in menu bar. Default is null. - - false - "Don't Show in Menu Bar" - true - "Show in Menu Bar" - ''; - }; - system.defaults.controlcenter.StageManager = lib.mkOption { type = lib.types.nullOr lib.types.bool; default = null; diff --git a/tests/fixtures/system-defaults-write/activate-user.txt b/tests/fixtures/system-defaults-write/activate-user.txt index 40e2f919..d132281d 100644 --- a/tests/fixtures/system-defaults-write/activate-user.txt +++ b/tests/fixtures/system-defaults-write/activate-user.txt @@ -686,11 +686,6 @@ defaults write ~/Library/Preferences/ByHost/com.apple.controlcenter 'Sound' $' 8 ' -defaults write ~/Library/Preferences/ByHost/com.apple.Spotlight 'MenuItemHidden' $' - - - -' defaults write ~/Library/Preferences/ByHost/com.apple.controlcenter 'StageManager' $' @@ -706,4 +701,8 @@ defaults write ~/Library/Preferences/ByHost/com.apple.controlcenter 'WiFi' $' 18 ' - +defaults write ~/Library/Preferences/ByHost/com.apple.Spotlight 'MenuItemHidden' $' + + + +' \ No newline at end of file diff --git a/tests/system-defaults-write.nix b/tests/system-defaults-write.nix index 958d2061..6d955958 100644 --- a/tests/system-defaults-write.nix +++ b/tests/system-defaults-write.nix @@ -149,10 +149,10 @@ system.defaults.controlcenter.NowPlaying = "always"; system.defaults.controlcenter.ScreenMirroring = "whenActive"; system.defaults.controlcenter.Sound = "whenActive"; - system.defaults.controlcenter.Spotlight = true; system.defaults.controlcenter.StageManager = true; system.defaults.controlcenter.UserSwitcher = "both"; system.defaults.controlcenter.WiFi = true; + system.defaults.Spotlight.MenuItemHidden = true; test = lib.strings.concatMapStringsSep "\n" (x: '' echo >&2 "checking defaults write in /${x}" From ad91f3c412147bea49b8e9e00f2109a91cf8d506 Mon Sep 17 00:00:00 2001 From: iamanaws <78835633+Iamanaws@users.noreply.github.com> Date: Sat, 22 Feb 2025 12:54:26 -0800 Subject: [PATCH 7/8] controlcenter: fix descriptions and add deprecation warnings --- modules/system/defaults/Spotlight.nix | 12 +- modules/system/defaults/controlcenter.nix | 223 ++++++++++++------ .../system-defaults-write/activate-user.txt | 14 +- tests/system-defaults-write.nix | 14 +- 4 files changed, 176 insertions(+), 87 deletions(-) diff --git a/modules/system/defaults/Spotlight.nix b/modules/system/defaults/Spotlight.nix index 526d0d31..7592768d 100644 --- a/modules/system/defaults/Spotlight.nix +++ b/modules/system/defaults/Spotlight.nix @@ -6,13 +6,15 @@ type = lib.types.nullOr lib.types.bool; default = null; description = '' - Apple menu > System Preferences > Control Center > Menu Bar Only > Spotlight + Show Spotlight control in menu bar. - Show Spotlight in menu bar. Default is null. + Available settings: + true - Don't Show in Menu Bar + false - Show in Menu Bar - false - "Don't Show in Menu Bar" - true - "Show in Menu Bar" + This option mirrors the setting found in: + System Preferences > Control Center > Menu Bar Only > Spotlight ''; }; }; -} +} \ No newline at end of file diff --git a/modules/system/defaults/controlcenter.nix b/modules/system/defaults/controlcenter.nix index 27f87705..93c961f9 100644 --- a/modules/system/defaults/controlcenter.nix +++ b/modules/system/defaults/controlcenter.nix @@ -4,6 +4,8 @@ let mapping: default: v: if v == null then null + else if builtins.isBool v then + if v then mapping.true else mapping.false else if mapping ? v then mapping.${v} else @@ -37,13 +39,16 @@ in hide = 12; } 12; description = '' - Apple menu > System Preferences > Control Center > Accessibility Shortcuts + Show an Accessibility Shortcuts control in menu bar. - Options: - both - Show in Menu Bar and Control Center (3) - menuBar - Show in Menu Bar only (6) - controlCenter - Show in Control Center only (1 or 9) - hide - Don't Show (2, 4, 8, or 12) + Available settings: + both - Show in both the Menu Bar and Control Center (3) + menuBar - Show in the Menu Bar only (6) + controlCenter - Show in Control Center only (9) + hide - Don't Show (12) + + This option mirrors the setting found in: + System Preferences > Control Center > AccessibilityShortcuts ''; }; @@ -55,12 +60,14 @@ in false = 24; }; description = '' - Apple menu > System Preferences > Control Center > AirDrop + Show an AirDrop control in menu bar. - Show a AirDrop control in menu bar. Default is null. + Available settings: + true - Show in Menu Bar (18) + false - Don't Show in Menu Bar (24) - 18 = Show in Menu Bar - 24 = Don't Show in Menu Bar + This option mirrors the setting found in: + System Preferences > Control Center > AirDrop ''; }; @@ -81,26 +88,40 @@ in hide = 12; } 4; description = '' - Apple menu > System Preferences > Control Center > Battery + Show a Battery control in menu bar. - Options: - both - Show in Menu Bar and Control Center (3) - menuBar - Show in Menu Bar only (6) - controlCenter - Show in Control Center only (1 or 9) - hide - Don't Show (2, 4, 8, or 12) + Available settings: + both - Show in both the Menu Bar and Control Center (3) + menuBar - Show in the Menu Bar only (4) + controlCenter - Show in Control Center only (9) + hide - Don't Show (12) + + This option mirrors the setting found in: + System Preferences > Control Center > Battery ''; }; system.defaults.controlcenter.BatteryShowEnergyMode = lib.mkOption { - type = lib.types.nullOr lib.types.bool; + type = lib.types.nullOr ( + lib.types.enum [ + "whenActive" + "always" + ] + ); default = null; + apply = mkEnumApply { + always = true; + whenActive = false; + } false; description = '' - Apple menu > System Preferences > Control Center > Battery + Show a Battery Energy Mode control in menu bar. - Show a battery energy mode. Default is null. + Available settings: + whenActive - Show When Active + always - Always Show - false - "When Active" - true - "Always" + This option mirrors the setting found in: + System Preferences > Control Center > Battery ''; }; @@ -108,9 +129,14 @@ in type = lib.types.nullOr lib.types.bool; default = null; description = '' - Apple menu > System Preferences > Control Center > Battery + Show a Battery Percentage control in menu bar. - Show a battery percentage in menu bar. Default is null. + Available settings: + true - Show in Menu Bar + false - Don't Show in Menu Bar + + This option mirrors the setting found in: + System Preferences > Control Center > Battery ''; }; @@ -122,12 +148,14 @@ in false = 24; }; description = '' - Apple menu > System Preferences > Control Center > Bluetooth + Show a Bluetooth control in menu bar. - Show a bluetooth control in menu bar. Default is null. + Available settings: + true - Show in Menu Bar (18) + false - Don't Show in Menu Bar (24) - 18 = Show in Menu Bar - 24 = Don't Show in Menu Bar + This option mirrors the setting found in: + System Preferences > Control Center > Bluetooth ''; }; @@ -137,6 +165,8 @@ in "whenActive" "hide" "always" + true + false ] ); default = null; @@ -144,14 +174,22 @@ in always = 18; hide = 8; whenActive = 2; + + true = lib.warn "system.defaults.controlcenter.Display = true is deprecated; please use \"always\" instead" 18; + false = lib.warn "system.defaults.controlcenter.Display = false is deprecated; please use \"whenActive\" instead" 2; } 2; description = '' - Apple menu > System Preferences > Control Center > Display + Show a Display control in menu bar. - Options: + Available settings: whenActive - Show When Active (2) hide - Don't Show in Menu Bar (8) always - Always Show in Menu Bar (18) + + Note: Boolean values are deprecated; please use the enum values. + + This option mirrors the setting found in: + System Preferences > Control Center > Display ''; }; @@ -161,6 +199,8 @@ in "whenActive" "hide" "always" + true + false ] ); default = null; @@ -168,14 +208,22 @@ in always = 18; hide = 8; whenActive = 2; + + true = lib.warn "system.defaults.controlcenter.FocusModes = true is deprecated; please use \"always\" instead" 18; + false = lib.warn "system.defaults.controlcenter.FocusModes = false is deprecated; please use \"whenActive\" instead" 2; } 2; description = '' - Apple menu > System Preferences > Control Center > Focus + Show a Focus control in menu bar. - Options: + Available settings: whenActive - Show When Active (2) hide - Don't Show in Menu Bar (8) always - Always Show in Menu Bar (18) + + Note: Boolean values are deprecated; please use the enum values. + + This option mirrors the setting found in: + System Preferences > Control Center > Focus ''; }; @@ -196,13 +244,16 @@ in hide = 12; } 12; description = '' - Apple menu > System Preferences > Control Center > Hearing + Show a Hearing control in menu bar. - Options: - both - Show in Menu Bar and Control Center (3) - menuBar - Show in Menu Bar only (6) - controlCenter - Show in Control Center only (1 or 9) - hide - Don't Show (2, 4, 8, or 12) + Available settings: + both - Show in both the Menu Bar and Control Center (3) + menuBar - Show in the Menu Bar only (6) + controlCenter - Show in Control Center only (9) + hide - Don't Show (12) + + This option mirrors the setting found in: + System Preferences > Control Center > Hearing ''; }; @@ -223,13 +274,16 @@ in hide = 12; } 12; description = '' - Apple menu > System Preferences > Control Center > Keyboard Brightness + Show a Keyboard Brightness control in menu bar. - Options: - both - Show in Menu Bar and Control Center (3) - menuBar - Show in Menu Bar only (6) - controlCenter - Show in Control Center only (1 or 9) - hide - Don't Show (2, 4, 8, or 12) + Available settings: + both - Show in both the Menu Bar and Control Center (3) + menuBar - Show in the Menu Bar only (6) + controlCenter - Show in Control Center only (9) + hide - Don't Show (12) + + This option mirrors the setting found in: + System Preferences > Control Center > Keyboard Brightness ''; }; @@ -250,13 +304,16 @@ in hide = 12; } 12; description = '' - Apple menu > System Preferences > Control Center > Music Recognition + Show a Music Recognition control in menu bar. - Options: - both - Show in Menu Bar and Control Center (3) - menuBar - Show in Menu Bar only (6) - controlCenter - Show in Control Center only (1 or 9) - hide - Don't Show (2, 4, 8, or 12) + Available settings: + both - Show in both the Menu Bar and Control Center (3) + menuBar - Show in the Menu Bar only (6) + controlCenter - Show in Control Center only (9) + hide - Don't Show (12) + + This option mirrors the setting found in: + System Preferences > Control Center > Music Recognition ''; }; @@ -266,6 +323,8 @@ in "whenActive" "hide" "always" + true + false ] ); default = null; @@ -273,14 +332,22 @@ in always = 18; hide = 8; whenActive = 2; + + true = lib.warn "system.defaults.controlcenter.NowPlaying = true is deprecated; please use \"always\" instead" 18; + false = lib.warn "system.defaults.controlcenter.NowPlaying = false is deprecated; please use \"whenActive\" instead" 2; } 2; description = '' - Apple menu > System Preferences > Control Center > Now Playing + Show a Now Playing control in menu bar. - Options: + Available settings: whenActive - Show When Active (2) hide - Don't Show in Menu Bar (8) always - Always Show in Menu Bar (18) + + Note: Boolean values are deprecated; please use the enum values. + + This option mirrors the setting found in: + System Preferences > Control Center > Now Playing ''; }; @@ -299,12 +366,15 @@ in whenActive = 2; } 2; description = '' - Apple menu > System Preferences > Control Center > Screen Mirroring + Show a Screen Mirroring control in menu bar. - Options: + Available settings: whenActive - Show When Active (2) hide - Don't Show in Menu Bar (8) always - Always Show in Menu Bar (18) + + This option mirrors the setting found in: + System Preferences > Control Center > Screen Mirroring ''; }; @@ -314,6 +384,8 @@ in "whenActive" "hide" "always" + true + false ] ); default = null; @@ -321,14 +393,22 @@ in always = 18; hide = 8; whenActive = 2; + + true = lib.warn "system.defaults.controlcenter.Sound = true is deprecated; please use \"always\" instead" 18; + false = lib.warn "system.defaults.controlcenter.Sound = false is deprecated; please use \"whenActive\" instead" 2; } 2; description = '' - Apple menu > System Preferences > Control Center > Sound + Show a Sound control in menu bar. - Options: + Available settings: whenActive - Show When Active (2) hide - Don't Show in Menu Bar (8) always - Always Show in Menu Bar (18) + + Note: Boolean values are deprecated; please use the enum values. + + This option mirrors the setting found in: + System Preferences > Control Center > Sound ''; }; @@ -340,12 +420,14 @@ in false = 8; }; description = '' - Apple menu > System Preferences > Control Center > Stage Manager + Show a Stage Manager control in menu bar. - Show a Wi-Fi control in menu bar. Default is null. + Available settings: + true - Show in Menu Bar (2) + false - Don't Show in Menu Bar (8) - 2 = Show in Menu Bar - 8 = Don't Show in Menu Bar + This option mirrors the setting found in: + System Preferences > Control Center > Stage Manager ''; }; @@ -366,13 +448,16 @@ in hide = 28; } 28; description = '' - Apple menu > System Preferences > Control Center > Fast User Switching + Show a User Switcher control in menu bar. - Options: - both - Show in Menu Bar and Control Center (19) - menuBar - Show in Menu Bar (22) - controlCenter - Show in Control Center (25) + Available settings: + both - Show in both the Menu Bar and Control Center (19) + menuBar - Show in the Menu Bar only (22) + controlCenter - Show in Control Center only (25) hide - Don't Show (28) + + This option mirrors the setting found in: + System Preferences > Control Center > Fast User Switching ''; }; @@ -384,12 +469,14 @@ in false = 24; }; description = '' - Apple menu > System Preferences > Control Center > Wi-Fi + Show a Wi-Fi control in menu bar. - Show a Wi-Fi control in menu bar. Default is null. + Available settings: + true - Show in Menu Bar (18) + false - Don't Show in Menu Bar (24) - 18 = Show in Menu Bar - 24 = Don't Show in Menu Bar + This option mirrors the setting found in: + System Preferences > Control Center > Wi-Fi ''; }; diff --git a/tests/fixtures/system-defaults-write/activate-user.txt b/tests/fixtures/system-defaults-write/activate-user.txt index d132281d..05358b47 100644 --- a/tests/fixtures/system-defaults-write/activate-user.txt +++ b/tests/fixtures/system-defaults-write/activate-user.txt @@ -634,7 +634,7 @@ defaults write ~/Library/Preferences/ByHost/com.apple.controlcenter 'Battery' $' defaults write ~/Library/Preferences/ByHost/com.apple.controlcenter 'BatteryShowEnergyMode' $' - + ' defaults write ~/Library/Preferences/ByHost/com.apple.controlcenter 'BatteryShowPercentage' $' @@ -649,17 +649,17 @@ defaults write ~/Library/Preferences/ByHost/com.apple.controlcenter 'Bluetooth' defaults write ~/Library/Preferences/ByHost/com.apple.controlcenter 'Display' $' -2 +18 ' defaults write ~/Library/Preferences/ByHost/com.apple.controlcenter 'FocusModes' $' -2 +18 ' defaults write ~/Library/Preferences/ByHost/com.apple.controlcenter 'Hearing' $' -3 +6 ' defaults write ~/Library/Preferences/ByHost/com.apple.controlcenter 'KeyboardBrightness' $' @@ -679,12 +679,12 @@ defaults write ~/Library/Preferences/ByHost/com.apple.controlcenter 'NowPlaying' defaults write ~/Library/Preferences/ByHost/com.apple.controlcenter 'ScreenMirroring' $' -2 +18 ' defaults write ~/Library/Preferences/ByHost/com.apple.controlcenter 'Sound' $' -8 +18 ' defaults write ~/Library/Preferences/ByHost/com.apple.controlcenter 'StageManager' $' @@ -694,7 +694,7 @@ defaults write ~/Library/Preferences/ByHost/com.apple.controlcenter 'StageManage defaults write ~/Library/Preferences/ByHost/com.apple.controlcenter 'UserSwitcher' $' -19 +22 ' defaults write ~/Library/Preferences/ByHost/com.apple.controlcenter 'WiFi' $' diff --git a/tests/system-defaults-write.nix b/tests/system-defaults-write.nix index 6d955958..e28cc231 100644 --- a/tests/system-defaults-write.nix +++ b/tests/system-defaults-write.nix @@ -138,19 +138,19 @@ system.defaults.controlcenter.AccessibilityShortcuts = "both"; system.defaults.controlcenter.AirDrop = true; system.defaults.controlcenter.Battery = "menuBar"; - system.defaults.controlcenter.BatteryShowEnergyMode = true; + system.defaults.controlcenter.BatteryShowEnergyMode = "always"; system.defaults.controlcenter.BatteryShowPercentage = true; system.defaults.controlcenter.Bluetooth = true; - system.defaults.controlcenter.Display = "whenActive"; - system.defaults.controlcenter.FocusModes = "whenActive"; - system.defaults.controlcenter.Hearing = "both"; + system.defaults.controlcenter.Display = "always"; + system.defaults.controlcenter.FocusModes = "always"; + system.defaults.controlcenter.Hearing = "menuBar"; system.defaults.controlcenter.KeyboardBrightness = "menuBar"; system.defaults.controlcenter.MusicRecognition = "menuBar"; system.defaults.controlcenter.NowPlaying = "always"; - system.defaults.controlcenter.ScreenMirroring = "whenActive"; - system.defaults.controlcenter.Sound = "whenActive"; + system.defaults.controlcenter.ScreenMirroring = "always"; + system.defaults.controlcenter.Sound = "always"; system.defaults.controlcenter.StageManager = true; - system.defaults.controlcenter.UserSwitcher = "both"; + system.defaults.controlcenter.UserSwitcher = "menuBar"; system.defaults.controlcenter.WiFi = true; system.defaults.Spotlight.MenuItemHidden = true; test = lib.strings.concatMapStringsSep "\n" From 75bdba8202371ffadbfce7be4dac43f82342d951 Mon Sep 17 00:00:00 2001 From: angel <78835633+Iamanaws@users.noreply.github.com> Date: Fri, 21 Mar 2025 09:22:20 -0700 Subject: [PATCH 8/8] use same option for controlcenter config --- tests/system-defaults-write.nix | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/system-defaults-write.nix b/tests/system-defaults-write.nix index e28cc231..8a4eea48 100644 --- a/tests/system-defaults-write.nix +++ b/tests/system-defaults-write.nix @@ -137,20 +137,20 @@ }; system.defaults.controlcenter.AccessibilityShortcuts = "both"; system.defaults.controlcenter.AirDrop = true; - system.defaults.controlcenter.Battery = "menuBar"; + system.defaults.controlcenter.Battery = "both"; system.defaults.controlcenter.BatteryShowEnergyMode = "always"; system.defaults.controlcenter.BatteryShowPercentage = true; system.defaults.controlcenter.Bluetooth = true; system.defaults.controlcenter.Display = "always"; system.defaults.controlcenter.FocusModes = "always"; - system.defaults.controlcenter.Hearing = "menuBar"; - system.defaults.controlcenter.KeyboardBrightness = "menuBar"; - system.defaults.controlcenter.MusicRecognition = "menuBar"; + system.defaults.controlcenter.Hearing = "both"; + system.defaults.controlcenter.KeyboardBrightness = "both"; + system.defaults.controlcenter.MusicRecognition = "both"; system.defaults.controlcenter.NowPlaying = "always"; system.defaults.controlcenter.ScreenMirroring = "always"; system.defaults.controlcenter.Sound = "always"; system.defaults.controlcenter.StageManager = true; - system.defaults.controlcenter.UserSwitcher = "menuBar"; + system.defaults.controlcenter.UserSwitcher = "both"; system.defaults.controlcenter.WiFi = true; system.defaults.Spotlight.MenuItemHidden = true; test = lib.strings.concatMapStringsSep "\n"