summaryrefslogtreecommitdiff
path: root/alacritty/default.nix
blob: 0a842297ca6254b007825b307f777c23438720e5 (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
52
53
54
55
56
57
58
59
60
61
62
63
{

  config,
  zsh,

  pkgs ? (import ../pkgs.nix).edge {},

}: rec {

  defaultXDGOpenRules = [
    {
      name = "open-url";
      pattern = "(ipfs:|ipns:|magnet:|mailto:|gemini:|gopher:|https:|http:|news:|file:|git:|ssh:|ftp:)[^<>\"\\s{-}\\^⟨⟩`]+";
      xdgOpen = "$1";
    }
  ];

  xdgOpenRules = defaultXDGOpenRules ++ config.alacritty.xdgOpenRules;

  alacrittyUnwrap = pkgs.writeShellScript "alacritty-unwrap" ''
    unset LD_LIBRARY_PATH
    unset __EGL_VENDOR_LIBRARY_DIRS
    exec "$@"
  '';

  hints = {
    enabled = (builtins.map (r:
      {
        regex = r.pattern;
        hyperlinks = true;
        command = (pkgs.writeShellScript "alacritty-hints-${r.name}" ''
          ${alacrittyUnwrap} xdg-open "${r.xdgOpen}"
        '');
        post_processing = true;
        mouse.enabled = true;
      }
    ) xdgOpenRules);
  };

  configFile = pkgs.writeText "alacritty-config" (
    builtins.replaceStrings
      ["$HINTS"]
      [(builtins.toJSON hints)]
      (builtins.readFile ./alacritty.yml)
    );

  shellEntrypoint = pkgs.writeShellScript "alacritty-shell-entrypoint" ''
    exec ${alacrittyUnwrap} "${zsh}/bin/zsh" "$@"
  '';

  alacritty = pkgs.writeShellScriptBin "alacritty" ''
    # TODO this might break things, especially if the machine is not using
    # nvidia, but more investigation is needed. But it at least lets us get rid
    # of nixGL.
    export LD_LIBRARY_PATH=/usr/lib
    export __EGL_VENDOR_LIBRARY_DIRS=/usr/share/glvnd/egl_vendor.d

    exec ${pkgs.alacritty}/bin/alacritty \
      -o font.size=${builtins.toString config.alacritty.fontSize} \
      --config-file ${configFile} \
      -e "${shellEntrypoint}"
  '';
}