at 25.11-pre 5.7 kB view raw
1{ 2 config, 3 lib, 4 pkgs, 5 ... 6}: 7 8with lib; 9 10let 11 cfg = config.services.getty; 12 13 baseArgs = 14 [ 15 "--login-program" 16 "${cfg.loginProgram}" 17 ] 18 ++ optionals (cfg.autologinUser != null && !cfg.autologinOnce) [ 19 "--autologin" 20 cfg.autologinUser 21 ] 22 ++ optionals (cfg.loginOptions != null) [ 23 "--login-options" 24 cfg.loginOptions 25 ] 26 ++ cfg.extraArgs; 27 28 gettyCmd = args: "${lib.getExe' pkgs.util-linux "agetty"} ${escapeShellArgs baseArgs} ${args}"; 29 30 autologinScript = '' 31 otherArgs="--noclear --keep-baud $TTY 115200,38400,9600 $TERM"; 32 ${lib.optionalString cfg.autologinOnce '' 33 autologged="/run/agetty.autologged" 34 if test "$TTY" = tty1 && ! test -f "$autologged"; then 35 touch "$autologged" 36 exec ${gettyCmd "$otherArgs --autologin ${cfg.autologinUser}"} 37 fi 38 ''} 39 exec ${gettyCmd "$otherArgs"} 40 ''; 41 42in 43 44{ 45 46 ###### interface 47 48 imports = [ 49 (mkRenamedOptionModule [ "services" "mingetty" ] [ "services" "getty" ]) 50 (mkRemovedOptionModule [ "services" "getty" "serialSpeed" ] 51 ''set non-standard baudrates with `boot.kernelParams` i.e. boot.kernelParams = ["console=ttyS2,1500000"];'' 52 ) 53 ]; 54 55 options = { 56 57 services.getty = { 58 59 autologinUser = mkOption { 60 type = types.nullOr types.str; 61 default = null; 62 description = '' 63 Username of the account that will be automatically logged in at the console. 64 If unspecified, a login prompt is shown as usual. 65 ''; 66 }; 67 68 autologinOnce = mkOption { 69 type = types.bool; 70 default = false; 71 description = '' 72 If enabled the automatic login will only happen in the first tty 73 once per boot. This can be useful to avoid retyping the account 74 password on systems with full disk encrypted. 75 ''; 76 }; 77 78 loginProgram = mkOption { 79 type = types.path; 80 default = "${pkgs.shadow}/bin/login"; 81 defaultText = literalExpression ''"''${pkgs.shadow}/bin/login"''; 82 description = '' 83 Path to the login binary executed by agetty. 84 ''; 85 }; 86 87 loginOptions = mkOption { 88 type = types.nullOr types.str; 89 default = null; 90 description = '' 91 Template for arguments to be passed to 92 {manpage}`login(1)`. 93 94 See {manpage}`agetty(1)` for details, 95 including security considerations. If unspecified, agetty 96 will not be invoked with a {option}`--login-options` 97 option. 98 ''; 99 example = "-h darkstar -- \\u"; 100 }; 101 102 extraArgs = mkOption { 103 type = types.listOf types.str; 104 default = [ ]; 105 description = '' 106 Additional arguments passed to agetty. 107 ''; 108 example = [ "--nohostname" ]; 109 }; 110 111 greetingLine = mkOption { 112 type = types.str; 113 description = '' 114 Welcome line printed by agetty. 115 The default shows current NixOS version label, machine type and tty. 116 ''; 117 }; 118 119 helpLine = mkOption { 120 type = types.lines; 121 default = ""; 122 description = '' 123 Help line printed by agetty below the welcome line. 124 Used by the installation CD to give some hints on 125 how to proceed. 126 ''; 127 }; 128 129 }; 130 131 }; 132 133 ###### implementation 134 135 config = mkIf config.console.enable { 136 # Note: this is set here rather than up there so that changing 137 # nixos.label would not rebuild manual pages 138 services.getty.greetingLine = mkDefault ''<<< Welcome to ${config.system.nixos.distroName} ${config.system.nixos.label} (\m) - \l >>>''; 139 services.getty.helpLine = mkIf ( 140 config.documentation.nixos.enable && config.documentation.doc.enable 141 ) "\nRun 'nixos-help' for the NixOS manual."; 142 143 systemd.additionalUpstreamSystemUnits = [ 144 "getty.target" 145 "getty-pre.target" 146 "getty@.service" 147 "serial-getty@.service" 148 "console-getty.service" 149 "container-getty@.service" 150 ]; 151 152 systemd.services."getty@" = { 153 serviceConfig.ExecStart = [ 154 # override upstream default with an empty ExecStart 155 "" 156 (pkgs.writers.writeDash "getty" autologinScript) 157 ]; 158 environment.TTY = "%I"; 159 restartIfChanged = false; 160 }; 161 162 systemd.services."serial-getty@" = { 163 serviceConfig.ExecStart = [ 164 "" # override upstream default with an empty ExecStart 165 (gettyCmd "%I --keep-baud $TERM") 166 ]; 167 restartIfChanged = false; 168 }; 169 170 systemd.services."autovt@" = { 171 serviceConfig.ExecStart = [ 172 "" # override upstream default with an empty ExecStart 173 (gettyCmd "--noclear %I $TERM") 174 ]; 175 restartIfChanged = false; 176 }; 177 178 systemd.services."container-getty@" = { 179 serviceConfig.ExecStart = [ 180 "" # override upstream default with an empty ExecStart 181 (gettyCmd "--noclear --keep-baud pts/%I 115200,38400,9600 $TERM") 182 ]; 183 restartIfChanged = false; 184 }; 185 186 systemd.services.console-getty = { 187 serviceConfig.ExecStart = [ 188 "" # override upstream default with an empty ExecStart 189 (gettyCmd "--noclear --keep-baud console 115200,38400,9600 $TERM") 190 ]; 191 serviceConfig.Restart = "always"; 192 restartIfChanged = false; 193 enable = mkDefault config.boot.isContainer; 194 }; 195 196 environment.etc.issue = mkDefault { 197 # Friendly greeting on the virtual consoles. 198 source = pkgs.writeText "issue" '' 199 200 ${config.services.getty.greetingLine} 201 ${config.services.getty.helpLine} 202 203 ''; 204 }; 205 206 }; 207 208 meta.maintainers = with maintainers; [ RossComputerGuy ]; 209}