2016-12-14 12:05:23 +00:00
|
|
|
{ config, lib, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.system.defaults;
|
|
|
|
|
|
|
|
writeDefault = domain: key: value:
|
2023-10-11 06:10:58 +00:00
|
|
|
"defaults write ${domain} '${key}' $'${strings.escape [ "'" ] (generators.toPlist { } value)}'";
|
2016-12-14 12:05:23 +00:00
|
|
|
|
|
|
|
defaultsToList = domain: attrs: mapAttrsToList (writeDefault domain) (filterAttrs (n: v: v != null) attrs);
|
|
|
|
|
2021-12-24 22:24:04 +00:00
|
|
|
# defaults
|
2019-11-04 03:56:21 +00:00
|
|
|
alf = defaultsToList "/Library/Preferences/com.apple.alf" cfg.alf;
|
2019-11-04 04:35:56 +00:00
|
|
|
loginwindow = defaultsToList "/Library/Preferences/com.apple.loginwindow" cfg.loginwindow;
|
2018-01-04 23:15:11 +00:00
|
|
|
smb = defaultsToList "/Library/Preferences/SystemConfiguration/com.apple.smb.server" cfg.smb;
|
2019-11-04 04:54:31 +00:00
|
|
|
SoftwareUpdate = defaultsToList "/Library/Preferences/SystemConfiguration/com.apple.SoftwareUpdate" cfg.SoftwareUpdate;
|
2021-12-24 22:24:04 +00:00
|
|
|
|
|
|
|
# userDefaults
|
|
|
|
GlobalPreferences = defaultsToList ".GlobalPreferences" cfg.".GlobalPreferences";
|
|
|
|
LaunchServices = defaultsToList "com.apple.LaunchServices" cfg.LaunchServices;
|
|
|
|
NSGlobalDomain = defaultsToList "-g" cfg.NSGlobalDomain;
|
2023-05-15 17:18:38 +00:00
|
|
|
menuExtraClock = defaultsToList "com.apple.menuextra.clock" cfg.menuExtraClock;
|
2021-12-24 22:24:04 +00:00
|
|
|
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;
|
2018-02-27 17:24:45 +00:00
|
|
|
screencapture = defaultsToList "com.apple.screencapture" cfg.screencapture;
|
2023-04-23 12:11:44 +00:00
|
|
|
screensaver = defaultsToList "com.apple.screensaver" cfg.screensaver;
|
2019-11-04 04:06:54 +00:00
|
|
|
spaces = defaultsToList "com.apple.spaces" cfg.spaces;
|
2017-10-03 19:13:51 +00:00
|
|
|
trackpad = defaultsToList "com.apple.AppleMultitouchTrackpad" cfg.trackpad;
|
|
|
|
trackpadBluetooth = defaultsToList "com.apple.driver.AppleBluetoothMultitouch.trackpad" cfg.trackpad;
|
2021-12-24 22:48:08 +00:00
|
|
|
universalaccess = defaultsToList "com.apple.universalaccess" cfg.universalaccess;
|
2022-03-11 02:53:55 +00:00
|
|
|
ActivityMonitor = defaultsToList "com.apple.ActivityMonitor" cfg.ActivityMonitor;
|
2022-10-24 12:12:54 +00:00
|
|
|
CustomUserPreferences = flatten (mapAttrsToList (name: value: defaultsToList name value) cfg.CustomUserPreferences);
|
|
|
|
CustomSystemPreferences = flatten (mapAttrsToList (name: value: defaultsToList name value) cfg.CustomSystemPreferences);
|
2016-12-14 12:05:23 +00:00
|
|
|
|
2021-12-24 22:20:15 +00:00
|
|
|
mkIfAttrs = list: mkIf (any (attrs: attrs != { }) list);
|
2016-12-14 12:05:23 +00:00
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
config = {
|
|
|
|
|
2022-08-29 22:39:16 +00:00
|
|
|
# Type used for `system.defaults.<domain>.*` options that previously accepted float values as a
|
|
|
|
# string.
|
|
|
|
lib.defaults.types.floatWithDeprecationError = types.float // {
|
|
|
|
check = x:
|
|
|
|
if isString x && builtins.match "^[+-]?([0-9]*[.])?[0-9]+$" x != null
|
|
|
|
then throw "Using strings for `system.defaults.<domain>.*' options of type float is no longer permitted, use native float values instead."
|
|
|
|
else types.float.check x;
|
|
|
|
};
|
|
|
|
|
2021-12-24 22:20:15 +00:00
|
|
|
system.activationScripts.defaults.text = mkIfAttrs [
|
|
|
|
alf
|
|
|
|
loginwindow
|
|
|
|
smb
|
|
|
|
SoftwareUpdate
|
2022-10-24 12:12:54 +00:00
|
|
|
CustomSystemPreferences
|
2021-12-24 22:20:15 +00:00
|
|
|
]
|
2018-01-17 22:10:57 +00:00
|
|
|
''
|
|
|
|
# Set defaults
|
|
|
|
echo >&2 "system defaults..."
|
2019-11-04 03:56:21 +00:00
|
|
|
${concatStringsSep "\n" alf}
|
2019-11-04 04:35:56 +00:00
|
|
|
${concatStringsSep "\n" loginwindow}
|
2018-01-17 22:10:57 +00:00
|
|
|
${concatStringsSep "\n" smb}
|
2019-11-04 04:54:31 +00:00
|
|
|
${concatStringsSep "\n" SoftwareUpdate}
|
2022-10-24 12:12:54 +00:00
|
|
|
${concatStringsSep "\n" CustomSystemPreferences}
|
2018-01-17 22:10:57 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
system.activationScripts.userDefaults.text = mkIfAttrs
|
2021-12-24 22:20:15 +00:00
|
|
|
[
|
|
|
|
GlobalPreferences
|
|
|
|
LaunchServices
|
2021-12-24 22:24:04 +00:00
|
|
|
NSGlobalDomain
|
2023-05-15 17:18:38 +00:00
|
|
|
menuExtraClock
|
2021-12-24 22:20:15 +00:00
|
|
|
dock
|
|
|
|
finder
|
2021-12-24 22:24:04 +00:00
|
|
|
magicmouse
|
|
|
|
magicmouseBluetooth
|
2021-12-24 22:20:15 +00:00
|
|
|
screencapture
|
2023-04-23 12:11:44 +00:00
|
|
|
screensaver
|
2021-12-24 22:20:15 +00:00
|
|
|
spaces
|
|
|
|
trackpad
|
|
|
|
trackpadBluetooth
|
2021-12-24 22:48:08 +00:00
|
|
|
universalaccess
|
2022-03-11 02:53:55 +00:00
|
|
|
ActivityMonitor
|
2022-10-24 12:12:54 +00:00
|
|
|
CustomUserPreferences
|
2021-12-24 22:20:15 +00:00
|
|
|
]
|
2018-01-17 22:10:57 +00:00
|
|
|
''
|
|
|
|
# Set defaults
|
|
|
|
echo >&2 "user defaults..."
|
|
|
|
|
|
|
|
${concatStringsSep "\n" NSGlobalDomain}
|
2021-12-24 22:24:04 +00:00
|
|
|
|
2019-08-19 14:02:59 +00:00
|
|
|
${concatStringsSep "\n" GlobalPreferences}
|
2018-01-17 22:10:57 +00:00
|
|
|
${concatStringsSep "\n" LaunchServices}
|
2023-05-15 17:18:38 +00:00
|
|
|
${concatStringsSep "\n" menuExtraClock}
|
2018-01-17 22:10:57 +00:00
|
|
|
${concatStringsSep "\n" dock}
|
|
|
|
${concatStringsSep "\n" finder}
|
2021-12-24 22:24:04 +00:00
|
|
|
${concatStringsSep "\n" magicmouse}
|
|
|
|
${concatStringsSep "\n" magicmouseBluetooth}
|
2018-02-27 17:24:45 +00:00
|
|
|
${concatStringsSep "\n" screencapture}
|
2023-04-23 12:11:44 +00:00
|
|
|
${concatStringsSep "\n" screensaver}
|
2019-11-04 04:06:54 +00:00
|
|
|
${concatStringsSep "\n" spaces}
|
2018-01-17 22:10:57 +00:00
|
|
|
${concatStringsSep "\n" trackpad}
|
|
|
|
${concatStringsSep "\n" trackpadBluetooth}
|
2021-12-24 22:48:08 +00:00
|
|
|
${concatStringsSep "\n" universalaccess}
|
2022-03-11 02:53:55 +00:00
|
|
|
${concatStringsSep "\n" ActivityMonitor}
|
2022-10-24 12:12:54 +00:00
|
|
|
${concatStringsSep "\n" CustomUserPreferences}
|
2018-01-17 22:10:57 +00:00
|
|
|
'';
|
2016-12-14 12:05:23 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
}
|