1# This module manages the terminfo database
2# and its integration in the system.
3{
4 config,
5 lib,
6 pkgs,
7 ...
8}:
9{
10
11 options = with lib; {
12 environment.enableAllTerminfo = lib.mkOption {
13 default = false;
14 type = lib.types.bool;
15 description = ''
16 Whether to install all terminfo outputs
17 '';
18 };
19
20 security.sudo.keepTerminfo = lib.mkOption {
21 default = true;
22 type = lib.types.bool;
23 description = ''
24 Whether to preserve the `TERMINFO` and `TERMINFO_DIRS`
25 environment variables, for `root` and the `wheel` group.
26 '';
27 };
28 };
29
30 config = {
31
32 # This should not contain packages that are broken or can't build, since it
33 # will break this expression
34 #
35 # can be generated with:
36 # lib.attrNames (lib.filterAttrs
37 # (_: drv: (builtins.tryEval (lib.isDerivation drv && drv ? terminfo)).value)
38 # pkgs)
39 environment.systemPackages = lib.mkIf config.environment.enableAllTerminfo (
40 map (x: x.terminfo) (
41 with pkgs.pkgsBuildBuild;
42 [
43 alacritty
44 contour
45 foot
46 ghostty
47 kitty
48 mtm
49 rio
50 rxvt-unicode-unwrapped
51 rxvt-unicode-unwrapped-emoji
52 st
53 termite
54 tmux
55 wezterm
56 yaft
57 ]
58 )
59 );
60
61 environment.pathsToLink = [
62 "/share/terminfo"
63 ];
64
65 environment.etc.terminfo = {
66 source = "${config.system.path}/share/terminfo";
67 };
68
69 environment.profileRelativeSessionVariables = {
70 TERMINFO_DIRS = [ "/share/terminfo" ];
71 };
72
73 environment.extraInit = ''
74
75 # reset TERM with new TERMINFO available (if any)
76 export TERM=$TERM
77 '';
78
79 security =
80 let
81 extraConfig = ''
82
83 # Keep terminfo database for root and %wheel.
84 Defaults:root,%wheel env_keep+=TERMINFO_DIRS
85 Defaults:root,%wheel env_keep+=TERMINFO
86 '';
87 in
88 lib.mkIf config.security.sudo.keepTerminfo {
89 sudo = { inherit extraConfig; };
90 sudo-rs = { inherit extraConfig; };
91 };
92 };
93}