2021-02-04 00:46:16 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.targets.darwin;
|
|
|
|
|
|
|
|
toDefaultsFile = domain: attrs:
|
|
|
|
pkgs.writeText "${domain}.plist" (lib.generators.toPlist { } attrs);
|
|
|
|
|
|
|
|
toActivationCmd = domain: attrs:
|
|
|
|
"$DRY_RUN_CMD defaults import ${escapeShellArg domain} ${
|
|
|
|
toDefaultsFile domain attrs
|
|
|
|
}";
|
|
|
|
|
|
|
|
nonNullDefaults =
|
|
|
|
mapAttrs (domain: attrs: (filterAttrs (n: v: v != null) attrs))
|
|
|
|
cfg.defaults;
|
|
|
|
writableDefaults = filterAttrs (domain: attrs: attrs != { }) nonNullDefaults;
|
|
|
|
activationCmds = mapAttrsToList toActivationCmd writableDefaults;
|
|
|
|
in {
|
2021-11-29 16:43:04 +01:00
|
|
|
meta.maintainers = [ maintainers.midchildan ];
|
|
|
|
|
2021-02-21 06:34:56 +01:00
|
|
|
imports = [ ./fonts.nix ./keybindings.nix ./linkapps.nix ./search.nix ];
|
2021-02-04 00:46:16 +01:00
|
|
|
|
|
|
|
options.targets.darwin.defaults = mkOption {
|
|
|
|
type = types.submodule ./options.nix;
|
|
|
|
default = { };
|
|
|
|
example = {
|
|
|
|
"com.apple.desktopservices" = {
|
|
|
|
DSDontWriteNetworkStores = true;
|
|
|
|
DSDontWriteUSBStores = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
description = ''
|
|
|
|
Set macOS user defaults. Values set to <literal>null</literal> are
|
|
|
|
ignored.
|
|
|
|
|
|
|
|
<warning>
|
|
|
|
<para>
|
|
|
|
Some settings might require a re-login to take effect.
|
|
|
|
</para>
|
|
|
|
</warning>
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf (activationCmds != [ ]) {
|
2021-07-07 23:24:27 +02:00
|
|
|
assertions = [
|
|
|
|
(hm.assertions.assertPlatform "targets.darwin.defaults" pkgs
|
|
|
|
platforms.darwin)
|
|
|
|
];
|
|
|
|
|
2021-11-29 16:18:26 +01:00
|
|
|
warnings = let
|
|
|
|
batteryPercentage =
|
|
|
|
attrByPath [ "com.apple.menuextra.battery" "ShowPercent" ] null
|
|
|
|
cfg.defaults;
|
|
|
|
webkitDevExtras = attrByPath [
|
|
|
|
"com.apple.Safari"
|
|
|
|
"com.apple.Safari.ContentPageGroupIdentifier.WebKit2DeveloperExtrasEnabled"
|
|
|
|
] null cfg.defaults;
|
|
|
|
in optional (batteryPercentage != null) ''
|
|
|
|
The option 'com.apple.menuextra.battery.ShowPercent' no longer works on
|
|
|
|
macOS 11 and later. Instead, open System Preferences, go to "Dock &
|
|
|
|
Menu Bar", select "Battery", and toggle the checkbox labeled "Show
|
|
|
|
Percentage."
|
|
|
|
'' ++ optional (webkitDevExtras != null) ''
|
|
|
|
The option 'com.apple.Safari.com.apple.Safari.ContentPageGroupIdentifier.WebKit2DeveloperExtrasEnabled'
|
|
|
|
is no longer present in recent versions of Safari.
|
|
|
|
'';
|
|
|
|
|
2021-02-04 00:46:16 +01:00
|
|
|
home.activation.setDarwinDefaults = hm.dag.entryAfter [ "writeBoundary" ] ''
|
|
|
|
$VERBOSE_ECHO "Configuring macOS user defaults"
|
|
|
|
${concatStringsSep "\n" activationCmds}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
}
|