summaryrefslogtreecommitdiffstats
path: root/modules/config/terminfo.nix
blob: 3e2c40ac168ec1928e138debe0a1f35064e7dcc5 (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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# This module manages the terminfo database
# and its integration in the system.
{
  config,
  lib,
  pkgs,
  ...
}:
{

  options = {
    environment.enableAllTerminfo = lib.mkOption {
      default = false;
      type = lib.types.bool;
      description = ''
        Whether to install all terminfo outputs
      '';
    };

    security.sudo.keepTerminfo = lib.mkOption {
      default = true;
      type = lib.types.bool;
      description = ''
        Whether to preserve the `TERMINFO` and `TERMINFO_DIRS`
        environment variables, for `root` and the `admin` group.
      '';
    };
  };

  config = {

    # This should not contain packages that are broken or can't build, since it
    # will break this expression
    #
    # can be generated with:
    # lib.attrNames (lib.filterAttrs
    #  (_: drv: (builtins.tryEval (
    #    lib.isDerivation drv && drv ? terminfo && drv.meta.available && !drv.meta.broken && !drv.meta.unsupported)).value)
    #  pkgs)
    environment.systemPackages = lib.mkIf config.environment.enableAllTerminfo (
      map (x: x.terminfo) (
        with pkgs.pkgsBuildBuild;
        [
          alacritty
          alacritty-graphics
          ghostty-bin
          kitty
          mtm
          rio
          rxvt-unicode-unwrapped
          rxvt-unicode-unwrapped-emoji
          st
          tmux
          wezterm
        ]
      )
    );

    environment.pathsToLink = [
      "/share/terminfo"
    ];

    environment.etc.terminfo = {
      source = "${config.system.path}/share/terminfo";
    };

    # TODO: use `environment.profileRelativeSessionVariables`
    environment.variables = {
      TERMINFO_DIRS = map (path: path + "/share/terminfo") config.environment.profiles ++ [ "/usr/share/terminfo" ];
    };

    environment.extraInit = ''
      # reset TERM with new TERMINFO available (if any)
      export TERM=$TERM
    '';

    security =
      let
        extraConfig = ''

          # Keep terminfo database for root and %admin.
          Defaults:root,%admin env_keep+=TERMINFO_DIRS
          Defaults:root,%admin env_keep+=TERMINFO
        '';
      in
      lib.mkIf config.security.sudo.keepTerminfo {
        sudo = { inherit extraConfig; };
      };
  };
}