nixpkgs/nixos/modules/services/ttys/kmscon.nix
pennae 2e751c0772 treewide: automatically md-convert option descriptions
the conversion procedure is simple:

 - find all things that look like options, ie calls to either `mkOption`
   or `lib.mkOption` that take an attrset. remember the attrset as the
   option
 - for all options, find a `description` attribute who's value is not a
   call to `mdDoc` or `lib.mdDoc`
 - textually convert the entire value of the attribute to MD with a few
   simple regexes (the set from mdize-module.sh)
 - if the change produced a change in the manual output, discard
 - if the change kept the manual unchanged, add some text to the
   description to make sure we've actually found an option. if the
   manual changes this time, keep the converted description

this procedure converts 80% of nixos options to markdown. around 2000
options remain to be inspected, but most of those fail the "does not
change the manual output check": currently the MD conversion process
does not faithfully convert docbook tags like <code> and <package>, so
any option using such tags will not be converted at all.
2022-07-30 15:16:34 +02:00

116 lines
3.9 KiB
Nix

{ config, pkgs, lib, ... }:
let
inherit (lib) mapAttrs mkIf mkOption optional optionals types;
cfg = config.services.kmscon;
autologinArg = lib.optionalString (cfg.autologinUser != null) "-f ${cfg.autologinUser}";
configDir = pkgs.writeTextFile { name = "kmscon-config"; destination = "/kmscon.conf"; text = cfg.extraConfig; };
in {
options = {
services.kmscon = {
enable = mkOption {
description = lib.mdDoc ''
Use kmscon as the virtual console instead of gettys.
kmscon is a kms/dri-based userspace virtual terminal implementation.
It supports a richer feature set than the standard linux console VT,
including full unicode support, and when the video card supports drm
should be much faster.
'';
type = types.bool;
default = false;
};
hwRender = mkOption {
description = lib.mdDoc "Whether to use 3D hardware acceleration to render the console.";
type = types.bool;
default = false;
};
fonts = mkOption {
description = lib.mdDoc "Fonts used by kmscon, in order of priority.";
default = null;
example = lib.literalExpression ''[ { name = "Source Code Pro"; package = pkgs.source-code-pro; } ]'';
type = with types;
let fontType = submodule {
options = {
name = mkOption { type = str; description = lib.mdDoc "Font name, as used by fontconfig."; };
package = mkOption { type = package; description = lib.mdDoc "Package providing the font."; };
};
}; in nullOr (nonEmptyListOf fontType);
};
extraConfig = mkOption {
description = lib.mdDoc "Extra contents of the kmscon.conf file.";
type = types.lines;
default = "";
example = "font-size=14";
};
extraOptions = mkOption {
description = lib.mdDoc "Extra flags to pass to kmscon.";
type = types.separatedString " ";
default = "";
example = "--term xterm-256color";
};
autologinUser = mkOption {
type = types.nullOr types.str;
default = null;
description = lib.mdDoc ''
Username of the account that will be automatically logged in at the console.
If unspecified, a login prompt is shown as usual.
'';
};
};
};
config = mkIf cfg.enable {
# Largely copied from unit provided with kmscon source
systemd.units."kmsconvt@.service".text = ''
[Unit]
Description=KMS System Console on %I
Documentation=man:kmscon(1)
After=systemd-user-sessions.service
After=plymouth-quit-wait.service
After=systemd-logind.service
After=systemd-vconsole-setup.service
Requires=systemd-logind.service
Before=getty.target
Conflicts=getty@%i.service
OnFailure=getty@%i.service
IgnoreOnIsolate=yes
ConditionPathExists=/dev/tty0
[Service]
ExecStart=
ExecStart=${pkgs.kmscon}/bin/kmscon "--vt=%I" ${cfg.extraOptions} --seats=seat0 --no-switchvt --configdir ${configDir} --login -- ${pkgs.shadow}/bin/login -p ${autologinArg}
UtmpIdentifier=%I
TTYPath=/dev/%I
TTYReset=yes
TTYVHangup=yes
TTYVTDisallocate=yes
X-RestartIfChanged=false
'';
systemd.suppressedSystemUnits = [ "autovt@.service" ];
systemd.units."kmsconvt@.service".aliases = [ "autovt@.service" ];
systemd.services.systemd-vconsole-setup.enable = false;
services.kmscon.extraConfig =
let
render = optionals cfg.hwRender [ "drm" "hwaccel" ];
fonts = optional (cfg.fonts != null) "font-name=${lib.concatMapStringsSep ", " (f: f.name) cfg.fonts}";
in lib.concatStringsSep "\n" (render ++ fonts);
hardware.opengl.enable = mkIf cfg.hwRender true;
fonts = mkIf (cfg.fonts != null) {
fontconfig.enable = true;
fonts = map (f: f.package) cfg.fonts;
};
};
}