at 16.09-beta 3.2 kB view raw
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 # nixosLabel would not rebuild manual pages 68 services.mingetty.greetingLine = mkDefault ''<<< Welcome to NixOS ${config.system.nixosLabel} (\m) - \l >>>''; 69 70 systemd.services."getty@" = 71 { serviceConfig.ExecStart = gettyCmd "--noclear --keep-baud %I 115200,38400,9600 $TERM"; 72 restartIfChanged = false; 73 }; 74 75 systemd.services."serial-getty@" = 76 { serviceConfig.ExecStart = 77 let speeds = concatStringsSep "," (map toString config.services.mingetty.serialSpeed); 78 in gettyCmd "%I ${speeds} $TERM"; 79 restartIfChanged = false; 80 }; 81 82 systemd.services."container-getty@" = 83 { unitConfig.ConditionPathExists = "/dev/pts/%I"; # Work around being respawned when "machinectl login" exits. 84 serviceConfig.ExecStart = gettyCmd "--noclear --keep-baud pts/%I 115200,38400,9600 $TERM"; 85 restartIfChanged = false; 86 }; 87 88 systemd.services."console-getty" = 89 { serviceConfig.ExecStart = gettyCmd "--noclear --keep-baud console 115200,38400,9600 $TERM"; 90 serviceConfig.Restart = "always"; 91 restartIfChanged = false; 92 enable = mkDefault config.boot.isContainer; 93 }; 94 95 environment.etc = singleton 96 { # Friendly greeting on the virtual consoles. 97 source = pkgs.writeText "issue" '' 98 99 ${config.services.mingetty.greetingLine} 100 ${config.services.mingetty.helpLine} 101 102 ''; 103 target = "issue"; 104 }; 105 106 }; 107 108}