Skip to content

nh does not try to elevate privileges when called with --bypass-root-check #439

@fugidev

Description

@fugidev

I have confirmed that this is a bug related to nh

  • This is a bug, and not an user error or a support request. I understand that my issue will be closed if it is not a bug in NH.
  • I have checked the issues tab and confirmed that my issue has not yet been reported. I understand that my issue will be closed if it is a duplicate.

Description

nh does not try to elevate privileges (i.e. call sudo when needed), when called with --bypass-root-check or if NH_BYPASS_ROOT_CHECK env variable is set. This is an issue when you have NH_BYPASS_ROOT_CHECK set globally, but also use nh as non-root user. (I know this can be easily worked around, but it is a bug – the flag's description says "Don't panic if calling nh as root", so it should not change any behaviour when not called as root.)

logs:

! Bypassing root check, now running nix as root (nh/src/nixos.rs:108)
> Building NixOS configuration
fetching git input 'git+file:///etc/nixos'
warning: Git tree '/etc/nixos' is dirty
Finished at 11:21:59 after 0s
[...]
> Apply the config? Yes
> Activating configuration
Error: switch-to-configuration must be run as the root user
Error: 
   0: Activation (test) failed
   1: Activating configuration (exit status Exited(1))

Location:
   src/commands.rs:562

Installation Method

Stable Release (nixpkgs, pkgs.nh from nixos-unstable or nixos-yy-mm)

Installation Method (Other)

I have also tried nh from nix shell github:nix-community/nh.

NH Version

4.2.0

System Information

  • system: "x86_64-linux"
  • host os: Linux 6.16.9, NixOS, 25.11 (Xantusia), 25.11.20251002.7df7ff7
  • multi-user?: yes
  • sandbox: yes
  • version: nix-env (Lix, like Nix) 2.93.3 System type: x86_64-linux Additional system types: i686-linux, x86_64-v1-linux, x86_64-v2-linux, x86_64-v3-linux Features: gc, signed-caches System configuration file: /etc/nix/nix.conf User configuration files: /home/fugi/.config/nix/nix.conf:/etc/xdg/nix/nix.conf:/home/fugi/.nix-profile/etc/xdg/nix/nix.conf:/nix/profile/etc/xdg/nix/nix.conf:/home/fugi/.local/state/nix/profile/etc/xdg/nix/nix.conf:/etc/profiles/per-user/fugi/etc/xdg/nix/nix.conf:/nix/var/nix/profiles/default/etc/xdg/nix/nix.conf:/run/current-system/sw/etc/xdg/nix/nix.conf Store directory: /nix/store State directory: /nix/var/nix Data directory: /nix/store/23a2fc0ha64j2ygaq8b9gaqc5sb0whf7-lix-2.93.3/share
  • nixpkgs: /nix/store/9v6qa656sq3xc58vkxslqy646p0ajj61-source

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions