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