2020-04-24 23:36:52 +00:00
|
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
2021-01-05 17:05:55 +00:00
|
|
|
|
autologinArg = optionalString (config.services.getty.autologinUser != null) "--autologin ${config.services.getty.autologinUser}";
|
2020-11-24 20:58:05 +00:00
|
|
|
|
gettyCmd = extraArgs: "@${pkgs.util-linux}/sbin/agetty agetty --login-program ${pkgs.shadow}/bin/login ${autologinArg} ${extraArgs}";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
|
2021-01-05 17:05:55 +00:00
|
|
|
|
imports = [
|
|
|
|
|
(mkRenamedOptionModule [ "services" "mingetty" ] [ "services" "getty" ])
|
|
|
|
|
];
|
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
|
options = {
|
|
|
|
|
|
2021-01-05 17:05:55 +00:00
|
|
|
|
services.getty = {
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
greetingLine = mkOption {
|
|
|
|
|
type = types.str;
|
|
|
|
|
description = ''
|
2021-01-05 17:05:55 +00:00
|
|
|
|
Welcome line printed by agetty.
|
2020-04-24 23:36:52 +00:00
|
|
|
|
The default shows current NixOS version label, machine type and tty.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
helpLine = mkOption {
|
|
|
|
|
type = types.lines;
|
|
|
|
|
default = "";
|
|
|
|
|
description = ''
|
2021-01-05 17:05:55 +00:00
|
|
|
|
Help line printed by agetty below the welcome line.
|
2020-04-24 23:36:52 +00:00
|
|
|
|
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
|
2021-01-05 17:05:55 +00:00
|
|
|
|
services.getty.greetingLine = mkDefault ''<<< Welcome to NixOS ${config.system.nixos.label} (\m) - \l >>>'';
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
|
|
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@" =
|
2021-01-05 17:05:55 +00:00
|
|
|
|
let speeds = concatStringsSep "," (map toString config.services.getty.serialSpeed); in
|
2020-04-24 23:36:52 +00:00
|
|
|
|
{ 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" ''
|
|
|
|
|
|
2021-01-05 17:05:55 +00:00
|
|
|
|
[1;32m${config.services.getty.greetingLine}[0m
|
|
|
|
|
${config.services.getty.helpLine}
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|