Skip to content

Instantly share code, notes, and snippets.

@eugeneia
Created June 8, 2018 23:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eugeneia/6169ee084e0dd9c2a22d33e8c7a10203 to your computer and use it in GitHub Desktop.
Save eugeneia/6169ee084e0dd9c2a22d33e8c7a10203 to your computer and use it in GitHub Desktop.
{ config, pkgs, lib, ... }:
# allows sudo in chroots by introducing some impurities
# has to be available on all servers for builds to always have those paths available inside chroot
with pkgs;
let
# use sudo without pam (eaiser in chroots)
sudoChroot = sudo.overrideDerivation (super: {
configureFlags = super.configureFlags ++ [ "--without-pam" ];
postInstall = ''
mv $out/bin/sudo $out/bin/sudo-chroot
'';
});
in {
nix.sandboxPaths = [
"/run/wrappers/bin/sudo=/run/wrappers/bin/sudo-chroot"
"/run/wrappers/bin/sudo.real=/run/wrappers/bin/sudo-chroot.real"
"${sudoChroot}"
"${libcap}"
"${libcap_ng}"
"/etc/sudoers"
"/etc/passwd"
"/sys"
# Snabb benchmark specific
"/dev/hugepages"
"/dev/net"
"/dev/cpu"
];
environment.systemPackages = [ (lowPrio sudoChroot) ];
security.wrappers.sudoChroot = {
source = "${sudoChroot}/bin/sudo-chroot";
program = "sudo-chroot";
};
# legacy/deprecated solution (no chroot)
nix.useSandbox = lib.mkForce "relaxed";
security.sudo.extraConfig = lib.concatMapStringsSep "\n" (i: "nixbld${toString i} ALL=(ALL) NOPASSWD:ALL") (lib.range 1 config.nix.nrBuildUsers);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment