third_party/nix: move overrides to toolchain-bundle derivation

We have multiple consumers of nixpkgs. The nix-shell for development
and our toolchain-bundle. To reduce the amount of applied overlays
in normal evaluation, we move all overrides/patches that are only
required for the toolchain bundle to its definition. Additionally
all small overrides get inlined as its actually more easy to read.
I also refactored the way the toolchain-bundle is constructed to make
it easier to extend.

Change-Id: If7daafb6de43d26a0b95d0248cfb8c573cc5bbbe
Reviewed-on: https://review.monogon.dev/c/monogon/+/4457
Reviewed-by: Leopold Schabel <leo@monogon.tech>
Tested-by: Jenkins CI
diff --git a/build/toolchain/toolchain-bundle/pkgs/qemu/default.nix b/build/toolchain/toolchain-bundle/pkgs/qemu/default.nix
new file mode 100644
index 0000000..81f8825
--- /dev/null
+++ b/build/toolchain/toolchain-bundle/pkgs/qemu/default.nix
@@ -0,0 +1,47 @@
+{ qemu_kvm, audit, ... }:
+let
+  qemuMinimal = qemu_kvm.override (old: {
+    hostCpuOnly = true;
+    vncSupport = true;
+
+    # Disable everything we don't need.
+    enableDocs = false;
+    ncursesSupport = false;
+    seccompSupport = false;
+    numaSupport = false;
+    alsaSupport = false;
+    pulseSupport = false;
+    pipewireSupport = false;
+    sdlSupport = false;
+    jackSupport = false;
+    gtkSupport = false;
+    smartcardSupport = false;
+    spiceSupport = false;
+    usbredirSupport = false;
+    xenSupport = false;
+    cephSupport = false;
+    glusterfsSupport = false;
+    openGLSupport = false;
+    rutabagaSupport = false;
+    virglSupport = false;
+    libiscsiSupport = false;
+    smbdSupport = false;
+    uringSupport = false;
+    canokeySupport = false;
+    capstoneSupport = false;
+  });
+in
+qemuMinimal.overrideAttrs (old: {
+  # Static build patch
+  # Based on https://github.com/NixOS/nixpkgs/pull/333923
+
+  patches = (old.patches ++ [
+    ./static_build_crc32c_duplicate_definition.patch
+  ]);
+
+  configureFlags = (builtins.filter (v: v != "--static") old.configureFlags) ++ [ "--disable-libcbor" ];
+  strictDeps = true;
+  # a private dependency of PAM which is not linked explicitly in static builds
+  buildInputs = old.buildInputs ++ [ audit ];
+  env.NIX_LDFLAGS = " -laudit ";
+})