aboutsummaryrefslogtreecommitdiff
path: root/infra/libkookie/home-manager/modules/targets/darwin/default.nix
blob: b971e18d2179a4cad00d7847ccae34e731df20f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
{ 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 = [ ./fonts.nix ./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}
    '';
  };
}