agam
agam

Reputation: 5364

Can't seem to get sudo working under NixOS

The title (embarassing as it is) says it all. Some context first:

I'm running NixOS using a custom ISO on Vultr.

Timeframe of attempts:

[root@nixos:/home/agam]# chmod 4755 /nix/var/nix/profiles/default/bin/sudo
chmod: changing permissions of '/nix/var/nix/profiles/default/bin/sudo': Read-only file system

Any clues on what's going on here?

Some possible options I see here are: 1. The custom ISO that Vultr provided was ... missing something 2. Some fundamentally different ways that sudo is supposed to work in NixOS 3. I'm missing something very basic in how to go about using Nix (most likely!)

Some details:

[agam@nixos:~]$ nixos-version
18.09.1534.d45a0d7a4f5 (Jellyfish)

[agam@nixos:~]$ which sudo
/nix/var/nix/profiles/default/bin/sudo

[agam@nixos:~]$ nix-channel --list
nixos https://nixos.org/channels/nixos-18.09

Edit: final set of steps that worked:

  1. As suggested in the answer, enable sudo first:
security.sudo.enable =  true;
  1. Add a sudoers section to /etc/nixos/configuration.nix:
  # Allow members of the "wheel" group to sudo:
  security.sudo.configFile = ''
    %wheel ALL=(ALL) ALL
  '';
  1. Add myself to wheel:
usermod -a -G wheel agam

Upvotes: 5

Views: 4867

Answers (1)

Robert Hensing
Robert Hensing

Reputation: 7359

The way to install sudo on NixOS is by adding to configuration.nix:

security.sudo.enable = true;

Nix by itself is simply not capable of creating setuid binaries like sudo. Otherwise it could not be "safe and policy free" - no multi user support. The nix/nix-* tools are designed to perform safe store operations and not to allow elevation of privileges.

In order to support setuid binaries like sudo, NixOS maintains a directory of setuid wrappers outside the Nix store, in /run/wrappers. This is only possible because NixOS is started/switched/activated with root privileges.

Upvotes: 5

Related Questions