Running user service in nixos container

Hi,

I’m trying to set up user services in a nixos container. I created a new normal user in the container and use systemd.user.services to configure the service.

However, I found that no output is shown for the service when I run systemctl --machine=<user>@.host --user status <service> and thus there’s no way to debug my service.
Besides, the user XDG runtime dir (e.g. /run/user/1000) is not created which causes some problems for the user service.

Does anyone know how to properly set up a user service in a nixos container?

I found that users.users.<user>.linger option doesn’t have any effect in a nixos container.

The solution I found is using a normal service with PAMName=login which helps set up the user runtime dir and environment variables.