NixOS rebuild failing while chrooted

Good evening all, having some issues related to NixOS, specifically on my Steam Deck this time. My current configuration is a 256GB NVMe SSD in a USBenclosure, booting over USB. I decided last night to copy the install from the external SSD to the internal SSD with e2image, and it looked like it booted right. I enabled some options in my config related to GitHub - Jovian-Experiments/Jovian-NixOS: Discussions:, and I mistakenly chose switch instead of boot when running nixos-rebuild. I didn’t think much of it, booted into an install image, reverted the changes, but now when I try running nixos-rebuild, I get the following error: sudo: PAM account management error: Authentication service cannot retrieve authentication info sudo: a password is required
What could possibly be causing this? I’m using nixos-enter to try and rebuild the config, but it fails at this message every single time, and I don’t know what could possibly be causing this.

For now, what I am trying to do is rerun nixos-install from the live environment with a fresh config, then copy my config, rebuild (hopefully), and potentially fix this.

Running into this trying to fix nixos asahi right now.

I ran in to the same. To work around opened /etc/pam.d/sudo and pasted in:

auth        sufficient
#auth       required
auth        required
#account        required
account     required
account     required
#session        required
session     required
password    required

which I found in this Arch post. Saved the file and sudo started working again.

I just ran across this myself. The reason this was happening for me was because I had run sudo -i at some point previously followed later by nixos-enter before running nixos-rebuild inside my rescue environment. This ultimately resulted in the error originally reported above which was happening because the environment variable SUDO_USER was inherited from the parent shell before doing nixos-enter and the nixos-rebuild script looks for this environment variable and acts on it, which folks who run across this post, probably don’t really want to happen.

The easy solution is to run unset SUDO_USER before running nixos-rebuild, and it will most likely make the error go away, as it did for me.