diff --git a/modules/system/activation-scripts.nix b/modules/system/activation-scripts.nix
index ddcbbe91..a5cdc24d 100644
--- a/modules/system/activation-scripts.nix
+++ b/modules/system/activation-scripts.nix
@@ -88,6 +88,7 @@ in
${cfg.activationScripts.patches.text}
${cfg.activationScripts.etc.text}
${cfg.activationScripts.defaults.text}
+ ${cfg.activationScripts.userDefaults.text}
${cfg.activationScripts.launchd.text}
${cfg.activationScripts.userLaunchd.text}
${cfg.activationScripts.nix-daemon.text}
@@ -138,7 +139,6 @@ in
${cfg.activationScripts.checks.text}
${cfg.activationScripts.etcChecks.text}
${cfg.activationScripts.extraUserActivation.text}
- ${cfg.activationScripts.userDefaults.text}
${cfg.activationScripts.postUserActivation.text}
diff --git a/modules/system/defaults-write.nix b/modules/system/defaults-write.nix
index a00b0e42..4b32bf3d 100644
--- a/modules/system/defaults-write.nix
+++ b/modules/system/defaults-write.nix
@@ -1,4 +1,4 @@
-{ config, lib, ... }:
+{ options, config, lib, ... }:
with lib;
@@ -9,6 +9,10 @@ let
"defaults write ${domain} '${key}' $'${strings.escape [ "'" ] (generators.toPlist { } value)}'";
defaultsToList = domain: attrs: mapAttrsToList (writeDefault domain) (filterAttrs (n: v: v != null) attrs);
+ userDefaultsToList = domain: attrs: map
+ (cmd: "sudo --user=${escapeShellArg config.system.primaryUser} -- ${cmd}")
+ (defaultsToList domain attrs);
+
# Filter out options to not pass through
# dock has alias options that we need to ignore
dockFiltered = (builtins.removeAttrs cfg.dock ["expose-group-by-app"]);
@@ -18,28 +22,28 @@ let
loginwindow = defaultsToList "/Library/Preferences/com.apple.loginwindow" cfg.loginwindow;
smb = defaultsToList "/Library/Preferences/SystemConfiguration/com.apple.smb.server" cfg.smb;
SoftwareUpdate = defaultsToList "/Library/Preferences/com.apple.SoftwareUpdate" cfg.SoftwareUpdate;
+ CustomSystemPreferences = flatten (mapAttrsToList (name: value: defaultsToList name value) cfg.CustomSystemPreferences);
# userDefaults
- GlobalPreferences = defaultsToList ".GlobalPreferences" cfg.".GlobalPreferences";
- LaunchServices = defaultsToList "com.apple.LaunchServices" cfg.LaunchServices;
- NSGlobalDomain = defaultsToList "-g" cfg.NSGlobalDomain;
- menuExtraClock = defaultsToList "com.apple.menuextra.clock" cfg.menuExtraClock;
- dock = defaultsToList "com.apple.dock" dockFiltered;
- finder = defaultsToList "com.apple.finder" cfg.finder;
- hitoolbox = defaultsToList "com.apple.HIToolbox" cfg.hitoolbox;
- magicmouse = defaultsToList "com.apple.AppleMultitouchMouse" cfg.magicmouse;
- magicmouseBluetooth = defaultsToList "com.apple.driver.AppleMultitouchMouse.mouse" cfg.magicmouse;
- screencapture = defaultsToList "com.apple.screencapture" cfg.screencapture;
- screensaver = defaultsToList "com.apple.screensaver" cfg.screensaver;
- 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;
- ActivityMonitor = defaultsToList "com.apple.ActivityMonitor" cfg.ActivityMonitor;
- WindowManager = defaultsToList "com.apple.WindowManager" cfg.WindowManager;
- controlcenter = defaultsToList "~/Library/Preferences/ByHost/com.apple.controlcenter" cfg.controlcenter;
- CustomUserPreferences = flatten (mapAttrsToList (name: value: defaultsToList name value) cfg.CustomUserPreferences);
- CustomSystemPreferences = flatten (mapAttrsToList (name: value: defaultsToList name value) cfg.CustomSystemPreferences);
+ GlobalPreferences = userDefaultsToList ".GlobalPreferences" cfg.".GlobalPreferences";
+ LaunchServices = userDefaultsToList "com.apple.LaunchServices" cfg.LaunchServices;
+ NSGlobalDomain = userDefaultsToList "-g" cfg.NSGlobalDomain;
+ menuExtraClock = userDefaultsToList "com.apple.menuextra.clock" cfg.menuExtraClock;
+ dock = userDefaultsToList "com.apple.dock" dockFiltered;
+ finder = userDefaultsToList "com.apple.finder" cfg.finder;
+ hitoolbox = userDefaultsToList "com.apple.HIToolbox" cfg.hitoolbox;
+ magicmouse = userDefaultsToList "com.apple.AppleMultitouchMouse" cfg.magicmouse;
+ magicmouseBluetooth = userDefaultsToList "com.apple.driver.AppleMultitouchMouse.mouse" cfg.magicmouse;
+ screencapture = userDefaultsToList "com.apple.screencapture" cfg.screencapture;
+ screensaver = userDefaultsToList "com.apple.screensaver" cfg.screensaver;
+ spaces = userDefaultsToList "com.apple.spaces" cfg.spaces;
+ trackpad = userDefaultsToList "com.apple.AppleMultitouchTrackpad" cfg.trackpad;
+ trackpadBluetooth = userDefaultsToList "com.apple.driver.AppleBluetoothMultitouch.trackpad" cfg.trackpad;
+ universalaccess = userDefaultsToList "com.apple.universalaccess" cfg.universalaccess;
+ ActivityMonitor = userDefaultsToList "com.apple.ActivityMonitor" cfg.ActivityMonitor;
+ WindowManager = userDefaultsToList "com.apple.WindowManager" cfg.WindowManager;
+ controlcenter = userDefaultsToList "~${config.system.primaryUser}/Library/Preferences/ByHost/com.apple.controlcenter" cfg.controlcenter;
+ CustomUserPreferences = flatten (mapAttrsToList (name: value: userDefaultsToList name value) cfg.CustomUserPreferences);
mkIfLists = list: mkIf (any (attrs: attrs != [ ]) list);
@@ -57,6 +61,30 @@ in
else types.float.check x;
};
+ system.requiresPrimaryUser = concatMap
+ (scope: mapAttrsToList
+ (name: value: mkIf (value != null) (showOption [ "system" "defaults" scope name ]))
+ (if scope == "dock" then dockFiltered else cfg.${scope}))
+ [
+ "CustomUserPreferences"
+ ".GlobalPreferences"
+ "LaunchServices"
+ "NSGlobalDomain"
+ "menuExtraClock"
+ "dock"
+ "finder"
+ "hitoolbox"
+ "magicmouse"
+ "screencapture"
+ "screensaver"
+ "spaces"
+ "trackpad"
+ "universalaccess"
+ "ActivityMonitor"
+ "WindowManager"
+ "controlcenter"
+ ];
+
system.activationScripts.defaults.text = mkIfLists [
alf
loginwindow
@@ -122,11 +150,8 @@ in
${concatStringsSep "\n" controlcenter}
${optionalString (length dock > 0) ''
- # Only restart Dock if current user is logged in
- if pgrep -xu $UID Dock >/dev/null; then
- echo >&2 "restarting Dock..."
- killall Dock || true
- fi
+ echo >&2 "restarting Dock..."
+ killall -qu ${escapeShellArg config.system.primaryUser} Dock || true
''}
'';
diff --git a/tests/fixtures/system-defaults-write/activate.txt b/tests/fixtures/system-defaults-write/system.txt
similarity index 100%
rename from tests/fixtures/system-defaults-write/activate.txt
rename to tests/fixtures/system-defaults-write/system.txt
diff --git a/tests/fixtures/system-defaults-write/activate-user.txt b/tests/fixtures/system-defaults-write/user.txt
similarity index 57%
rename from tests/fixtures/system-defaults-write/activate-user.txt
rename to tests/fixtures/system-defaults-write/user.txt
index d93321ef..1cc99da0 100644
--- a/tests/fixtures/system-defaults-write/activate-user.txt
+++ b/tests/fixtures/system-defaults-write/user.txt
@@ -1,251 +1,251 @@
-defaults write -g 'AppleEnableMouseSwipeNavigateWithScrolls' $'
+sudo --user=test-defaults-user -- defaults write -g 'AppleEnableMouseSwipeNavigateWithScrolls' $'
'
-defaults write -g 'AppleEnableSwipeNavigateWithScrolls' $'
+sudo --user=test-defaults-user -- defaults write -g 'AppleEnableSwipeNavigateWithScrolls' $'
'
-defaults write -g 'AppleFontSmoothing' $'
+sudo --user=test-defaults-user -- defaults write -g 'AppleFontSmoothing' $'
1
'
-defaults write -g 'AppleICUForce24HourTime' $'
+sudo --user=test-defaults-user -- defaults write -g 'AppleICUForce24HourTime' $'
'
-defaults write -g 'AppleKeyboardUIMode' $'
+sudo --user=test-defaults-user -- defaults write -g 'AppleKeyboardUIMode' $'
3
'
-defaults write -g 'ApplePressAndHoldEnabled' $'
+sudo --user=test-defaults-user -- defaults write -g 'ApplePressAndHoldEnabled' $'
'
-defaults write -g 'AppleScrollerPagingBehavior' $'
+sudo --user=test-defaults-user -- defaults write -g 'AppleScrollerPagingBehavior' $'
'
-defaults write -g 'AppleShowAllExtensions' $'
+sudo --user=test-defaults-user -- defaults write -g 'AppleShowAllExtensions' $'
'
-defaults write -g 'AppleShowAllFiles' $'
+sudo --user=test-defaults-user -- defaults write -g 'AppleShowAllFiles' $'
'
-defaults write -g 'AppleShowScrollBars' $'
+sudo --user=test-defaults-user -- defaults write -g 'AppleShowScrollBars' $'
Always
'
-defaults write -g 'AppleSpacesSwitchOnActivate' $'
+sudo --user=test-defaults-user -- defaults write -g 'AppleSpacesSwitchOnActivate' $'
'
-defaults write -g 'AppleWindowTabbingMode' $'
+sudo --user=test-defaults-user -- defaults write -g 'AppleWindowTabbingMode' $'
always
'
-defaults write -g 'InitialKeyRepeat' $'
+sudo --user=test-defaults-user -- defaults write -g 'InitialKeyRepeat' $'
10
'
-defaults write -g 'KeyRepeat' $'
+sudo --user=test-defaults-user -- defaults write -g 'KeyRepeat' $'
1
'
-defaults write -g 'NSAutomaticCapitalizationEnabled' $'
+sudo --user=test-defaults-user -- defaults write -g 'NSAutomaticCapitalizationEnabled' $'
'
-defaults write -g 'NSAutomaticDashSubstitutionEnabled' $'
+sudo --user=test-defaults-user -- defaults write -g 'NSAutomaticDashSubstitutionEnabled' $'
'
-defaults write -g 'NSAutomaticInlinePredictionEnabled' $'
+sudo --user=test-defaults-user -- defaults write -g 'NSAutomaticInlinePredictionEnabled' $'
'
-defaults write -g 'NSAutomaticPeriodSubstitutionEnabled' $'
+sudo --user=test-defaults-user -- defaults write -g 'NSAutomaticPeriodSubstitutionEnabled' $'
'
-defaults write -g 'NSAutomaticQuoteSubstitutionEnabled' $'
+sudo --user=test-defaults-user -- defaults write -g 'NSAutomaticQuoteSubstitutionEnabled' $'
'
-defaults write -g 'NSAutomaticSpellingCorrectionEnabled' $'
+sudo --user=test-defaults-user -- defaults write -g 'NSAutomaticSpellingCorrectionEnabled' $'
'
-defaults write -g 'NSAutomaticWindowAnimationsEnabled' $'
+sudo --user=test-defaults-user -- defaults write -g 'NSAutomaticWindowAnimationsEnabled' $'
'
-defaults write -g 'NSDisableAutomaticTermination' $'
+sudo --user=test-defaults-user -- defaults write -g 'NSDisableAutomaticTermination' $'
'
-defaults write -g 'NSDocumentSaveNewDocumentsToCloud' $'
+sudo --user=test-defaults-user -- defaults write -g 'NSDocumentSaveNewDocumentsToCloud' $'
'
-defaults write -g 'NSNavPanelExpandedStateForSaveMode' $'
+sudo --user=test-defaults-user -- defaults write -g 'NSNavPanelExpandedStateForSaveMode' $'
'
-defaults write -g 'NSNavPanelExpandedStateForSaveMode2' $'
+sudo --user=test-defaults-user -- defaults write -g 'NSNavPanelExpandedStateForSaveMode2' $'
'
-defaults write -g 'NSScrollAnimationEnabled' $'
+sudo --user=test-defaults-user -- defaults write -g 'NSScrollAnimationEnabled' $'
'
-defaults write -g 'NSTableViewDefaultSizeMode' $'
+sudo --user=test-defaults-user -- defaults write -g 'NSTableViewDefaultSizeMode' $'
2
'
-defaults write -g 'NSTextShowsControlCharacters' $'
+sudo --user=test-defaults-user -- defaults write -g 'NSTextShowsControlCharacters' $'
'
-defaults write -g 'NSUseAnimatedFocusRing' $'
+sudo --user=test-defaults-user -- defaults write -g 'NSUseAnimatedFocusRing' $'
'
-defaults write -g 'NSWindowResizeTime' $'
+sudo --user=test-defaults-user -- defaults write -g 'NSWindowResizeTime' $'
0.010000
'
-defaults write -g 'NSWindowShouldDragOnGesture' $'
+sudo --user=test-defaults-user -- defaults write -g 'NSWindowShouldDragOnGesture' $'
'
-defaults write -g 'PMPrintingExpandedStateForPrint' $'
+sudo --user=test-defaults-user -- defaults write -g 'PMPrintingExpandedStateForPrint' $'
'
-defaults write -g 'PMPrintingExpandedStateForPrint2' $'
+sudo --user=test-defaults-user -- defaults write -g 'PMPrintingExpandedStateForPrint2' $'
'
-defaults write -g 'com.apple.keyboard.fnState' $'
+sudo --user=test-defaults-user -- defaults write -g 'com.apple.keyboard.fnState' $'
'
-defaults write -g 'com.apple.mouse.tapBehavior' $'
+sudo --user=test-defaults-user -- defaults write -g 'com.apple.mouse.tapBehavior' $'
1
'
-defaults write -g 'com.apple.springing.delay' $'
+sudo --user=test-defaults-user -- defaults write -g 'com.apple.springing.delay' $'
0.000000
'
-defaults write -g 'com.apple.springing.enabled' $'
+sudo --user=test-defaults-user -- defaults write -g 'com.apple.springing.enabled' $'
'
-defaults write -g 'com.apple.swipescrolldirection' $'
+sudo --user=test-defaults-user -- defaults write -g 'com.apple.swipescrolldirection' $'
'
-defaults write -g 'com.apple.trackpad.enableSecondaryClick' $'
+sudo --user=test-defaults-user -- defaults write -g 'com.apple.trackpad.enableSecondaryClick' $'
'
-defaults write -g 'com.apple.trackpad.trackpadCornerClickBehavior' $'
+sudo --user=test-defaults-user -- defaults write -g 'com.apple.trackpad.trackpadCornerClickBehavior' $'
1
'
-defaults write .GlobalPreferences 'com.apple.sound.beep.sound' $'
+sudo --user=test-defaults-user -- defaults write .GlobalPreferences 'com.apple.sound.beep.sound' $'
/System/Library/Sounds/Funk.aiff
'
-defaults write com.apple.menuextra.clock 'FlashDateSeparators' $'
+sudo --user=test-defaults-user -- defaults write com.apple.menuextra.clock 'FlashDateSeparators' $'
'
-defaults write com.apple.menuextra.clock 'Show24Hour' $'
+sudo --user=test-defaults-user -- defaults write com.apple.menuextra.clock 'Show24Hour' $'
'
-defaults write com.apple.menuextra.clock 'ShowDate' $'
+sudo --user=test-defaults-user -- defaults write com.apple.menuextra.clock 'ShowDate' $'
2
'
-defaults write com.apple.menuextra.clock 'ShowDayOfWeek' $'
+sudo --user=test-defaults-user -- defaults write com.apple.menuextra.clock 'ShowDayOfWeek' $'
'
-defaults write com.apple.dock 'appswitcher-all-displays' $'
+sudo --user=test-defaults-user -- defaults write com.apple.dock 'appswitcher-all-displays' $'
'
-defaults write com.apple.dock 'autohide-delay' $'
+sudo --user=test-defaults-user -- defaults write com.apple.dock 'autohide-delay' $'
0.240000
'
-defaults write com.apple.dock 'expose-group-apps' $'
+sudo --user=test-defaults-user -- defaults write com.apple.dock 'expose-group-apps' $'
'
-defaults write com.apple.dock 'orientation' $'
+sudo --user=test-defaults-user -- defaults write com.apple.dock 'orientation' $'
left
'
-defaults write com.apple.dock 'persistent-apps' $'
+sudo --user=test-defaults-user -- defaults write com.apple.dock 'persistent-apps' $'
@@ -319,7 +319,7 @@ defaults write com.apple.dock 'persistent-apps' $'
'
-defaults write com.apple.dock 'persistent-others' $'
+sudo --user=test-defaults-user -- defaults write com.apple.dock 'persistent-others' $'
@@ -353,134 +353,134 @@ defaults write com.apple.dock 'persistent-others' $'
'
-defaults write com.apple.dock 'scroll-to-open' $'
+sudo --user=test-defaults-user -- defaults write com.apple.dock 'scroll-to-open' $'
'
-defaults write com.apple.finder 'AppleShowAllExtensions' $'
+sudo --user=test-defaults-user -- defaults write com.apple.finder 'AppleShowAllExtensions' $'
'
-defaults write com.apple.finder 'AppleShowAllFiles' $'
+sudo --user=test-defaults-user -- defaults write com.apple.finder 'AppleShowAllFiles' $'
'
-defaults write com.apple.finder 'CreateDesktop' $'
+sudo --user=test-defaults-user -- defaults write com.apple.finder 'CreateDesktop' $'
'
-defaults write com.apple.finder 'FXDefaultSearchScope' $'
+sudo --user=test-defaults-user -- defaults write com.apple.finder 'FXDefaultSearchScope' $'
SCcf
'
-defaults write com.apple.finder 'FXEnableExtensionChangeWarning' $'
+sudo --user=test-defaults-user -- defaults write com.apple.finder 'FXEnableExtensionChangeWarning' $'
'
-defaults write com.apple.finder 'FXPreferredViewStyle' $'
+sudo --user=test-defaults-user -- defaults write com.apple.finder 'FXPreferredViewStyle' $'
Flwv
'
-defaults write com.apple.finder 'FXRemoveOldTrashItems' $'
+sudo --user=test-defaults-user -- defaults write com.apple.finder 'FXRemoveOldTrashItems' $'
'
-defaults write com.apple.finder 'NewWindowTarget' $'
+sudo --user=test-defaults-user -- defaults write com.apple.finder 'NewWindowTarget' $'
PfLo
'
-defaults write com.apple.finder 'NewWindowTargetPath' $'
+sudo --user=test-defaults-user -- defaults write com.apple.finder 'NewWindowTargetPath' $'
file:///Library/Apple
'
-defaults write com.apple.finder 'QuitMenuItem' $'
+sudo --user=test-defaults-user -- defaults write com.apple.finder 'QuitMenuItem' $'
'
-defaults write com.apple.finder 'ShowExternalHardDrivesOnDesktop' $'
+sudo --user=test-defaults-user -- defaults write com.apple.finder 'ShowExternalHardDrivesOnDesktop' $'
'
-defaults write com.apple.finder 'ShowHardDrivesOnDesktop' $'
+sudo --user=test-defaults-user -- defaults write com.apple.finder 'ShowHardDrivesOnDesktop' $'
'
-defaults write com.apple.finder 'ShowMountedServersOnDesktop' $'
+sudo --user=test-defaults-user -- defaults write com.apple.finder 'ShowMountedServersOnDesktop' $'
'
-defaults write com.apple.finder 'ShowPathbar' $'
+sudo --user=test-defaults-user -- defaults write com.apple.finder 'ShowPathbar' $'
'
-defaults write com.apple.finder 'ShowRemovableMediaOnDesktop' $'
+sudo --user=test-defaults-user -- defaults write com.apple.finder 'ShowRemovableMediaOnDesktop' $'
'
-defaults write com.apple.finder 'ShowStatusBar' $'
+sudo --user=test-defaults-user -- defaults write com.apple.finder 'ShowStatusBar' $'
'
-defaults write com.apple.finder '_FXShowPosixPathInTitle' $'
+sudo --user=test-defaults-user -- defaults write com.apple.finder '_FXShowPosixPathInTitle' $'
'
-defaults write com.apple.finder '_FXSortFoldersFirst' $'
+sudo --user=test-defaults-user -- defaults write com.apple.finder '_FXSortFoldersFirst' $'
'
-defaults write com.apple.finder '_FXSortFoldersFirstOnDesktop' $'
+sudo --user=test-defaults-user -- defaults write com.apple.finder '_FXSortFoldersFirstOnDesktop' $'
'
-defaults write com.apple.HIToolbox 'AppleFnUsageType' $'
+sudo --user=test-defaults-user -- defaults write com.apple.HIToolbox 'AppleFnUsageType' $'
2
'
-defaults write com.apple.screencapture 'include-date' $'
+sudo --user=test-defaults-user -- defaults write com.apple.screencapture 'include-date' $'
'
-defaults write com.apple.screencapture 'location' $'
+sudo --user=test-defaults-user -- defaults write com.apple.screencapture 'location' $'
/tmp
'
-defaults write com.apple.screencapture 'target' $'
+sudo --user=test-defaults-user -- defaults write com.apple.screencapture 'target' $'
file
'
-defaults write com.apple.screensaver 'askForPassword' $'
+sudo --user=test-defaults-user -- defaults write com.apple.screensaver 'askForPassword' $'
'
-defaults write com.apple.screensaver 'askForPasswordDelay' $'
+sudo --user=test-defaults-user -- defaults write com.apple.screensaver 'askForPasswordDelay' $'
5
@@ -488,62 +488,62 @@ defaults write com.apple.screensaver 'askForPasswordDelay' $'
+sudo --user=test-defaults-user -- defaults write com.apple.universalaccess 'closeViewScrollWheelToggle' $'
'
-defaults write com.apple.universalaccess 'closeViewZoomFollowsFocus' $'
+sudo --user=test-defaults-user -- defaults write com.apple.universalaccess 'closeViewZoomFollowsFocus' $'
'
-defaults write com.apple.universalaccess 'mouseDriverCursorSize' $'
+sudo --user=test-defaults-user -- defaults write com.apple.universalaccess 'mouseDriverCursorSize' $'
1.500000
'
-defaults write com.apple.universalaccess 'reduceMotion' $'
+sudo --user=test-defaults-user -- defaults write com.apple.universalaccess 'reduceMotion' $'
'
-defaults write com.apple.universalaccess 'reduceTransparency' $'
+sudo --user=test-defaults-user -- defaults write com.apple.universalaccess 'reduceTransparency' $'
'
-defaults write com.apple.ActivityMonitor 'IconType' $'
+sudo --user=test-defaults-user -- defaults write com.apple.ActivityMonitor 'IconType' $'
3
'
-defaults write com.apple.ActivityMonitor 'OpenMainWindow' $'
+sudo --user=test-defaults-user -- defaults write com.apple.ActivityMonitor 'OpenMainWindow' $'
'
-defaults write com.apple.ActivityMonitor 'ShowCategory' $'
+sudo --user=test-defaults-user -- defaults write com.apple.ActivityMonitor 'ShowCategory' $'
103
'
-defaults write com.apple.ActivityMonitor 'SortColumn' $'
+sudo --user=test-defaults-user -- defaults write com.apple.ActivityMonitor 'SortColumn' $'
CPUUsage
'
-defaults write com.apple.ActivityMonitor 'SortDirection' $'
+sudo --user=test-defaults-user -- defaults write com.apple.ActivityMonitor 'SortDirection' $'
0
'
-defaults write NSGlobalDomain 'TISRomanSwitchState' $'
+sudo --user=test-defaults-user -- defaults write NSGlobalDomain 'TISRomanSwitchState' $'
1
'
-defaults write com.apple.Safari 'NSUserKeyEquivalents' $'
+sudo --user=test-defaults-user -- defaults write com.apple.Safari 'NSUserKeyEquivalents' $'
@@ -551,102 +551,102 @@ defaults write com.apple.Safari 'NSUserKeyEquivalents' $'@^q
'
-defaults write com.apple.Safari 'com.apple.Safari.ContentPageGroupIdentifier.WebKit2DeveloperExtrasEnabled' $'
+sudo --user=test-defaults-user -- defaults write com.apple.Safari 'com.apple.Safari.ContentPageGroupIdentifier.WebKit2DeveloperExtrasEnabled' $'
'
-defaults write com.apple.WindowManager 'AppWindowGroupingBehavior' $'
+sudo --user=test-defaults-user -- defaults write com.apple.WindowManager 'AppWindowGroupingBehavior' $'
'
-defaults write com.apple.WindowManager 'AutoHide' $'
+sudo --user=test-defaults-user -- defaults write com.apple.WindowManager 'AutoHide' $'
'
-defaults write com.apple.WindowManager 'EnableStandardClickToShowDesktop' $'
+sudo --user=test-defaults-user -- defaults write com.apple.WindowManager 'EnableStandardClickToShowDesktop' $'
'
-defaults write com.apple.WindowManager 'EnableTiledWindowMargins' $'
+sudo --user=test-defaults-user -- defaults write com.apple.WindowManager 'EnableTiledWindowMargins' $'
'
-defaults write com.apple.WindowManager 'EnableTilingByEdgeDrag' $'
+sudo --user=test-defaults-user -- defaults write com.apple.WindowManager 'EnableTilingByEdgeDrag' $'
'
-defaults write com.apple.WindowManager 'EnableTilingOptionAccelerator' $'
+sudo --user=test-defaults-user -- defaults write com.apple.WindowManager 'EnableTilingOptionAccelerator' $'
'
-defaults write com.apple.WindowManager 'EnableTopTilingByEdgeDrag' $'
+sudo --user=test-defaults-user -- defaults write com.apple.WindowManager 'EnableTopTilingByEdgeDrag' $'
'
-defaults write com.apple.WindowManager 'GloballyEnabled' $'
+sudo --user=test-defaults-user -- defaults write com.apple.WindowManager 'GloballyEnabled' $'
'
-defaults write com.apple.WindowManager 'HideDesktop' $'
+sudo --user=test-defaults-user -- defaults write com.apple.WindowManager 'HideDesktop' $'
'
-defaults write com.apple.WindowManager 'StageManagerHideWidgets' $'
+sudo --user=test-defaults-user -- defaults write com.apple.WindowManager 'StageManagerHideWidgets' $'
'
-defaults write com.apple.WindowManager 'StandardHideDesktopIcons' $'
+sudo --user=test-defaults-user -- defaults write com.apple.WindowManager 'StandardHideDesktopIcons' $'
'
-defaults write com.apple.WindowManager 'StandardHideWidgets' $'
+sudo --user=test-defaults-user -- defaults write com.apple.WindowManager 'StandardHideWidgets' $'
'
-defaults write ~/Library/Preferences/ByHost/com.apple.controlcenter 'AirDrop' $'
+sudo --user=test-defaults-user -- defaults write ~test-defaults-user/Library/Preferences/ByHost/com.apple.controlcenter 'AirDrop' $'
18
'
-defaults write ~/Library/Preferences/ByHost/com.apple.controlcenter 'BatteryShowPercentage' $'
+sudo --user=test-defaults-user -- defaults write ~test-defaults-user/Library/Preferences/ByHost/com.apple.controlcenter 'BatteryShowPercentage' $'
'
-defaults write ~/Library/Preferences/ByHost/com.apple.controlcenter 'Bluetooth' $'
+sudo --user=test-defaults-user -- defaults write ~test-defaults-user/Library/Preferences/ByHost/com.apple.controlcenter 'Bluetooth' $'
18
'
-defaults write ~/Library/Preferences/ByHost/com.apple.controlcenter 'Display' $'
+sudo --user=test-defaults-user -- defaults write ~test-defaults-user/Library/Preferences/ByHost/com.apple.controlcenter 'Display' $'
24
'
-defaults write ~/Library/Preferences/ByHost/com.apple.controlcenter 'FocusModes' $'
+sudo --user=test-defaults-user -- defaults write ~test-defaults-user/Library/Preferences/ByHost/com.apple.controlcenter 'FocusModes' $'
24
'
-defaults write ~/Library/Preferences/ByHost/com.apple.controlcenter 'NowPlaying' $'
+sudo --user=test-defaults-user -- defaults write ~test-defaults-user/Library/Preferences/ByHost/com.apple.controlcenter 'NowPlaying' $'
18
'
-defaults write ~/Library/Preferences/ByHost/com.apple.controlcenter 'Sound' $'
+sudo --user=test-defaults-user -- defaults write ~test-defaults-user/Library/Preferences/ByHost/com.apple.controlcenter 'Sound' $'
24
diff --git a/tests/system-defaults-write.nix b/tests/system-defaults-write.nix
index 35ff8532..b4b5b7b2 100644
--- a/tests/system-defaults-write.nix
+++ b/tests/system-defaults-write.nix
@@ -1,6 +1,8 @@
{ config, pkgs, lib, ... }:
{
+ system.primaryUser = "test-defaults-user";
+
imports = [
{
system.defaults.CustomUserPreferences = {
@@ -137,18 +139,18 @@
system.defaults.controlcenter.NowPlaying = true;
test = lib.strings.concatMapStringsSep "\n"
(x: ''
- echo >&2 "checking defaults write in /${x}"
+ echo >&2 "checking ${x} defaults write in /activate"
${pkgs.python3}/bin/python3 <