NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.62k stars 13.77k forks source link

`su` does not work in`nixos-enter`: Authentication service cannot retrieve authentication info #308285

Open Andy3153 opened 5 months ago

Andy3153 commented 5 months ago

Describe the bug

su does not work while chrooting into any NixOS installation, even if it has only the bare minimum installed, it's clean, it's brand new etc.

Steps To Reproduce

Steps to reproduce the behavior:

  1. nixos-enter
  2. su

Expected behavior

I can run the su command normally. Any other distro that I've chrooted into I was able to switch to another user.

Screenshots

[nixos@nixos:~]$ sudo nixos-enter
setting up /etc...
bash: warning: setlocale: LC_NUMERIC: cannot change locale (ro_RO.UTF-8): No such file or directory
bash: warning: setlocale: LC_TIME: cannot change locale (ro_RO.UTF-8): No such file or directory

[root@nixos:/]# su
su: command not found

[root@nixos:/]# export PATH=/nix/var/nix/profiles/system/sw/sbin/:/nix/var/nix/profiles/system/sw/bin/:$PATH

[root@nixos:/]# su
su: Authentication service cannot retrieve authentication info
(Ignored)
Cannot execute /run/current-system/sw/bin/bash: No such file or directory

[root@nixos:/]#

Additional context

By the way, ignore I need to manually set $PATH, that’s another issue I found, but at least I worked around it.

Also, I want to do this because I want to run some commands post-installation to clone some Git repos in my $HOME and I also want to enable Home Manager for my user (I use the standalone installation). Basically my use case is use su to switch users to someone that isn't root.

I've posted this on other sites before: 1 2

Notify maintainers

nixos-enter doesn't appear on search.nixos.org. Taking maintainer from manpage: @edolstra

coreutils for chroot: @dasJ

su doesn't seem to have any maintainers.

Metadata

Basically what you'd get on the latest 23.11 image, because that's where I'm running this. I want to run it post-install, before first boot.

Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.

[nixos@nixos:~]$ nix-shell -p nix-info --run "nix-info -m"
 - system: `"x86_64-linux"`
 - host os: `Linux 6.1.73, NixOS, 23.11 (Tapir), 23.11.3019.8bf65f17d807`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.18.1`
 - channels(root): `"nixos-23.11.3019.8bf65f17d807"`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`

Add a :+1: reaction to issues you find important.

TornaxO7 commented 5 months ago

Is there any known workaround for this? My whole nixos-system is broken since the last unstable-update (all generations are unable to boot) and I can't rebuild my system due to this bug.

ErrorNoInternet commented 5 months ago

and I can't rebuild my system due to this bug.

Does

export SUDO_USER=
nixos-rebuild boot

(yes, empty SUDO_USER) do anything?

Andy3153 commented 5 months ago

What does sudo have to do with it though? On my config, I have sudo disabled and doas enabled instead and it still happens. It's about su

ErrorNoInternet commented 5 months ago

What does sudo have to do with it though? On my config, I have sudo disabled and doas enabled instead and it still happens. It's about su

It doesn't have anything to do with sudo (except PAM), I was replying to that specific comment ("and I can't rebuild my system due to this bug.").

I see the same error with sudo in a nixos-enter, and I also couldn't rebuild my system until I did export SUDO_USER= since nixos-rebuild uses sudo as long as you have a non-empty SUDO_USER.

TornaxO7 commented 5 months ago

I just reinstalled my whole system with nixos-install --flake <bla>. Well, that worked at least...

wasv commented 3 months ago

What does sudo have to do with it though? On my config, I have sudo disabled and doas enabled instead and it still happens. It's about su

It doesn't have anything to do with sudo (except PAM), I was replying to that specific comment ("and I can't rebuild my system due to this bug.").

I see the same error with sudo in a nixos-enter, and I also couldn't rebuild my system until I did export SUDO_USER= since nixos-rebuild uses sudo as long as you have a non-empty SUDO_USER.

I had the same issue and adding export SUDO_USER= before my nixos-rebuild does workaround the PAM error I was seeing, and let me rebuild within a nixos-enter chroot successfully.