mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-06-14 21:49:34 +03:00
nixos/getty: add option to autologin once per boot
This commit is contained in:
parent
0b393b38ee
commit
ae48df3ebb
1 changed files with 28 additions and 4 deletions
|
@ -7,14 +7,26 @@ let
|
||||||
|
|
||||||
baseArgs = [
|
baseArgs = [
|
||||||
"--login-program" "${cfg.loginProgram}"
|
"--login-program" "${cfg.loginProgram}"
|
||||||
] ++ optionals (cfg.autologinUser != null) [
|
] ++ optionals (cfg.autologinUser != null && !cfg.autologinOnce) [
|
||||||
"--autologin" cfg.autologinUser
|
"--autologin" cfg.autologinUser
|
||||||
] ++ optionals (cfg.loginOptions != null) [
|
] ++ optionals (cfg.loginOptions != null) [
|
||||||
"--login-options" cfg.loginOptions
|
"--login-options" cfg.loginOptions
|
||||||
] ++ cfg.extraArgs;
|
] ++ cfg.extraArgs;
|
||||||
|
|
||||||
gettyCmd = args:
|
gettyCmd = args:
|
||||||
"@${pkgs.util-linux}/sbin/agetty agetty ${escapeShellArgs baseArgs} ${args}";
|
"${pkgs.util-linux}/sbin/agetty ${escapeShellArgs baseArgs} ${args}";
|
||||||
|
|
||||||
|
autologinScript = ''
|
||||||
|
otherArgs="--noclear --keep-baud $TTY 115200,38400,9600 $TERM";
|
||||||
|
${lib.optionalString cfg.autologinOnce ''
|
||||||
|
autologged="/run/agetty.autologged"
|
||||||
|
if test "$TTY" = tty1 && ! test -f "$autologged"; then
|
||||||
|
touch "$autologged"
|
||||||
|
exec ${gettyCmd "$otherArgs --autologin ${cfg.autologinUser}"}
|
||||||
|
fi
|
||||||
|
''}
|
||||||
|
exec ${gettyCmd "$otherArgs"}
|
||||||
|
'';
|
||||||
|
|
||||||
in
|
in
|
||||||
|
|
||||||
|
@ -40,6 +52,16 @@ in
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
autologinOnce = mkOption {
|
||||||
|
type = types.bool;
|
||||||
|
default = false;
|
||||||
|
description = ''
|
||||||
|
If enabled the automatic login will only happen in the first tty
|
||||||
|
once per boot. This can be useful to avoid retyping the account
|
||||||
|
password on systems with full disk encrypted.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
loginProgram = mkOption {
|
loginProgram = mkOption {
|
||||||
type = types.path;
|
type = types.path;
|
||||||
default = "${pkgs.shadow}/bin/login";
|
default = "${pkgs.shadow}/bin/login";
|
||||||
|
@ -106,9 +128,11 @@ in
|
||||||
|
|
||||||
systemd.services."getty@" =
|
systemd.services."getty@" =
|
||||||
{ serviceConfig.ExecStart = [
|
{ serviceConfig.ExecStart = [
|
||||||
"" # override upstream default with an empty ExecStart
|
# override upstream default with an empty ExecStart
|
||||||
(gettyCmd "--noclear --keep-baud %I 115200,38400,9600 $TERM")
|
""
|
||||||
|
(pkgs.writers.writeDash "getty" autologinScript)
|
||||||
];
|
];
|
||||||
|
environment.TTY = "%I";
|
||||||
restartIfChanged = false;
|
restartIfChanged = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue