1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-16 08:09:45 +01:00
home-manager/modules/targets/darwin/default.nix
midchildan 9dad146639
targets/darwin: add more options for configuring macOS (#1753)
Add new options Darwin options:

- `targets.darwin.defaults`
  This adds options for configuring macOS through the `defaults(1)` system.
  This option can be used to manipulate a vast majority of user settings for macOS
  and its applications.

  This is implemented using freeform modules and includes additional descriptions
  and type information for some useful options.

- `targets.darwin.keybindings`
  This adds options for configuring the default keybindings for macOS text fields.

- `targets.darwin.search`
  This adds options for configuring the default search engine for macOS.
2021-02-03 18:46:16 -05:00

51 lines
1.4 KiB
Nix

{ 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 {
imports = [ ./keybindings.nix ./linkapps.nix ./search.nix ];
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 != [ ]) {
home.activation.setDarwinDefaults = hm.dag.entryAfter [ "writeBoundary" ] ''
$VERBOSE_ECHO "Configuring macOS user defaults"
${concatStringsSep "\n" activationCmds}
'';
};
}