Running containers within a (sandboxed) nix-build

I’m highly interested in spawning containers as part of a nix build.
I had a look at https://rootlesscontaine.rs/ to see if I could make it work, but it seems pretty much every container technology at least needs /etc/subuid and /etc/subgid configured. On a regular multi user nix installation the nixbuild users don’t have entries in these files. It seems to me however that within a nix-build this file wouldn’t be mapped into the build environment so that might not matter.
I’m wondering if anyone was already successful in this feat or if it requires patching nix to create these files as part of derivation-goal.cc.

My main motivation here is to benefit from nix’s reproducibility features when building software for other distros and using “off-the-shelf” containers.

I know that for that use case there also exists an infrastructure for spawning VMs, but that requires both KVM enabled and also it is harder for me to pass through some impure locations from the host (which I use to run CUDA code on an Nvidia GPU as part of the nix-build for some projects’ unit tests: /dev/nvidiactl)

2 Likes

As mentioned here, the uid issue is being worked on in this PR.

1 Like

runInLinuxVM does not require KVM. It did for some time, but that has been fixed AFAIK.

runInLinuxVM does not require KVM. It did for some time, but that has been fixed AFAIK.

I just checked today’s master and it still has:

  runInLinuxVM = drv: lib.overrideDerivation drv ({ memSize ? 512, QEMU_OPTS ? "", args, builder, ... }: {
    requiredSystemFeatures = [ "kvm" ];

in pkgs/build-support/vm/default.nix#L307. Am I missing something?