Skip to content

Commit

Permalink
packages/buildMicroVM: init
Browse files Browse the repository at this point in the history
This adds a builder for "MicroVM" images which are comprised of only a kernel, its kernel command line, and a root filesystem image. Additionally, this builder has a sanity check to see if the rootfs image contains an ESP, which indicates that an image thats not supposed to be a microVM was built with this builder.
  • Loading branch information
msanft committed Nov 12, 2024
1 parent 579e51f commit 2d44a8f
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions packages/by-name/buildMicroVM/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Copyright 2024 Edgeless Systems GmbH
# SPDX-License-Identifier: AGPL-3.0-only

# Builds a micro VM image (i.e. rootfs, kernel and kernel cmdline) from a NixOS
# configuration. These components can then be booted in a microVM-fashion
# with QEMU's direct Linux boot feature.
# See: https://qemu-project.gitlab.io/qemu/system/linuxboot.html

{
symlinkJoin,
lib,
...
}:

nixos-config:

lib.throwIf
(lib.foldlAttrs (
acc: _: partConfig:
acc || (partConfig.repartConfig.Type == "esp")
) false nixos-config.config.image.repart.partitions)
"MicroVM images should not contain an ESP."

symlinkJoin
{
name = "microvm-image";

paths = [
nixos-config.config.system.build.kernel
nixos-config.config.system.build.image
];

postBuild = ''
echo -n ${lib.concatStringsSep " " nixos-config.config.boot.kernelParams} > $out/kernel-params
'';
}

0 comments on commit 2d44a8f

Please sign in to comment.