1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6
7 autologinArg = optionalString (config.services.mingetty.autologinUser != null) "--autologin ${config.services.mingetty.autologinUser}";
8 gettyCmd = extraArgs: "@${pkgs.utillinux}/sbin/agetty agetty --login-program ${pkgs.shadow}/bin/login ${autologinArg} ${extraArgs}";
9
10in
11
12{
13
14 ###### interface
15
16 options = {
17
18 services.mingetty = {
19
20 autologinUser = mkOption {
21 type = types.nullOr types.str;
22 default = null;
23 description = ''
24 Username of the account that will be automatically logged in at the console.
25 If unspecified, a login prompt is shown as usual.
26 '';
27 };
28
29 greetingLine = mkOption {
30 type = types.str;
31 description = ''
32 Welcome line printed by mingetty.
33 The default shows current NixOS version label, machine type and tty.
34 '';
35 };
36
37 helpLine = mkOption {
38 type = types.lines;
39 default = "";
40 description = ''
41 Help line printed by mingetty below the welcome line.
42 Used by the installation CD to give some hints on
43 how to proceed.
44 '';
45 };
46
47 serialSpeed = mkOption {
48 type = types.listOf types.int;
49 default = [ 115200 57600 38400 9600 ];
50 example = [ 38400 9600 ];
51 description = ''
52 Bitrates to allow for agetty's listening on serial ports. Listing more
53 bitrates gives more interoperability but at the cost of long delays
54 for getting a sync on the line.
55 '';
56 };
57
58 };
59
60 };
61
62
63 ###### implementation
64
65 config = {
66 # Note: this is set here rather than up there so that changing
67 # nixos.label would not rebuild manual pages
68 services.mingetty.greetingLine = mkDefault ''<<< Welcome to NixOS ${config.system.nixos.label} (\m) - \l >>>'';
69
70 systemd.services."getty@" =
71 { serviceConfig.ExecStart = [
72 "" # override upstream default with an empty ExecStart
73 (gettyCmd "--noclear --keep-baud %I 115200,38400,9600 $TERM")
74 ];
75 restartIfChanged = false;
76 };
77
78 systemd.services."serial-getty@" =
79 let speeds = concatStringsSep "," (map toString config.services.mingetty.serialSpeed); in
80 { serviceConfig.ExecStart = [
81 "" # override upstream default with an empty ExecStart
82 (gettyCmd "%I ${speeds} $TERM")
83 ];
84 restartIfChanged = false;
85 };
86
87 systemd.services."container-getty@" =
88 { serviceConfig.ExecStart = [
89 "" # override upstream default with an empty ExecStart
90 (gettyCmd "--noclear --keep-baud pts/%I 115200,38400,9600 $TERM")
91 ];
92 restartIfChanged = false;
93 };
94
95 systemd.services."console-getty" =
96 { serviceConfig.ExecStart = [
97 "" # override upstream default with an empty ExecStart
98 (gettyCmd "--noclear --keep-baud console 115200,38400,9600 $TERM")
99 ];
100 serviceConfig.Restart = "always";
101 restartIfChanged = false;
102 enable = mkDefault config.boot.isContainer;
103 };
104
105 environment.etc = singleton
106 { # Friendly greeting on the virtual consoles.
107 source = pkgs.writeText "issue" ''
108
109 [1;32m${config.services.mingetty.greetingLine}[0m
110 ${config.services.mingetty.helpLine}
111
112 '';
113 target = "issue";
114 };
115
116 };
117
118}