NixOS container login failed

Hi,

When I set up a systemd-nspawn container via NixOS containers option, I found that the login command always fails with the following error:

> sudo machinectl login <container>
Failed to get login PTY: Unit container-getty@1.service not found

Using shell command is okay but that’s different from a login shell.

Does anyone have any clues on how to fix this error?

I have the exact same problem.
nixos-container root-login is OK but nixos-container login is not:

$ sudo nixos-container login <container>
Failed to get login PTY: Unit container-getty@1.service not found.

I am using 25.05

stdout of command without sudo

$ nixos-container login my-container
==== AUTHENTICATING FOR org.freedesktop.machine1.login ====
Authentication is required to log into a local container.
Authenticating as: user
Password:
==== AUTHENTICATION COMPLETE ====
Failed to get login PTY: Unit container-getty@1.service not found.

journalctl of nixos-container login my-container

Sep 20 23:03:53 myhostname polkitd[12345]: Registered Authentication Agent for unix-process:12222:323232 (system bus name :1.65 [/run/current-system/sw/bin/pkttyagent --notify-fd 6 --fallback], object path /org/freedesktop/PolicyKit1/AuthenticationAgent, locale en_US.UTF-8)

journalctl after entered password and hit enter

Sep 20 23:03:57 myhostname polkitd[12345]: Operator of unix-process:12222:323232 successfully authenticated as unix-user:user to gain ONE-SHOT authorization for action org.freedesktop.machine1.login for system-bus-name::1.66 [machinectl login – my-container] (owned by unix-user:user)

Sep 20 23:03:57 myhostname polkitd[12345]: Unregistered Authentication Agent for unix-process:12222:323232 (system bus name :1.65, object path /org/freedesktop/PolicyKit1/AuthenticationAgent, locale en_US.UTF-8) (disconnected from bus)

nixos-container login my-container was working fine for me for a little bit then I started getting the exact same errors as you. I haven’t figured out a fix but I did find that sudo nixos-container root-login my-container does work.