1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6 cfg = config.services.getty;
7
8 baseArgs = [
9 "--login-program" "${cfg.loginProgram}"
10 ] ++ optionals (cfg.autologinUser != null) [
11 "--autologin" cfg.autologinUser
12 ] ++ optionals (cfg.loginOptions != null) [
13 "--login-options" cfg.loginOptions
14 ] ++ cfg.extraArgs;
15
16 gettyCmd = args:
17 "@${pkgs.util-linux}/sbin/agetty agetty ${escapeShellArgs baseArgs} ${args}";
18
19in
20
21{
22
23 ###### interface
24
25 imports = [
26 (mkRenamedOptionModule [ "services" "mingetty" ] [ "services" "getty" ])
27 (mkRemovedOptionModule [ "services" "getty" "serialSpeed" ] ''set non-standard baudrates with `boot.kernelParams` i.e. boot.kernelParams = ["console=ttyS2,1500000"];'')
28 ];
29
30 options = {
31
32 services.getty = {
33
34 autologinUser = mkOption {
35 type = types.nullOr types.str;
36 default = null;
37 description = lib.mdDoc ''
38 Username of the account that will be automatically logged in at the console.
39 If unspecified, a login prompt is shown as usual.
40 '';
41 };
42
43 loginProgram = mkOption {
44 type = types.path;
45 default = "${pkgs.shadow}/bin/login";
46 defaultText = literalExpression ''"''${pkgs.shadow}/bin/login"'';
47 description = lib.mdDoc ''
48 Path to the login binary executed by agetty.
49 '';
50 };
51
52 loginOptions = mkOption {
53 type = types.nullOr types.str;
54 default = null;
55 description = lib.mdDoc ''
56 Template for arguments to be passed to
57 {manpage}`login(1)`.
58
59 See {manpage}`agetty(1)` for details,
60 including security considerations. If unspecified, agetty
61 will not be invoked with a {option}`--login-options`
62 option.
63 '';
64 example = "-h darkstar -- \\u";
65 };
66
67 extraArgs = mkOption {
68 type = types.listOf types.str;
69 default = [ ];
70 description = lib.mdDoc ''
71 Additional arguments passed to agetty.
72 '';
73 example = [ "--nohostname" ];
74 };
75
76 greetingLine = mkOption {
77 type = types.str;
78 description = lib.mdDoc ''
79 Welcome line printed by agetty.
80 The default shows current NixOS version label, machine type and tty.
81 '';
82 };
83
84 helpLine = mkOption {
85 type = types.lines;
86 default = "";
87 description = lib.mdDoc ''
88 Help line printed by agetty below the welcome line.
89 Used by the installation CD to give some hints on
90 how to proceed.
91 '';
92 };
93
94 };
95
96 };
97
98
99 ###### implementation
100
101 config = {
102 # Note: this is set here rather than up there so that changing
103 # nixos.label would not rebuild manual pages
104 services.getty.greetingLine = mkDefault ''<<< Welcome to NixOS ${config.system.nixos.label} (\m) - \l >>>'';
105 services.getty.helpLine = mkIf (config.documentation.nixos.enable && config.documentation.doc.enable) "\nRun 'nixos-help' for the NixOS manual.";
106
107 systemd.services."getty@" =
108 { serviceConfig.ExecStart = [
109 "" # override upstream default with an empty ExecStart
110 (gettyCmd "--noclear --keep-baud %I 115200,38400,9600 $TERM")
111 ];
112 restartIfChanged = false;
113 };
114
115 systemd.services."serial-getty@" =
116 { serviceConfig.ExecStart = [
117 "" # override upstream default with an empty ExecStart
118 (gettyCmd "%I --keep-baud $TERM")
119 ];
120 restartIfChanged = false;
121 };
122
123 systemd.services."autovt@" =
124 { serviceConfig.ExecStart = [
125 "" # override upstream default with an empty ExecStart
126 (gettyCmd "--noclear %I $TERM")
127 ];
128 restartIfChanged = false;
129 };
130
131 systemd.services."container-getty@" =
132 { serviceConfig.ExecStart = [
133 "" # override upstream default with an empty ExecStart
134 (gettyCmd "--noclear --keep-baud pts/%I 115200,38400,9600 $TERM")
135 ];
136 restartIfChanged = false;
137 };
138
139 systemd.services.console-getty =
140 { serviceConfig.ExecStart = [
141 "" # override upstream default with an empty ExecStart
142 (gettyCmd "--noclear --keep-baud console 115200,38400,9600 $TERM")
143 ];
144 serviceConfig.Restart = "always";
145 restartIfChanged = false;
146 enable = mkDefault config.boot.isContainer;
147 };
148
149 environment.etc.issue = mkDefault
150 { # Friendly greeting on the virtual consoles.
151 source = pkgs.writeText "issue" ''
152
153 [1;32m${config.services.getty.greetingLine}[0m
154 ${config.services.getty.helpLine}
155
156 '';
157 };
158
159 };
160
161}