1 { config, lib, pkgs, ... }:
6 cfg = config.services.getty;
9 "--login-program" "${cfg.loginProgram}"
10 ] ++ optionals (cfg.autologinUser != null && !cfg.autologinOnce) [
11 "--autologin" cfg.autologinUser
12 ] ++ optionals (cfg.loginOptions != null) [
13 "--login-options" cfg.loginOptions
17 "${lib.getExe' pkgs.util-linux "agetty"} ${escapeShellArgs baseArgs} ${args}";
20 otherArgs="--noclear --keep-baud $TTY 115200,38400,9600 $TERM";
21 ${lib.optionalString cfg.autologinOnce ''
22 autologged="/run/agetty.autologged"
23 if test "$TTY" = tty1 && ! test -f "$autologged"; then
25 exec ${gettyCmd "$otherArgs --autologin ${cfg.autologinUser}"}
28 exec ${gettyCmd "$otherArgs"}
38 (mkRenamedOptionModule [ "services" "mingetty" ] [ "services" "getty" ])
39 (mkRemovedOptionModule [ "services" "getty" "serialSpeed" ] ''set non-standard baudrates with `boot.kernelParams` i.e. boot.kernelParams = ["console=ttyS2,1500000"];'')
46 autologinUser = mkOption {
47 type = types.nullOr types.str;
50 Username of the account that will be automatically logged in at the console.
51 If unspecified, a login prompt is shown as usual.
55 autologinOnce = mkOption {
59 If enabled the automatic login will only happen in the first tty
60 once per boot. This can be useful to avoid retyping the account
61 password on systems with full disk encrypted.
65 loginProgram = mkOption {
67 default = "${pkgs.shadow}/bin/login";
68 defaultText = literalExpression ''"''${pkgs.shadow}/bin/login"'';
70 Path to the login binary executed by agetty.
74 loginOptions = mkOption {
75 type = types.nullOr types.str;
78 Template for arguments to be passed to
81 See {manpage}`agetty(1)` for details,
82 including security considerations. If unspecified, agetty
83 will not be invoked with a {option}`--login-options`
86 example = "-h darkstar -- \\u";
89 extraArgs = mkOption {
90 type = types.listOf types.str;
93 Additional arguments passed to agetty.
95 example = [ "--nohostname" ];
98 greetingLine = mkOption {
101 Welcome line printed by agetty.
102 The default shows current NixOS version label, machine type and tty.
106 helpLine = mkOption {
110 Help line printed by agetty below the welcome line.
111 Used by the installation CD to give some hints on
121 ###### implementation
124 # Note: this is set here rather than up there so that changing
125 # nixos.label would not rebuild manual pages
126 services.getty.greetingLine = mkDefault ''<<< Welcome to ${config.system.nixos.distroName} ${config.system.nixos.label} (\m) - \l >>>'';
127 services.getty.helpLine = mkIf (config.documentation.nixos.enable && config.documentation.doc.enable) "\nRun 'nixos-help' for the NixOS manual.";
129 systemd.services."getty@" =
130 { serviceConfig.ExecStart = [
131 # override upstream default with an empty ExecStart
133 (pkgs.writers.writeDash "getty" autologinScript)
135 environment.TTY = "%I";
136 restartIfChanged = false;
139 systemd.services."serial-getty@" =
140 { serviceConfig.ExecStart = [
141 "" # override upstream default with an empty ExecStart
142 (gettyCmd "%I --keep-baud $TERM")
144 restartIfChanged = false;
147 systemd.services."autovt@" =
148 { serviceConfig.ExecStart = [
149 "" # override upstream default with an empty ExecStart
150 (gettyCmd "--noclear %I $TERM")
152 restartIfChanged = false;
155 systemd.services."container-getty@" =
156 { serviceConfig.ExecStart = [
157 "" # override upstream default with an empty ExecStart
158 (gettyCmd "--noclear --keep-baud pts/%I 115200,38400,9600 $TERM")
160 restartIfChanged = false;
163 systemd.services.console-getty =
164 { serviceConfig.ExecStart = [
165 "" # override upstream default with an empty ExecStart
166 (gettyCmd "--noclear --keep-baud console 115200,38400,9600 $TERM")
168 serviceConfig.Restart = "always";
169 restartIfChanged = false;
170 enable = mkDefault config.boot.isContainer;
173 environment.etc.issue = mkDefault
174 { # Friendly greeting on the virtual consoles.
175 source = pkgs.writeText "issue" ''
177 \e[1;32m${config.services.getty.greetingLine}
\e[0m
178 ${config.services.getty.helpLine}
185 meta.maintainers = with maintainers; [ RossComputerGuy ];