aboutsummaryrefslogtreecommitdiffstats
path: root/base/kernel.nix
blob: 16983c7fda1d4253d97df14f18648bae01bef77f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# Cut-down guest kernel, based on Firecracker's recommended configuration,
# as a module for the base system:
#   nix-build pkgs/run-firecracker-vm --arg base '[ base/kernel.nix ]'
# With erofs and 9P (for the store), and KVM as modules, which load when
# the VMM offers hardware virtualization (run-firecracker-vm --nested).
{ pkgs, ... }:
let
  linux = pkgs.linux_6_18;

  firecrackerConfig = pkgs.fetchurl {
    url = "https://raw.githubusercontent.com/firecracker-microvm/firecracker/cc88013eadcf432da1b37d47d445b7e8bcc3046e/resources/guest_configs/microvm-kernel-ci-x86_64-6.18.config";
    sha256 = "05ajrz05kcfk0qa6gvgssazz38flcaji1kgb4k0a94kj1hd408ms";
  };

  configfile = pkgs.stdenv.mkDerivation {
    name = "linux-config-${linux.version}-firecracker";
    inherit (linux) src;
    nativeBuildInputs = [ pkgs.bison pkgs.flex ];
    dontConfigure = true;
    buildPhase = ''
      cat ${firecrackerConfig} - > .config <<EOF
      CONFIG_EROFS_FS=m
      CONFIG_NET_9P=m
      CONFIG_9P_FS=m
      CONFIG_VIRTUALIZATION=y
      CONFIG_KVM=m
      CONFIG_KVM_AMD=m
      CONFIG_KVM_INTEL=m
      EOF
      make olddefconfig
    '';
    installPhase = ''
      cp .config $out
    '';
  };
in
{
  boot.kernelPackages = pkgs.linuxPackagesFor (pkgs.linuxManualConfig {
    inherit (linux) src version modDirVersion;
    inherit configfile;
    allowImportFromDerivation = true;
  });
}