diff options
Diffstat (limited to 'nixpkgs/nixos/modules/services/ttys')
-rw-r--r-- | nixpkgs/nixos/modules/services/ttys/agetty.nix | 139 | ||||
-rw-r--r-- | nixpkgs/nixos/modules/services/ttys/gpm.nix | 57 | ||||
-rw-r--r-- | nixpkgs/nixos/modules/services/ttys/kmscon.nix | 100 |
3 files changed, 296 insertions, 0 deletions
diff --git a/nixpkgs/nixos/modules/services/ttys/agetty.nix b/nixpkgs/nixos/modules/services/ttys/agetty.nix new file mode 100644 index 000000000000..996925134524 --- /dev/null +++ b/nixpkgs/nixos/modules/services/ttys/agetty.nix @@ -0,0 +1,139 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + cfg = config.services.mingetty; + + loginArgs = concatStringsSep " " [ + "--login-program ${pkgs.shadow}/bin/login" + + (optionalString (cfg.autologinUser != null) + "--autologin ${cfg.autologinUser}") + + (optionalString (cfg.loginOptions != null) + "--login-options ${escapeShellArg cfg.loginOptions}") + ]; + + gettyCmd = extraArgs: + "@${pkgs.utillinux}/sbin/agetty agetty ${loginArgs} ${extraArgs}"; + +in + +{ + + ###### interface + + options = { + + services.mingetty = { + + autologinUser = mkOption { + type = types.nullOr types.str; + default = null; + description = '' + Username of the account that will be automatically logged in at the console. + If unspecified, a login prompt is shown as usual. + ''; + }; + + loginOptions = mkOption { + type = types.nullOr types.str; + default = null; + description = '' + Template for arguments to be passed to login(1). + See agetty(1) for details, including security considerations. + If unspecified, agetty will not be invoked with a --login-options option. + ''; + example = "-h darkstar -- \u"; + }; + + greetingLine = mkOption { + type = types.str; + description = '' + Welcome line printed by mingetty. + The default shows current NixOS version label, machine type and tty. + ''; + }; + + helpLine = mkOption { + type = types.lines; + default = ""; + description = '' + Help line printed by mingetty below the welcome line. + Used by the installation CD to give some hints on + how to proceed. + ''; + }; + + serialSpeed = mkOption { + type = types.listOf types.int; + default = [ 115200 57600 38400 9600 ]; + example = [ 38400 9600 ]; + description = '' + Bitrates to allow for agetty's listening on serial ports. Listing more + bitrates gives more interoperability but at the cost of long delays + for getting a sync on the line. + ''; + }; + + }; + + }; + + + ###### implementation + + config = { + # Note: this is set here rather than up there so that changing + # nixos.label would not rebuild manual pages + services.mingetty.greetingLine = mkDefault ''<<< Welcome to NixOS ${config.system.nixos.label} (\m) - \l >>>''; + + systemd.services."getty@" = + { serviceConfig.ExecStart = [ + "" # override upstream default with an empty ExecStart + (gettyCmd "--noclear --keep-baud %I 115200,38400,9600 $TERM") + ]; + restartIfChanged = false; + }; + + systemd.services."serial-getty@" = + let speeds = concatStringsSep "," (map toString config.services.mingetty.serialSpeed); in + { serviceConfig.ExecStart = [ + "" # override upstream default with an empty ExecStart + (gettyCmd "%I ${speeds} $TERM") + ]; + restartIfChanged = false; + }; + + systemd.services."container-getty@" = + { serviceConfig.ExecStart = [ + "" # override upstream default with an empty ExecStart + (gettyCmd "--noclear --keep-baud pts/%I 115200,38400,9600 $TERM") + ]; + restartIfChanged = false; + }; + + systemd.services.console-getty = + { serviceConfig.ExecStart = [ + "" # override upstream default with an empty ExecStart + (gettyCmd "--noclear --keep-baud console 115200,38400,9600 $TERM") + ]; + serviceConfig.Restart = "always"; + restartIfChanged = false; + enable = mkDefault config.boot.isContainer; + }; + + environment.etc.issue = + { # Friendly greeting on the virtual consoles. + source = pkgs.writeText "issue" '' + + [1;32m${config.services.mingetty.greetingLine}[0m + ${config.services.mingetty.helpLine} + + ''; + }; + + }; + +} diff --git a/nixpkgs/nixos/modules/services/ttys/gpm.nix b/nixpkgs/nixos/modules/services/ttys/gpm.nix new file mode 100644 index 000000000000..308a6d3643a6 --- /dev/null +++ b/nixpkgs/nixos/modules/services/ttys/gpm.nix @@ -0,0 +1,57 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + + cfg = config.services.gpm; + +in + +{ + + ###### interface + + options = { + + services.gpm = { + + enable = mkOption { + type = types.bool; + default = false; + description = '' + Whether to enable GPM, the General Purpose Mouse daemon, + which enables mouse support in virtual consoles. + ''; + }; + + protocol = mkOption { + type = types.str; + default = "ps/2"; + description = "Mouse protocol to use."; + }; + + }; + + }; + + + ###### implementation + + config = mkIf cfg.enable { + + systemd.services.gpm = + { description = "Console Mouse Daemon"; + + wantedBy = [ "multi-user.target" ]; + requires = [ "dev-input-mice.device" ]; + after = [ "dev-input-mice.device" ]; + + serviceConfig.ExecStart = "@${pkgs.gpm}/sbin/gpm gpm -m /dev/input/mice -t ${cfg.protocol}"; + serviceConfig.Type = "forking"; + serviceConfig.PIDFile = "/run/gpm.pid"; + }; + + }; + +} diff --git a/nixpkgs/nixos/modules/services/ttys/kmscon.nix b/nixpkgs/nixos/modules/services/ttys/kmscon.nix new file mode 100644 index 000000000000..dc37f9bee4b3 --- /dev/null +++ b/nixpkgs/nixos/modules/services/ttys/kmscon.nix @@ -0,0 +1,100 @@ +{ config, pkgs, lib, ... }: +let + inherit (lib) mkOption types mkIf; + + 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 = '' + 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 = "Whether to use 3D hardware acceleration to render the console."; + type = types.bool; + default = false; + }; + + extraConfig = mkOption { + description = "Extra contents of the kmscon.conf file."; + type = types.lines; + default = ""; + example = "font-size=14"; + }; + + extraOptions = mkOption { + description = "Extra flags to pass to kmscon."; + type = types.separatedString " "; + default = ""; + example = "--term xterm-256color"; + }; + + autologinUser = mkOption { + type = types.nullOr types.str; + default = null; + description = '' + 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.units."autovt@.service".unit = pkgs.runCommand "unit" { preferLocalBuild = true; } + '' + mkdir -p $out + ln -s ${config.systemd.units."kmsconvt@.service".unit}/kmsconvt@.service $out/autovt@.service + ''; + + systemd.services.systemd-vconsole-setup.enable = false; + + services.kmscon.extraConfig = mkIf cfg.hwRender '' + drm + hwaccel + ''; + + hardware.opengl.enable = mkIf cfg.hwRender true; + }; +} |