From f07acb443ae578a77fba338cbdeac6365e68ae25 Mon Sep 17 00:00:00 2001 From: Chris Montgomery Date: Fri, 24 Dec 2021 17:20:15 -0500 Subject: [PATCH 1/3] defaults-write: formatting --- modules/system/defaults-write.nix | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/modules/system/defaults-write.nix b/modules/system/defaults-write.nix index 8342984..a1d392b 100644 --- a/modules/system/defaults-write.nix +++ b/modules/system/defaults-write.nix @@ -37,13 +37,18 @@ let magicmouse = defaultsToList "com.apple.AppleMultitouchMouse" cfg.magicmouse; magicmouseBluetooth = defaultsToList "com.apple.driver.AppleMultitouchMouse.mouse" cfg.magicmouse; - mkIfAttrs = list: mkIf (any (attrs: attrs != {}) list); + mkIfAttrs = list: mkIf (any (attrs: attrs != { }) list); in { config = { - system.activationScripts.defaults.text = mkIfAttrs [ alf loginwindow smb SoftwareUpdate ] + system.activationScripts.defaults.text = mkIfAttrs [ + alf + loginwindow + smb + SoftwareUpdate + ] '' # Set defaults echo >&2 "system defaults..." @@ -54,7 +59,19 @@ in ''; system.activationScripts.userDefaults.text = mkIfAttrs - [ NSGlobalDomain GlobalPreferences LaunchServices dock finder screencapture spaces trackpad trackpadBluetooth magicmouse magicmouseBluetooth ] + [ + NSGlobalDomain + GlobalPreferences + LaunchServices + dock + finder + screencapture + spaces + trackpad + trackpadBluetooth + magicmouse + magicmouseBluetooth + ] '' # Set defaults echo >&2 "user defaults..." From 7709d31d7619aaaed423191b3ef0f3446484b9e5 Mon Sep 17 00:00:00 2001 From: Chris Montgomery Date: Fri, 24 Dec 2021 17:24:04 -0500 Subject: [PATCH 2/3] defaults-write: sort variables and lists by name and option --- modules/system/defaults-write.nix | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/modules/system/defaults-write.nix b/modules/system/defaults-write.nix index a1d392b..0357a1e 100644 --- a/modules/system/defaults-write.nix +++ b/modules/system/defaults-write.nix @@ -21,21 +21,24 @@ let defaultsToList = domain: attrs: mapAttrsToList (writeDefault domain) (filterAttrs (n: v: v != null) attrs); - NSGlobalDomain = defaultsToList "-g" cfg.NSGlobalDomain; - GlobalPreferences = defaultsToList ".GlobalPreferences" cfg.".GlobalPreferences"; - LaunchServices = defaultsToList "com.apple.LaunchServices" cfg.LaunchServices; - dock = defaultsToList "com.apple.dock" cfg.dock; - finder = defaultsToList "com.apple.finder" cfg.finder; + # defaults alf = defaultsToList "/Library/Preferences/com.apple.alf" cfg.alf; loginwindow = defaultsToList "/Library/Preferences/com.apple.loginwindow" cfg.loginwindow; smb = defaultsToList "/Library/Preferences/SystemConfiguration/com.apple.smb.server" cfg.smb; SoftwareUpdate = defaultsToList "/Library/Preferences/SystemConfiguration/com.apple.SoftwareUpdate" cfg.SoftwareUpdate; + + # userDefaults + GlobalPreferences = defaultsToList ".GlobalPreferences" cfg.".GlobalPreferences"; + LaunchServices = defaultsToList "com.apple.LaunchServices" cfg.LaunchServices; + NSGlobalDomain = defaultsToList "-g" cfg.NSGlobalDomain; + dock = defaultsToList "com.apple.dock" cfg.dock; + finder = defaultsToList "com.apple.finder" cfg.finder; + magicmouse = defaultsToList "com.apple.AppleMultitouchMouse" cfg.magicmouse; + magicmouseBluetooth = defaultsToList "com.apple.driver.AppleMultitouchMouse.mouse" cfg.magicmouse; screencapture = defaultsToList "com.apple.screencapture" cfg.screencapture; spaces = defaultsToList "com.apple.spaces" cfg.spaces; trackpad = defaultsToList "com.apple.AppleMultitouchTrackpad" cfg.trackpad; trackpadBluetooth = defaultsToList "com.apple.driver.AppleBluetoothMultitouch.trackpad" cfg.trackpad; - magicmouse = defaultsToList "com.apple.AppleMultitouchMouse" cfg.magicmouse; - magicmouseBluetooth = defaultsToList "com.apple.driver.AppleMultitouchMouse.mouse" cfg.magicmouse; mkIfAttrs = list: mkIf (any (attrs: attrs != { }) list); in @@ -60,33 +63,34 @@ in system.activationScripts.userDefaults.text = mkIfAttrs [ - NSGlobalDomain GlobalPreferences LaunchServices + NSGlobalDomain dock finder + magicmouse + magicmouseBluetooth screencapture spaces trackpad trackpadBluetooth - magicmouse - magicmouseBluetooth ] '' # Set defaults echo >&2 "user defaults..." ${concatStringsSep "\n" NSGlobalDomain} + ${concatStringsSep "\n" GlobalPreferences} ${concatStringsSep "\n" LaunchServices} ${concatStringsSep "\n" dock} ${concatStringsSep "\n" finder} + ${concatStringsSep "\n" magicmouse} + ${concatStringsSep "\n" magicmouseBluetooth} ${concatStringsSep "\n" screencapture} ${concatStringsSep "\n" spaces} ${concatStringsSep "\n" trackpad} ${concatStringsSep "\n" trackpadBluetooth} - ${concatStringsSep "\n" magicmouse} - ${concatStringsSep "\n" magicmouseBluetooth} ''; }; From 1cf57052834731a8cabf644032e9147606ac0ed1 Mon Sep 17 00:00:00 2001 From: Chris Montgomery Date: Fri, 24 Dec 2021 17:48:08 -0500 Subject: [PATCH 3/3] defaults: add options for common `universalaccess` settings --- modules/module-list.nix | 1 + modules/system/defaults-write.nix | 3 ++ modules/system/defaults/universalaccess.nix | 38 +++++++++++++++++++++ tests/system-defaults-write.nix | 6 ++++ 4 files changed, 48 insertions(+) create mode 100644 modules/system/defaults/universalaccess.nix diff --git a/modules/module-list.nix b/modules/module-list.nix index e7fd2af..30a83b9 100644 --- a/modules/module-list.nix +++ b/modules/module-list.nix @@ -21,6 +21,7 @@ ./system/defaults/SoftwareUpdate.nix ./system/defaults/spaces.nix ./system/defaults/trackpad.nix + ./system/defaults/universalaccess.nix ./system/etc.nix ./system/keyboard.nix ./system/launchd.nix diff --git a/modules/system/defaults-write.nix b/modules/system/defaults-write.nix index 0357a1e..e58c3ac 100644 --- a/modules/system/defaults-write.nix +++ b/modules/system/defaults-write.nix @@ -39,6 +39,7 @@ let spaces = defaultsToList "com.apple.spaces" cfg.spaces; trackpad = defaultsToList "com.apple.AppleMultitouchTrackpad" cfg.trackpad; trackpadBluetooth = defaultsToList "com.apple.driver.AppleBluetoothMultitouch.trackpad" cfg.trackpad; + universalaccess = defaultsToList "com.apple.universalaccess" cfg.universalaccess; mkIfAttrs = list: mkIf (any (attrs: attrs != { }) list); in @@ -74,6 +75,7 @@ in spaces trackpad trackpadBluetooth + universalaccess ] '' # Set defaults @@ -91,6 +93,7 @@ in ${concatStringsSep "\n" spaces} ${concatStringsSep "\n" trackpad} ${concatStringsSep "\n" trackpadBluetooth} + ${concatStringsSep "\n" universalaccess} ''; }; diff --git a/modules/system/defaults/universalaccess.nix b/modules/system/defaults/universalaccess.nix new file mode 100644 index 0000000..85cae54 --- /dev/null +++ b/modules/system/defaults/universalaccess.nix @@ -0,0 +1,38 @@ +{ config, lib, ... }: + +with lib; + +{ + options = { + + system.defaults.universalaccess.reduceTransparency = mkOption { + type = types.nullOr types.bool; + default = null; + description = '' + Disable transparency in the menu bar and elsewhere. + Requires macOS Yosemite or later. + The default is false. + ''; + }; + + system.defaults.universalaccess.closeViewScrollWheelToggle = mkOption { + type = types.nullOr types.bool; + default = null; + description = '' + Use scroll gesture with the Ctrl (^) modifier key to zoom. + The default is false. + ''; + }; + + system.defaults.universalaccess.closeViewZoomFollowsFocus = mkOption { + type = types.nullOr types.bool; + default = null; + description = '' + Follow the keyboard focus while zoomed in. + Without setting `closeViewScrollWheelToggle` this has no effect. + The default is false. + ''; + }; + + }; +} diff --git a/tests/system-defaults-write.nix b/tests/system-defaults-write.nix index 2a0eef4..414b903 100644 --- a/tests/system-defaults-write.nix +++ b/tests/system-defaults-write.nix @@ -39,6 +39,9 @@ system.defaults.screencapture.location = "/tmp"; system.defaults.smb.NetBIOSName = "IMAC-000000"; system.defaults.smb.ServerDescription = ''Darwin\\\\U2019s iMac''; + system.defaults.universalaccess.reduceTransparency = true; + system.defaults.universalaccess.closeViewScrollWheelToggle = true; + system.defaults.universalaccess.closeViewZoomFollowsFocus = true; test = '' echo >&2 "checking defaults write in /activate" @@ -82,5 +85,8 @@ grep "defaults write com.apple.dock 'autohide-delay' -float 0.24" ${config.out}/activate-user grep "defaults write com.apple.dock 'orientation' -string 'left'" ${config.out}/activate-user grep "defaults write com.apple.screencapture 'location' -string '/tmp'" ${config.out}/activate-user + grep "defaults write com.apple.universalaccess 'reduceTransparency' -bool YES" ${config.out}/activate-user + grep "defaults write com.apple.universalaccess 'closeViewScrollWheelToggle' -bool YES" ${config.out}/activate-user + grep "defaults write com.apple.universalaccess 'closeViewZoomFollowsFocus' -bool YES" ${config.out}/activate-user ''; }