1 { config, pkgs, lib, ... }:
3 inherit (lib) mapAttrs mkIf mkOption optional optionals types;
5 cfg = config.services.kmscon;
7 autologinArg = lib.optionalString (cfg.autologinUser != null) "-f ${cfg.autologinUser}";
9 configDir = pkgs.writeTextFile { name = "kmscon-config"; destination = "/kmscon.conf"; text = cfg.extraConfig; };
15 Use kmscon as the virtual console instead of gettys.
16 kmscon is a kms/dri-based userspace virtual terminal implementation.
17 It supports a richer feature set than the standard linux console VT,
18 including full unicode support, and when the video card supports drm
19 should be much faster.
26 description = "Whether to use 3D hardware acceleration to render the console.";
32 description = "Fonts used by kmscon, in order of priority.";
34 example = lib.literalExpression ''[ { name = "Source Code Pro"; package = pkgs.source-code-pro; } ]'';
36 let fontType = submodule {
38 name = mkOption { type = str; description = "Font name, as used by fontconfig."; };
39 package = mkOption { type = package; description = "Package providing the font."; };
41 }; in nullOr (nonEmptyListOf fontType);
44 useXkbConfig = mkOption {
45 description = "Configure keymap from xserver keyboard settings.";
50 extraConfig = mkOption {
51 description = "Extra contents of the kmscon.conf file.";
54 example = "font-size=14";
57 extraOptions = mkOption {
58 description = "Extra flags to pass to kmscon.";
59 type = types.separatedString " ";
61 example = "--term xterm-256color";
64 autologinUser = mkOption {
65 type = types.nullOr types.str;
68 Username of the account that will be automatically logged in at the console.
69 If unspecified, a login prompt is shown as usual.
75 config = mkIf cfg.enable {
76 systemd.packages = [ pkgs.kmscon ];
78 systemd.services."kmsconvt@" = {
79 after = [ "systemd-logind.service" "systemd-vconsole-setup.service" ];
80 requires = [ "systemd-logind.service" ];
82 serviceConfig.ExecStart = [
85 ${pkgs.kmscon}/bin/kmscon "--vt=%I" ${cfg.extraOptions} --seats=seat0 --no-switchvt --configdir ${configDir} --login -- ${pkgs.shadow}/bin/login -p ${autologinArg}
89 restartIfChanged = false;
90 aliases = [ "autovt@.service" ];
93 systemd.suppressedSystemUnits = [ "autovt@.service" ];
95 systemd.services.systemd-vconsole-setup.enable = false;
96 systemd.services.reload-systemd-vconsole-setup.enable = false;
98 services.kmscon.extraConfig =
100 xkb = optionals cfg.useXkbConfig
101 (lib.mapAttrsToList (n: v: "xkb-${n}=${v}") (
103 (n: v: builtins.elem n ["layout" "model" "options" "variant"] && v != "")
104 config.services.xserver.xkb
106 render = optionals cfg.hwRender [ "drm" "hwaccel" ];
107 fonts = optional (cfg.fonts != null) "font-name=${lib.concatMapStringsSep ", " (f: f.name) cfg.fonts}";
108 in lib.concatLines (xkb ++ render ++ fonts);
110 hardware.graphics.enable = mkIf cfg.hwRender true;
112 fonts = mkIf (cfg.fonts != null) {
113 fontconfig.enable = true;
114 packages = map (f: f.package) cfg.fonts;