-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add NixOS image for bare-metal Kata #1019
base: main
Are you sure you want to change the base?
Changes from all commits
1435b47
8c9c247
1cf1c67
accbe46
93c473d
6b903fc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
|
||
{ | ||
writeShellApplication, | ||
qemu, | ||
OVMF, | ||
}: | ||
|
||
# Usage example: | ||
# outPath=$(nix build .#kata.kata-image --print-out-paths); nix run .#boot-microvm -- "${outPath}/bzImage" "${outPath}/initrd" "${outPath}/image-podvm-gpu_1-rc1.raw" "$(nix eval --raw .#kata.kata-image.cmdline)" | ||
burgerdev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
writeShellApplication { | ||
name = "boot-microvm"; | ||
runtimeInputs = [ qemu ]; | ||
text = '' | ||
if [ $# -ne 4 ]; then | ||
echo "Usage: $0 <kernel> <initrd> <rootfs> <cmdline>"; | ||
exit 1; | ||
fi | ||
|
||
tmpFile=$(mktemp) | ||
cp "$3" "$tmpFile" | ||
|
||
qemu-system-x86_64 \ | ||
-enable-kvm \ | ||
-m 3G \ | ||
-nographic \ | ||
-drive if=pflash,format=raw,readonly=on,file=${OVMF.firmware} \ | ||
-drive if=pflash,format=raw,readonly=on,file=${OVMF.variables} \ | ||
-kernel "$1" \ | ||
-initrd "$2" \ | ||
-append "$4" \ | ||
-drive "if=virtio,format=raw,file=$tmpFile" | ||
''; | ||
} |
msanft marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. package comment seems outdated. What part of this is microvm specific at this point? Looks like it's just an image in parts compared to packaging it as uki. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's still a valid name for a non-bootable image like this, as you can boot it without a rootfs. But I'm also open for other suggestions here. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# 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: | ||
|
||
let | ||
image = nixos-config.image.overrideAttrs (oldAttrs: { | ||
passthru = oldAttrs.passthru // { | ||
imageFileName = "${oldAttrs.pname}_${oldAttrs.version}.raw"; | ||
}; | ||
}); | ||
in | ||
|
||
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 | ||
{ | ||
pname = "microvm-image"; | ||
inherit (nixos-config.config.system.image) version; | ||
|
||
paths = [ | ||
nixos-config.config.system.build.kernel | ||
nixos-config.config.system.build.initialRamdisk | ||
image | ||
]; | ||
|
||
passthru = | ||
let | ||
roothash = builtins.head ( | ||
lib.map (e: e.roothash) (builtins.fromJSON (builtins.readFile "${image}/repart-output.json")) | ||
); | ||
in | ||
{ | ||
cmdline = lib.concatStringsSep " " ( | ||
nixos-config.config.boot.kernelParams | ||
++ [ | ||
"init=${nixos-config.config.system.build.toplevel}/init" | ||
"roothash=${roothash}" | ||
] | ||
); | ||
inherit (image) imageFileName; | ||
}; | ||
} |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rather phrase this positively, listing the options that are expected to work. Initial list:
runtime.create_container_timeout
hypervisor.default_memory
(only upwards?)hypervisor.default_vcpus
agent.kernel_modules
(?)Reading through the linked doc, I noticed that we're not setting
container_annotations
. Maybe doesn't make a difference now, but we might want to add it.This doc change could be in a separate commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can hardly list things that are expected to work, as we don't test any of these. What do you think?
I'm also fine with specifying that some may work, and when they are useful.
I'm not sure about how
agent.kernel_modules
should work exactly, but besides the NVIDIA driver for GPU images, our images don't actually contain loadable modules.Re
container_annotations
: Yeah, I think we'll want to set these.