at 25.11-pre 4.4 kB view raw
1{ 2 config, 3 pkgs, 4 lib, 5 ... 6}: 7let 8 inherit (lib) 9 mapAttrs 10 mkIf 11 mkOption 12 optional 13 optionals 14 types 15 ; 16 17 cfg = config.services.kmscon; 18 19 autologinArg = lib.optionalString (cfg.autologinUser != null) "-f ${cfg.autologinUser}"; 20 21 configDir = pkgs.writeTextFile { 22 name = "kmscon-config"; 23 destination = "/kmscon.conf"; 24 text = cfg.extraConfig; 25 }; 26in 27{ 28 options = { 29 services.kmscon = { 30 enable = mkOption { 31 description = '' 32 Use kmscon as the virtual console instead of gettys. 33 kmscon is a kms/dri-based userspace virtual terminal implementation. 34 It supports a richer feature set than the standard linux console VT, 35 including full unicode support, and when the video card supports drm 36 should be much faster. 37 ''; 38 type = types.bool; 39 default = false; 40 }; 41 42 hwRender = mkOption { 43 description = "Whether to use 3D hardware acceleration to render the console."; 44 type = types.bool; 45 default = false; 46 }; 47 48 fonts = mkOption { 49 description = "Fonts used by kmscon, in order of priority."; 50 default = null; 51 example = lib.literalExpression ''[ { name = "Source Code Pro"; package = pkgs.source-code-pro; } ]''; 52 type = 53 with types; 54 let 55 fontType = submodule { 56 options = { 57 name = mkOption { 58 type = str; 59 description = "Font name, as used by fontconfig."; 60 }; 61 package = mkOption { 62 type = package; 63 description = "Package providing the font."; 64 }; 65 }; 66 }; 67 in 68 nullOr (nonEmptyListOf fontType); 69 }; 70 71 useXkbConfig = mkOption { 72 description = "Configure keymap from xserver keyboard settings."; 73 type = types.bool; 74 default = false; 75 }; 76 77 extraConfig = mkOption { 78 description = "Extra contents of the kmscon.conf file."; 79 type = types.lines; 80 default = ""; 81 example = "font-size=14"; 82 }; 83 84 extraOptions = mkOption { 85 description = "Extra flags to pass to kmscon."; 86 type = types.separatedString " "; 87 default = ""; 88 example = "--term xterm-256color"; 89 }; 90 91 autologinUser = mkOption { 92 type = types.nullOr types.str; 93 default = null; 94 description = '' 95 Username of the account that will be automatically logged in at the console. 96 If unspecified, a login prompt is shown as usual. 97 ''; 98 }; 99 }; 100 }; 101 102 config = mkIf cfg.enable { 103 systemd.packages = [ pkgs.kmscon ]; 104 105 systemd.services."kmsconvt@" = { 106 after = [ 107 "systemd-logind.service" 108 "systemd-vconsole-setup.service" 109 ]; 110 requires = [ "systemd-logind.service" ]; 111 112 serviceConfig.ExecStart = [ 113 "" 114 '' 115 ${pkgs.kmscon}/bin/kmscon "--vt=%I" ${cfg.extraOptions} --seats=seat0 --no-switchvt --configdir ${configDir} --login -- ${pkgs.shadow}/bin/login -p ${autologinArg} 116 '' 117 ]; 118 119 restartIfChanged = false; 120 aliases = [ "autovt@.service" ]; 121 }; 122 123 systemd.suppressedSystemUnits = [ "autovt@.service" ]; 124 125 systemd.services.systemd-vconsole-setup.enable = false; 126 systemd.services.reload-systemd-vconsole-setup.enable = false; 127 128 services.kmscon.extraConfig = 129 let 130 xkb = optionals cfg.useXkbConfig ( 131 lib.mapAttrsToList (n: v: "xkb-${n}=${v}") ( 132 lib.filterAttrs ( 133 n: v: 134 builtins.elem n [ 135 "layout" 136 "model" 137 "options" 138 "variant" 139 ] 140 && v != "" 141 ) config.services.xserver.xkb 142 ) 143 ); 144 render = optionals cfg.hwRender [ 145 "drm" 146 "hwaccel" 147 ]; 148 fonts = 149 optional (cfg.fonts != null) 150 "font-name=${lib.concatMapStringsSep ", " (f: f.name) cfg.fonts}"; 151 in 152 lib.concatLines (xkb ++ render ++ fonts); 153 154 hardware.graphics.enable = mkIf cfg.hwRender true; 155 156 fonts = mkIf (cfg.fonts != null) { 157 fontconfig.enable = true; 158 packages = map (f: f.package) cfg.fonts; 159 }; 160 }; 161}