2016-12-14 12:05:23 +00:00
|
|
|
{ config, lib, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.system.defaults;
|
|
|
|
|
2018-01-01 00:20:27 +00:00
|
|
|
isFloat = x: isString x && builtins.match "^[+-]?([0-9]*[.])?[0-9]+$" x != null;
|
2017-12-31 02:44:02 +00:00
|
|
|
|
2016-12-14 12:05:23 +00:00
|
|
|
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
|
2017-12-31 02:44:02 +00:00
|
|
|
if isFloat value then "-float ${toString value}" else
|
2016-12-14 12:05:23 +00:00
|
|
|
if isString value then "-string '${value}'" else
|
|
|
|
throw "invalid value type";
|
|
|
|
|
|
|
|
writeDefault = domain: key: value:
|
|
|
|
"defaults write ${domain} '${key}' ${writeValue value}";
|
|
|
|
|
|
|
|
defaultsToList = domain: attrs: mapAttrsToList (writeDefault domain) (filterAttrs (n: v: v != null) attrs);
|
|
|
|
|
|
|
|
NSGlobalDomain = defaultsToList "-g" cfg.NSGlobalDomain;
|
2019-08-19 14:02:59 +00:00
|
|
|
GlobalPreferences = defaultsToList ".GlobalPreferences" cfg.".GlobalPreferences";
|
2016-12-14 12:05:23 +00:00
|
|
|
LaunchServices = defaultsToList "com.apple.LaunchServices" cfg.LaunchServices;
|
|
|
|
dock = defaultsToList "com.apple.dock" cfg.dock;
|
|
|
|
finder = defaultsToList "com.apple.finder" cfg.finder;
|
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;
|
2018-02-27 17:24:45 +00:00
|
|
|
screencapture = defaultsToList "com.apple.screencapture" cfg.screencapture;
|
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;
|
2016-12-14 12:05:23 +00:00
|
|
|
|
2018-01-17 22:10:57 +00:00
|
|
|
mkIfAttrs = list: mkIf (any (attrs: attrs != {}) list);
|
2016-12-14 12:05:23 +00:00
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
config = {
|
|
|
|
|
2019-11-04 04:35:56 +00:00
|
|
|
system.activationScripts.defaults.text = mkIfAttrs [ alf loginwindow smb ]
|
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}
|
|
|
|
'';
|
|
|
|
|
|
|
|
system.activationScripts.userDefaults.text = mkIfAttrs
|
2019-11-04 04:06:54 +00:00
|
|
|
[ NSGlobalDomain GlobalPreferences LaunchServices dock finder screencapture spaces trackpad trackpadBluetooth ]
|
2018-01-17 22:10:57 +00:00
|
|
|
''
|
|
|
|
# Set defaults
|
|
|
|
echo >&2 "user defaults..."
|
|
|
|
|
|
|
|
${concatStringsSep "\n" NSGlobalDomain}
|
2019-08-19 14:02:59 +00:00
|
|
|
${concatStringsSep "\n" GlobalPreferences}
|
2018-01-17 22:10:57 +00:00
|
|
|
${concatStringsSep "\n" LaunchServices}
|
|
|
|
${concatStringsSep "\n" dock}
|
|
|
|
${concatStringsSep "\n" finder}
|
2018-02-27 17:24:45 +00:00
|
|
|
${concatStringsSep "\n" screencapture}
|
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}
|
|
|
|
'';
|
2016-12-14 12:05:23 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
}
|