NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.15k stars 13.42k forks source link

`nixos-rebuild` failed to run in rescue USB `chroot` when `sudo` is not installed (used `doas` instead) #268134

Open amalgame21 opened 9 months ago

amalgame21 commented 9 months ago

I am testing the latest stable NixOS. I followed this guide to use doas instead of sudo. It works fine.

Today I have to use live USB to rescue my OS, because I messed up with the hardware-configuration.nix and it was no longer bootable. In the chroot environment after running nixos-enter, nixos-rebuild switch failed to run because it hit this line: https://github.com/NixOS/nixpkgs/blob/08be2ef0bfd785b984bd0fc66d764b153afaf28f/pkgs/os-specific/linux/nixos-rebuild/nixos-rebuild.sh#L161

And I have to remove the "${maybeSudo[@]}" in this line manually to make it run (with some error, but at least it process hardware-configuration.nix and the OS is bootable again after that). https://github.com/NixOS/nixpkgs/blob/08be2ef0bfd785b984bd0fc66d764b153afaf28f/pkgs/os-specific/linux/nixos-rebuild/nixos-rebuild.sh#L189

Am I doing something wrong?

By the way, in the doas wiki, The syntax of security.doas.extraRules = { ... } is wrong. It should be security.doas.extraRules = [{ ... }].

FliegendeWurst commented 9 months ago

Let's ping the nixos-rebuild package maintainer @Profpatsch.

Is there a particular reason nixos-rebuild.sh only checks for sudo here?

amalgame21 commented 9 months ago

Sorry I just noticed that the wiki is unofficial.

ryze312 commented 8 months ago

Encountering the same issue on unstable channel, removing "${maybeSudo[@]}" or replacing it with doas causes it to fail with

building the system configuration...
'/nix/store/v4ymdm28ycahb7c6s5jpgaw9jvb23lr3-system-path/bin/busctl --json=short call org.freedesktop.systemd1 /org/freedesktop/systemd1 org.freedesktop.systemd1.Manager ListUnitsByPatterns asas 0 0' exited with value 1 at /nix/store/656162gvsjii70n248ksg8yxmdh7apaw-nixos-system-hostname-24.05.20231129.e92039b/bin/switch-to-configuration line 145.
warning: error(s) occurred while switching to the new configuration
poweredbypie commented 5 months ago

I ran into the same issue but only because my EFI entries got wiped somehow (no data lost, just EFI entry broke). Turns out (in my case) I could just reinstall the bootloader entries as shown in the wiki: https://nixos.wiki/wiki/Bootloader#From_an_installation_media If this link is broken in the future, here's the command I ran in a Ubuntu installation USB (after manually mounting system root in /mnt, along with dev, sys, and proc):

NIXOS_INSTALL_BOOTLOADER=1 chroot /mnt /nix/var/nix/profiles/system/bin/switch-to-configuration boot
useranon350 commented 2 months ago

I've seen similar issues when sudo won't run correctly due to a misconfiguration of some sort.