diff --git a/modules/system/defaults-write.nix b/modules/system/defaults-write.nix
index 2e56d74a..7e1fc443 100644
--- a/modules/system/defaults-write.nix
+++ b/modules/system/defaults-write.nix
@@ -5,18 +5,8 @@ with lib;
let
cfg = config.system.defaults;
- boolValue = x: if x then "YES" else "NO";
-
- writeValue = value:
- if isBool value then "-bool ${boolValue value}" else
- if isInt value then "-int ${toString value}" else
- if isFloat value then "-float ${strings.floatToString value}" else
- if isString value then "-string '${value}'" else
- if isList value then "-array ${concatStringsSep " " (map (v: writeValue v)value)}" else
- throw "invalid value type";
-
writeDefault = domain: key: value:
- "defaults write ${domain} '${key}' ${writeValue value}";
+ "defaults write ${domain} '${key}' $'${strings.escape [ "'" ] (generators.toPlist { } value)}'";
defaultsToList = domain: attrs: mapAttrsToList (writeDefault domain) (filterAttrs (n: v: v != null) attrs);
diff --git a/tests/fixtures/system-defaults-write/activate-user.txt b/tests/fixtures/system-defaults-write/activate-user.txt
new file mode 100644
index 00000000..81d9b277
--- /dev/null
+++ b/tests/fixtures/system-defaults-write/activate-user.txt
@@ -0,0 +1,308 @@
+defaults write -g 'AppleEnableMouseSwipeNavigateWithScrolls' $'
+
+
+
+'
+defaults write -g 'AppleEnableSwipeNavigateWithScrolls' $'
+
+
+
+'
+defaults write -g 'AppleFontSmoothing' $'
+
+
+1
+'
+defaults write -g 'AppleICUForce24HourTime' $'
+
+
+
+'
+defaults write -g 'AppleKeyboardUIMode' $'
+
+
+3
+'
+defaults write -g 'ApplePressAndHoldEnabled' $'
+
+
+
+'
+defaults write -g 'AppleScrollerPagingBehavior' $'
+
+
+
+'
+defaults write -g 'AppleShowAllExtensions' $'
+
+
+
+'
+defaults write -g 'AppleShowAllFiles' $'
+
+
+
+'
+defaults write -g 'AppleShowScrollBars' $'
+
+
+Always
+'
+defaults write -g 'AppleWindowTabbingMode' $'
+
+
+always
+'
+defaults write -g 'InitialKeyRepeat' $'
+
+
+10
+'
+defaults write -g 'KeyRepeat' $'
+
+
+1
+'
+defaults write -g 'NSAutomaticCapitalizationEnabled' $'
+
+
+
+'
+defaults write -g 'NSAutomaticDashSubstitutionEnabled' $'
+
+
+
+'
+defaults write -g 'NSAutomaticPeriodSubstitutionEnabled' $'
+
+
+
+'
+defaults write -g 'NSAutomaticQuoteSubstitutionEnabled' $'
+
+
+
+'
+defaults write -g 'NSAutomaticSpellingCorrectionEnabled' $'
+
+
+
+'
+defaults write -g 'NSAutomaticWindowAnimationsEnabled' $'
+
+
+
+'
+defaults write -g 'NSDisableAutomaticTermination' $'
+
+
+
+'
+defaults write -g 'NSDocumentSaveNewDocumentsToCloud' $'
+
+
+
+'
+defaults write -g 'NSNavPanelExpandedStateForSaveMode' $'
+
+
+
+'
+defaults write -g 'NSNavPanelExpandedStateForSaveMode2' $'
+
+
+
+'
+defaults write -g 'NSScrollAnimationEnabled' $'
+
+
+
+'
+defaults write -g 'NSTableViewDefaultSizeMode' $'
+
+
+2
+'
+defaults write -g 'NSTextShowsControlCharacters' $'
+
+
+
+'
+defaults write -g 'NSUseAnimatedFocusRing' $'
+
+
+
+'
+defaults write -g 'NSWindowResizeTime' $'
+
+
+0.010000
+'
+defaults write -g 'NSWindowShouldDragOnGesture' $'
+
+
+
+'
+defaults write -g 'PMPrintingExpandedStateForPrint' $'
+
+
+
+'
+defaults write -g 'PMPrintingExpandedStateForPrint2' $'
+
+
+
+'
+defaults write -g 'com.apple.keyboard.fnState' $'
+
+
+
+'
+defaults write -g 'com.apple.mouse.tapBehavior' $'
+
+
+1
+'
+defaults write -g 'com.apple.springing.delay' $'
+
+
+0.000000
+'
+defaults write -g 'com.apple.springing.enabled' $'
+
+
+
+'
+defaults write -g 'com.apple.swipescrolldirection' $'
+
+
+
+'
+defaults write -g 'com.apple.trackpad.enableSecondaryClick' $'
+
+
+
+'
+defaults write -g 'com.apple.trackpad.trackpadCornerClickBehavior' $'
+
+
+1
+'
+
+defaults write .GlobalPreferences 'com.apple.sound.beep.sound' $'
+
+
+/System/Library/Sounds/Funk.aiff
+'
+
+defaults write com.apple.menuextra.clock 'Show24Hour' $'
+
+
+
+'
+defaults write com.apple.menuextra.clock 'ShowDate' $'
+
+
+2
+'
+defaults write com.apple.menuextra.clock 'ShowDayOfWeek' $'
+
+
+
+'
+defaults write com.apple.dock 'appswitcher-all-displays' $'
+
+
+
+'
+defaults write com.apple.dock 'autohide-delay' $'
+
+
+0.240000
+'
+defaults write com.apple.dock 'orientation' $'
+
+
+left
+'
+
+
+
+defaults write com.apple.screencapture 'location' $'
+
+
+/tmp
+'
+defaults write com.apple.screensaver 'askForPassword' $'
+
+
+
+'
+defaults write com.apple.screensaver 'askForPasswordDelay' $'
+
+
+5
+'
+
+
+
+defaults write com.apple.universalaccess 'closeViewScrollWheelToggle' $'
+
+
+
+'
+defaults write com.apple.universalaccess 'closeViewZoomFollowsFocus' $'
+
+
+
+'
+defaults write com.apple.universalaccess 'mouseDriverCursorSize' $'
+
+
+1.500000
+'
+defaults write com.apple.universalaccess 'reduceMotion' $'
+
+
+
+'
+defaults write com.apple.universalaccess 'reduceTransparency' $'
+
+
+
+'
+defaults write com.apple.ActivityMonitor 'IconType' $'
+
+
+3
+'
+defaults write com.apple.ActivityMonitor 'OpenMainWindow' $'
+
+
+
+'
+defaults write com.apple.ActivityMonitor 'ShowCategory' $'
+
+
+103
+'
+defaults write com.apple.ActivityMonitor 'SortColumn' $'
+
+
+CPUUsage
+'
+defaults write com.apple.ActivityMonitor 'SortDirection' $'
+
+
+0
+'
+defaults write NSGlobalDomain 'TISRomanSwitchState' $'
+
+
+1
+'
+defaults write com.apple.Safari 'com.apple.Safari.ContentPageGroupIdentifier.WebKit2DeveloperExtrasEnabled' $'
+
+
+
+'
diff --git a/tests/fixtures/system-defaults-write/activate.txt b/tests/fixtures/system-defaults-write/activate.txt
new file mode 100644
index 00000000..b22bc6d4
--- /dev/null
+++ b/tests/fixtures/system-defaults-write/activate.txt
@@ -0,0 +1,10 @@
+defaults write /Library/Preferences/SystemConfiguration/com.apple.smb.server 'NetBIOSName' $'
+
+
+IMAC-000000
+'
+defaults write /Library/Preferences/SystemConfiguration/com.apple.smb.server 'ServerDescription' $'
+
+
+Darwin\\\\U2019\'s iMac
+'
diff --git a/tests/system-defaults-write.nix b/tests/system-defaults-write.nix
index 4745efd4..def169d2 100644
--- a/tests/system-defaults-write.nix
+++ b/tests/system-defaults-write.nix
@@ -1,4 +1,4 @@
-{ config, pkgs, ... }:
+{ config, pkgs, lib, ... }:
{
system.defaults.NSGlobalDomain.AppleShowAllFiles = true;
@@ -50,7 +50,7 @@
system.defaults.screensaver.askForPassword = true;
system.defaults.screensaver.askForPasswordDelay = 5;
system.defaults.smb.NetBIOSName = "IMAC-000000";
- system.defaults.smb.ServerDescription = ''Darwin\\\\U2019s iMac'';
+ system.defaults.smb.ServerDescription = ''Darwin\\\\U2019's iMac'';
system.defaults.universalaccess.mouseDriverCursorSize = 1.5;
system.defaults.universalaccess.reduceMotion = true;
system.defaults.universalaccess.reduceTransparency = true;
@@ -68,70 +68,19 @@
true;
};
};
- test = ''
- echo >&2 "checking defaults write in /activate"
- grep "defaults write /Library/Preferences/SystemConfiguration/com.apple.smb.server 'NetBIOSName' -string 'IMAC-000000'" ${config.out}/activate
- grep "defaults write /Library/Preferences/SystemConfiguration/com.apple.smb.server 'ServerDescription' -string 'Darwin.*s iMac'" ${config.out}/activate
-
- echo >&2 "checking defaults write in /activate-user"
- grep "defaults write -g 'AppleShowAllFiles' -bool YES" ${config.out}/activate-user
- grep "defaults write -g 'AppleEnableMouseSwipeNavigateWithScrolls' -bool NO" ${config.out}/activate-user
- grep "defaults write -g 'AppleEnableSwipeNavigateWithScrolls' -bool NO" ${config.out}/activate-user
- grep "defaults write -g 'AppleFontSmoothing' -int 1" ${config.out}/activate-user
- grep "defaults write -g 'AppleICUForce24HourTime' -bool YES" ${config.out}/activate-user
- grep "defaults write -g 'AppleKeyboardUIMode' -int 3" ${config.out}/activate-user
- grep "defaults write -g 'ApplePressAndHoldEnabled' -bool YES" ${config.out}/activate-user
- grep "defaults write -g 'AppleShowAllExtensions' -bool YES" ${config.out}/activate-user
- grep "defaults write -g 'AppleShowScrollBars' -string 'Always'" ${config.out}/activate-user
- grep "defaults write -g 'AppleScrollerPagingBehavior' -bool YES" ${config.out}/activate-user
- grep "defaults write -g 'NSAutomaticCapitalizationEnabled' -bool NO" ${config.out}/activate-user
- grep "defaults write -g 'NSAutomaticDashSubstitutionEnabled' -bool NO" ${config.out}/activate-user
- grep "defaults write -g 'NSAutomaticPeriodSubstitutionEnabled' -bool NO" ${config.out}/activate-user
- grep "defaults write -g 'NSAutomaticQuoteSubstitutionEnabled' -bool NO" ${config.out}/activate-user
- grep "defaults write -g 'NSAutomaticSpellingCorrectionEnabled' -bool NO" ${config.out}/activate-user
- grep "defaults write -g 'NSAutomaticWindowAnimationsEnabled' -bool NO" ${config.out}/activate-user
- grep "defaults write -g 'NSDisableAutomaticTermination' -bool YES" ${config.out}/activate-user
- grep "defaults write -g 'NSDocumentSaveNewDocumentsToCloud' -bool NO" ${config.out}/activate-user
- grep "defaults write -g 'AppleWindowTabbingMode' -string 'always'" ${config.out}/activate-user
- grep "defaults write -g 'NSNavPanelExpandedStateForSaveMode' -bool YES" ${config.out}/activate-user
- grep "defaults write -g 'NSNavPanelExpandedStateForSaveMode2' -bool YES" ${config.out}/activate-user
- grep "defaults write -g 'NSTableViewDefaultSizeMode' -int 2" ${config.out}/activate-user
- grep "defaults write -g 'NSTextShowsControlCharacters' -bool YES" ${config.out}/activate-user
- grep "defaults write -g 'NSUseAnimatedFocusRing' -bool NO" ${config.out}/activate-user
- grep "defaults write -g 'NSScrollAnimationEnabled' -bool YES" ${config.out}/activate-user
- grep "defaults write -g 'NSWindowResizeTime' -float 0.01" ${config.out}/activate-user
- grep "defaults write -g 'NSWindowShouldDragOnGesture' -bool YES" ${config.out}/activate-user
- grep "defaults write -g 'InitialKeyRepeat' -int 10" ${config.out}/activate-user
- grep "defaults write -g 'KeyRepeat' -int 1" ${config.out}/activate-user
- grep "defaults write -g 'PMPrintingExpandedStateForPrint' -bool YES" ${config.out}/activate-user
- grep "defaults write -g 'PMPrintingExpandedStateForPrint2' -bool YES" ${config.out}/activate-user
- grep "defaults write -g 'com.apple.keyboard.fnState' -bool YES" ${config.out}/activate-user
- grep "defaults write -g 'com.apple.mouse.tapBehavior' -int 1" ${config.out}/activate-user
- grep "defaults write -g 'com.apple.trackpad.enableSecondaryClick' -bool YES" ${config.out}/activate-user
- grep "defaults write -g 'com.apple.trackpad.trackpadCornerClickBehavior' -int 1" ${config.out}/activate-user
- grep "defaults write -g 'com.apple.springing.enabled' -bool YES" ${config.out}/activate-user
- grep "defaults write -g 'com.apple.springing.delay' -float 0.0" ${config.out}/activate-user
- grep "defaults write -g 'com.apple.swipescrolldirection' -bool YES" ${config.out}/activate-user
- grep "defaults write .GlobalPreferences 'com.apple.sound.beep.sound' -string '/System/Library/Sounds/Funk.aiff'" ${config.out}/activate-user
- grep "defaults write com.apple.menuextra.clock 'Show24Hour' -bool NO" ${config.out}/activate-user
- grep "defaults write com.apple.menuextra.clock 'ShowDayOfWeek' -bool YES" ${config.out}/activate-user
- grep "defaults write com.apple.menuextra.clock 'ShowDate' -int 2" ${config.out}/activate-user
- grep "defaults write com.apple.dock 'autohide-delay' -float 0.24" ${config.out}/activate-user
- grep "defaults write com.apple.dock 'appswitcher-all-displays' -bool NO" ${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.screensaver 'askForPassword' -bool YES" ${config.out}/activate-user
- grep "defaults write com.apple.screensaver 'askForPasswordDelay' -int 5" ${config.out}/activate-user
- grep "defaults write com.apple.universalaccess 'mouseDriverCursorSize' -float 1.5" ${config.out}/activate-user
- grep "defaults write com.apple.universalaccess 'reduceMotion' -bool YES" ${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
- grep "defaults write com.apple.ActivityMonitor 'ShowCategory' -int 103" ${config.out}/activate-user
- grep "defaults write com.apple.ActivityMonitor 'IconType' -int 3" ${config.out}/activate-user
- grep "defaults write com.apple.ActivityMonitor 'SortColumn' -string 'CPUUsage'" ${config.out}/activate-user
- grep "defaults write com.apple.ActivityMonitor 'SortDirection' -int 0" ${config.out}/activate-user
- grep "defaults write com.apple.ActivityMonitor 'OpenMainWindow' -bool YES" ${config.out}/activate-user
- grep "defaults write NSGlobalDomain 'TISRomanSwitchState' -int 1" ${config.out}/activate-user
- '';
+ test = lib.strings.concatMapStringsSep "\n" (x: ''
+ echo >&2 "checking defaults write in /${x}"
+ ${pkgs.python3}/bin/python3 <