fork/home-manager

git clone https://git.julia.blue/fork/home-manager

Robert HelgessonMerge PR #421575790441

master
1.4 KiB45 linesraw
1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6  cfg = config.targets.darwin;
7  homeDir = config.home.homeDirectory;
8  confFile = pkgs.writeText "DefaultKeybinding.dict"
9    (lib.generators.toPlist { } cfg.keybindings);
10in {
11  options.targets.darwin.keybindings = mkOption {
12    type = with types; attrsOf anything;
13    default = { };
14    example = {
15      "^u" = "deleteToBeginningOfLine:";
16      "^w" = "deleteWordBackward:";
17    };
18    description = ''
19      This will configure the default keybindings for text fields in macOS
20      applications. See
21      [Apple's documentation](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/EventOverview/TextDefaultsBindings/TextDefaultsBindings.html)
22      for more details.
23
24      ::: {.warning}
25      Existing keybinding configuration will be wiped when using this
26      option.
27      :::
28    '';
29  };
30
31  config = mkIf (cfg.keybindings != { }) {
32    assertions = [
33      (hm.assertions.assertPlatform "targets.darwin.keybindings" pkgs
34        platforms.darwin)
35    ];
36
37    # NOTE: just copy the files because symlinks won't be recognized by macOS
38    home.activation.setCocoaKeybindings =
39      hm.dag.entryAfter [ "writeBoundary" ] ''
40        $VERBOSE_ECHO "Configuring keybindings for the Cocoa Text System"
41        $DRY_RUN_CMD install -Dm644 $VERBOSE_ARG \
42          "${confFile}" "${homeDir}/Library/KeyBindings/DefaultKeyBinding.dict"
43      '';
44  };
45}