Autologin for single TTY

I am attempting to autologin on tty1 only

I tried adding the following to my configuration:

systemd.services."getty@tty1" = {
  serviceConfig.ExecStart = ["" "@${pkgs.util-linux}/sbin/agetty agetty --login-program ${config.services.getty.loginProgram} --autologin YOURUSER --noclear --keep-baud %I 115200,38400,9600 $TERM"];
};

However autologin did not work. Running systemctl cat getty@tty1.service returned the following:

# /etc/systemd/system/getty@.service
#  SPDX-License-Identifier: LGPL-2.1-or-later
#
#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.

[Unit]
Description=Getty on %I
Documentation=man:agetty(8) man:systemd-getty-generator(8)
Documentation=https://0pointer.de/blog/projects/serial-console.html
After=systemd-user-sessions.service plymouth-quit-wait.service getty-pre.target

# If additional gettys are spawned during boot then we should make
# sure that this is synchronized before getty.target, even though
# getty.target didn't actually pull it in.
Before=getty.target
IgnoreOnIsolate=yes

# IgnoreOnIsolate causes issues with sulogin, if someone isolates
# rescue.target or starts rescue.service from multi-user.target or
# graphical.target.
Conflicts=rescue.service
Before=rescue.service

# On systems without virtual consoles, don't start any getty. Note
# that serial gettys are covered by serial-getty@.service, not this
# unit.
ConditionPathExists=/dev/tty0

[Service]
# the VT is cleared by TTYVTDisallocate
# The '-o' option value tells agetty to replace 'login' arguments with an
# option to preserve environment (-p), followed by '--' for safety, and then
# the entered username.
ExecStart=-/sbin/agetty -o '-p -- \\u' --noclear - $TERM
Type=idle
Restart=always
RestartSec=0
UtmpIdentifier=%I
StandardInput=tty
StandardOutput=tty
TTYPath=/dev/%I
TTYReset=yes
TTYVHangup=yes
TTYVTDisallocate=yes
IgnoreSIGPIPE=no
SendSIGHUP=yes
ImportCredential=agetty.*
ImportCredential=login.*

# Unset locale for the console getty since the console has problems
# displaying some internationalized messages.
UnsetEnvironment=LANG LANGUAGE LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT LC_IDENTIFICATION

[Install]
WantedBy=getty.target
DefaultInstance=tty1

# /nix/store/lrgljwlw10k4hjlp3b7cgpmpz4wqyyyc-system-units/autovt@.service.d/overrides.conf
[Unit]

[Service]
Environment="LOCALE_ARCHIVE=/nix/store/v8c1f07sl7bks8v3dpni76q0v36ap2j6-glibc-locales-2.39-52/lib/locale/locale-archive"
Environment="PATH=/nix/store/dhv5gh89him9a7ddr56cqg87zfkmjihp-coreutils-9.5/bin:/nix/store/j71whmq49hfcvhpn4wqzrqcnbq5mafic-findutils-4.10.0/bin:/nix/store/mdiqq9b2rvv7fajlmg3f7d6r6g78l547-gnugrep-3.11/bin:/nix/store/cdhx572ij0pvn9ayd33lk8118137j6m8-gnused-4.9/bin:/nix/store/sbqf71kqhlgaff1ajd8zak09g4wn8ymd-systemd-255.6/bin:/nix/store/dhv5gh89him9a7ddr56cqg87zfkmjihp-coreutils-9.5/sbin:/nix/store/j71whmq49hfcvhpn4wqzrqcnbq5mafic-findutils-4.10.0/sbin:/nix/store/mdiqq9b2rvv7fajlmg3f7d6r6g78l547-gnugrep-3.11/sbin:/nix/store/cdhx572ij0pvn9ayd33lk8118137j6m8-gnused-4.9/sbin:/nix/store/sbqf71kqhlgaff1ajd8zak09g4wn8ymd-systemd-255.6/sbin"
Environment="TZDIR=/nix/store/k6vxnriwl3ywpmlmvif3zr418j7dwm1n-tzdata-2024a/share/zoneinfo"
X-RestartIfChanged=false
ExecStart=
ExecStart=@/nix/store/kwa0akdagjw0hmv3mam65gmz8f1v8c8k-util-linux-2.39.4-bin/sbin/agetty agetty '--login-program' '/nix/store/9647id4agrj4248sk685sc87yjy8br8g-shadow-4.14.6/bin/login' --noclear %I $TERM

try this:

systemd.services."getty@tty1" = {
  overrideStrategy = "asDropin";
  serviceConfig.ExecStart = ["" "@${pkgs.util-linux}/sbin/agetty agetty --login-program ${config.services.getty.loginProgram} --autologin YOURUSER --noclear --keep-baud %I 115200,38400,9600 $TERM"];
};
2 Likes