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..7592768d --- /dev/null +++ b/modules/system/defaults/Spotlight.nix @@ -0,0 +1,20 @@ +{ config, lib, ... }: + +{ + options = { + system.defaults.Spotlight.MenuItemHidden = lib.mkOption { + type = lib.types.nullOr lib.types.bool; + default = null; + description = '' + Show Spotlight control in menu bar. + + Available settings: + true - Don't Show in Menu Bar + false - 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 91532fa9..93c961f9 100644 --- a/modules/system/defaults/controlcenter.nix +++ b/modules/system/defaults/controlcenter.nix @@ -1,100 +1,484 @@ { config, lib, ... }: - +let + mkEnumApply = + 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 + default; + mkBoolApply = + mapping: v: + if v == null then + null + else if v then + mapping.true + else + mapping.false; +in { options = { - system.defaults.controlcenter.BatteryShowPercentage = lib.mkOption { - type = lib.types.nullOr lib.types.bool; - default = null; - description = '' - Apple menu > System Preferences > Control Center > Battery + system.defaults.controlcenter.AccessibilityShortcuts = lib.mkOption { + 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 = '' + Show an Accessibility Shortcuts control in menu bar. - Show a battery percentage in menu bar. Default is null. - ''; - }; + 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) - 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 - ''; + This option mirrors the setting found in: + System Preferences > Control Center > AccessibilityShortcuts + ''; }; 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 = '' + 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 = Display icon in menu bar - 24 = Hide icon in menu bar - ''; + This option mirrors the setting found in: + System Preferences > Control Center > AirDrop + ''; + }; + + system.defaults.controlcenter.Battery = lib.mkOption { + 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 = '' + Show a Battery control in menu bar. + + 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.enum [ + "whenActive" + "always" + ] + ); + default = null; + apply = mkEnumApply { + always = true; + whenActive = false; + } false; + description = '' + Show a Battery Energy Mode control in menu bar. + + Available settings: + whenActive - Show When Active + always - Always Show + + This option mirrors the setting found in: + System Preferences > Control Center > Battery + ''; + }; + + system.defaults.controlcenter.BatteryShowPercentage = lib.mkOption { + type = lib.types.nullOr lib.types.bool; + default = null; + description = '' + Show a Battery Percentage control in menu bar. + + 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 + ''; + }; + + system.defaults.controlcenter.Bluetooth = lib.mkOption { + type = lib.types.nullOr lib.types.bool; + default = null; + apply = mkBoolApply { + true = 18; + false = 24; + }; + description = '' + Show a Bluetooth control in menu bar. + + Available settings: + true - Show in Menu Bar (18) + false - Don't Show in Menu Bar (24) + + This option mirrors the setting found in: + System Preferences > Control Center > Bluetooth + ''; }; 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; - description = '' - Apple menu > System Preferences > Control Center > Display + type = lib.types.nullOr ( + lib.types.enum [ + "whenActive" + "hide" + "always" + true + false + ] + ); + default = null; + apply = mkEnumApply { + always = 18; + hide = 8; + whenActive = 2; - Show a Screen Brightness control in menu bar. Default is null. + 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 = '' + Show a Display control in menu bar. - 18 = Display icon in menu bar - 24 = Hide icon in menu bar - ''; + 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 + ''; }; 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; - description = '' - Apple menu > System Preferences > Control Center > Focus + type = lib.types.nullOr ( + lib.types.enum [ + "whenActive" + "hide" + "always" + true + false + ] + ); + default = null; + apply = mkEnumApply { + always = 18; + hide = 8; + whenActive = 2; - Show a Focus control in menu bar. Default is null. + 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 = '' + Show a Focus control in menu bar. - 18 = Display icon in menu bar - 24 = Hide icon in menu bar - ''; + 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 + ''; + }; + + system.defaults.controlcenter.Hearing = lib.mkOption { + 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 = '' + Show a Hearing control in menu bar. + + 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 + ''; + }; + + system.defaults.controlcenter.KeyboardBrightness = lib.mkOption { + 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 = '' + Show a Keyboard Brightness control in menu bar. + + 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 + ''; + }; + + system.defaults.controlcenter.MusicRecognition = lib.mkOption { + 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 = '' + Show a Music Recognition control in menu bar. + + 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 + ''; }; system.defaults.controlcenter.NowPlaying = 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 + type = lib.types.nullOr ( + lib.types.enum [ + "whenActive" + "hide" + "always" + true + false + ] + ); + default = null; + apply = mkEnumApply { + always = 18; + hide = 8; + whenActive = 2; - Show a Now Playing control in menu bar. Default is null. + 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 = '' + Show a Now Playing control in menu bar. - 18 = Display icon in menu bar - 24 = Hide icon in menu bar - ''; + 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 + ''; }; + + system.defaults.controlcenter.ScreenMirroring = lib.mkOption { + type = lib.types.nullOr ( + lib.types.enum [ + "whenActive" + "hide" + "always" + ] + ); + default = null; + apply = mkEnumApply { + always = 18; + hide = 8; + whenActive = 2; + } 2; + description = '' + Show a Screen Mirroring control in menu bar. + + 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 + ''; + }; + + system.defaults.controlcenter.Sound = lib.mkOption { + type = lib.types.nullOr ( + lib.types.enum [ + "whenActive" + "hide" + "always" + true + false + ] + ); + default = null; + apply = mkEnumApply { + 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 = '' + Show a Sound control in menu bar. + + 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 + ''; + }; + + system.defaults.controlcenter.StageManager = lib.mkOption { + type = lib.types.nullOr lib.types.bool; + default = null; + apply = mkBoolApply { + true = 2; + false = 8; + }; + description = '' + Show a Stage Manager control in menu bar. + + Available settings: + true - Show in Menu Bar (2) + false - Don't Show in Menu Bar (8) + + This option mirrors the setting found in: + System Preferences > Control Center > Stage Manager + ''; + }; + + system.defaults.controlcenter.UserSwitcher = lib.mkOption { + 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 = '' + Show a User Switcher control in menu bar. + + 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 + ''; + }; + + system.defaults.controlcenter.WiFi = lib.mkOption { + type = lib.types.nullOr lib.types.bool; + default = null; + apply = mkBoolApply { + true = 18; + false = 24; + }; + description = '' + Show a Wi-Fi control in menu bar. + + Available settings: + true - Show in Menu Bar (18) + false - Don't Show in Menu Bar (24) + + 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 d93321ef..05358b47 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,60 @@ defaults write ~/Library/Preferences/ByHost/com.apple.controlcenter 'Bluetooth' defaults write ~/Library/Preferences/ByHost/com.apple.controlcenter 'Display' $' -24 +18 ' defaults write ~/Library/Preferences/ByHost/com.apple.controlcenter 'FocusModes' $' -24 +18 +' +defaults write ~/Library/Preferences/ByHost/com.apple.controlcenter 'Hearing' $' + + +6 +' +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' $' + + +18 +' defaults write ~/Library/Preferences/ByHost/com.apple.controlcenter 'Sound' $' -24 +18 ' +defaults write ~/Library/Preferences/ByHost/com.apple.controlcenter 'StageManager' $' + + +2 +' +defaults write ~/Library/Preferences/ByHost/com.apple.controlcenter 'UserSwitcher' $' + + +22 +' +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 35ff8532..8a4eea48 100644 --- a/tests/system-defaults-write.nix +++ b/tests/system-defaults-write.nix @@ -128,13 +128,31 @@ 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 = "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 = "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 = "both"; + system.defaults.controlcenter.WiFi = true; + system.defaults.Spotlight.MenuItemHidden = true; test = lib.strings.concatMapStringsSep "\n" (x: '' echo >&2 "checking defaults write in /${x}"