Sudo not working inside a buildFHSUserEnv: "no new privileges" flag

Hi there. Does anyone know how to get sudo privileges inside a fhs?

Minimal example of a buildFHSUserEnv:

# shell.nix
{ pkgs ? import <nixpkgs> {} }:
(pkgs.buildFHSUserEnv {
  name = "example";
  targetPkgs = pkgs: (with pkgs; [ libgcc ]);
  runScript = "bash";
}).env

Start with nix-shell. But sudo is disabled:

$ sudo
sudo: The "no new privileges" flag is set, which prevents sudo from running as root.
sudo: If sudo is running in a container, you may need to adjust the container configuration to disable the flag.

Any help welcome, thanks!

3 Likes

I would love to know this too.
since I want to get a deb file running that has binaries that need root.

https://ryantm.github.io/nixpkgs/builders/special/fhs-environments/

It seems that FHSEnv will not by design be able to allow root.

You just can’t do it.

Or I am missing sth.

1 Like

I’m also still looking for a solution. But I just found this workaround, however I did not tried it out yet.

Some other links that may help and I need to have a closer look at when i find time to do so:

1 Like

The only attainable “proper” way out I can think of is to use polkit to elevate privileges. The new systemd 256 actually has a tool precisely for that purpose which you might want check out or build yourself atop of systemd-run.

1 Like