"{kvm} is required" error building a Docker image using "runAsRoot"

With a big of digging, I found this post, which suggested adding:

system-features = kvm

to /etc/nix/nix.conf. That enabled the build to work without an error (although I got the following logs - it looks like it’s using QEMU TCG emulation to run something?)

Could not access KVM kernel module: No such file or directory
qemu-kvm: failed to initialize kvm: No such file or directory
qemu-kvm: falling back to tcg
cSeaBIOS (version rel-1.16.0-0-gd239552ce722-prebuilt.qemu.org)


iPXE (http://ipxe.org) 00:03.0 CA00 PCI2.10 PnP PMM+1FF90FC0+1FEF0FC0 CA00



Booting from ROM...
Probing EDD (edd=off to disable)... ocloading kernel modules...
[    2.928094] Invalid ELF header magic: != ELF
[    3.186787] Invalid ELF header magic: != ELF
[    3.261119] Invalid ELF header magic: != ELF
[    3.324290] Invalid ELF header magic: != ELF
[    4.836923] Invalid ELF header magic: != ELF
[    4.908298] Invalid ELF header magic: != ELF
[    5.039657] Invalid ELF header magic: != ELF
[    5.115107] Invalid ELF header magic: != ELF
[    5.186883] Invalid ELF header magic: != ELF
[    5.259467] Invalid ELF header magic: != ELF
[    5.421870] Invalid ELF header magic: != ELF
[    5.490063] Invalid ELF header magic: != ELF
[    5.551640] Invalid ELF header magic: != ELF
[    5.621662] Invalid ELF header magic: != ELF
[    5.690720] Invalid ELF header magic: != ELF
[    6.290835] Invalid ELF header magic: != ELF
[    6.442829] Invalid ELF header magic: != ELF
[    6.578055] Invalid ELF header magic: != ELF
[    6.681639] Invalid ELF header magic: != ELF
[    6.751195] Invalid ELF header magic: != ELF

For future Googling in case it helps someone else - I could also do the same the workaround in a Github Cachix action as follows:

    - name: Install Nix
      uses: cachix/install-nix-action@v18
      with:
        # Needed for "runAsRoot" capability
        extra_nix_config: |
          system-features = kvm