1{ config, pkgs, lib, ... }:
2let
3 inherit (lib) mkOption types mkIf;
4
5 cfg = config.services.kmscon;
6
7 configDir = pkgs.writeTextFile { name = "kmscon-config"; destination = "/kmscon.conf"; text = cfg.extraConfig; };
8in {
9 options = {
10 services.kmscon = {
11 enable = mkOption {
12 description = ''
13 Use kmscon as the virtual console instead of gettys.
14 kmscon is a kms/dri-based userspace virtual terminal implementation.
15 It supports a richer feature set than the standard linux console VT,
16 including full unicode support, and when the video card supports drm
17 should be much faster.
18 '';
19 type = types.bool;
20 default = false;
21 };
22
23 hwRender = mkOption {
24 description = "Whether to use 3D hardware acceleration to render the console.";
25 type = types.bool;
26 default = false;
27 };
28
29 extraConfig = mkOption {
30 description = "Extra contents of the kmscon.conf file.";
31 type = types.lines;
32 default = "";
33 example = "font-size=14";
34 };
35
36 extraOptions = mkOption {
37 description = "Extra flags to pass to kmscon.";
38 type = types.separatedString " ";
39 default = "";
40 example = "--term xterm-256color";
41 };
42 };
43 };
44
45 config = mkIf cfg.enable {
46 # Largely copied from unit provided with kmscon source
47 systemd.units."kmsconvt@.service".text = ''
48 [Unit]
49 Description=KMS System Console on %I
50 Documentation=man:kmscon(1)
51 After=systemd-user-sessions.service
52 After=plymouth-quit-wait.service
53 After=systemd-logind.service
54 After=systemd-vconsole-setup.service
55 Requires=systemd-logind.service
56 Before=getty.target
57 Conflicts=getty@%i.service
58 OnFailure=getty@%i.service
59 IgnoreOnIsolate=yes
60 ConditionPathExists=/dev/tty0
61
62 [Service]
63 ExecStart=
64 ExecStart=${pkgs.kmscon}/bin/kmscon "--vt=%I" ${cfg.extraOptions} --seats=seat0 --no-switchvt --configdir ${configDir} --login -- ${pkgs.shadow}/bin/login -p
65 UtmpIdentifier=%I
66 TTYPath=/dev/%I
67 TTYReset=yes
68 TTYVHangup=yes
69 TTYVTDisallocate=yes
70
71 X-RestartIfChanged=false
72 '';
73
74 systemd.units."autovt@.service".unit = pkgs.runCommand "unit" { }
75 ''
76 mkdir -p $out
77 ln -s ${config.systemd.units."kmsconvt@.service".unit}/kmsconvt@.service $out/autovt@.service
78 '';
79
80 systemd.services.systemd-vconsole-setup.enable = false;
81
82 services.kmscon.extraConfig = mkIf cfg.hwRender ''
83 drm
84 hwaccel
85 '';
86
87 hardware.opengl.enable = mkIf cfg.hwRender true;
88 };
89}