Merge pull request #204 from tylerjl/qcow-efi

qcow-efi format with ESP mount and configurable diskSize
This commit is contained in:
lassulus 2024-02-20 11:11:16 +07:00 committed by GitHub
commit fa146e1a15
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 62 additions and 1 deletions

View File

@ -9,6 +9,7 @@ For example:
```
nixos-generate -f iso
```
or
```
@ -64,6 +65,7 @@ openstack | qcow2 image for openstack
proxmox | [VMA](https://pve.proxmox.com/wiki/VMA) file for proxmox
proxmox-lxc | LXC template for proxmox
qcow | qcow2 image
qcow-efi | qcow2 image with efi support
raw | raw image with bios/mbr. for physical hardware, see the 'raw and raw-efi' section
raw-efi | raw image with efi support. for physical hardware, see the 'raw and raw-efi' section
sd-aarch64 | Like sd-aarch64-installer, but does not use default installer image config.
@ -124,6 +126,7 @@ To cross compile nixos images for other architectures you have to configure
`boot.binfmt.emulatedSystems` or `boot.binfmt.registrations` on your host system.
In your system `configuration.nix`:
```nix
{
# Enable binfmt emulation of aarch64-linux.
@ -132,6 +135,7 @@ In your system `configuration.nix`:
```
Alternatively, if you want to target other architectures:
```nix
# Define qemu-arm-static source.
let qemu-arm-static = pkgs.stdenv.mkDerivation {
@ -229,7 +233,7 @@ Images can be built from that flake by running:
`nixos-generators` can be included as a `Flake` input and provides
a `nixos-generate` function for building images as `Flake` outputs. This
approach pins all dependencies and allows for conveniently defining multiple
output types based on one config.
output types based on one config.
An example `flake.nix` demonstrating this approach is below. `vmware` or
`virtualbox` images can be built from the same `configuration.nix` by running

57
formats/qcow-efi.nix Normal file
View File

@ -0,0 +1,57 @@
{ config, lib, pkgs, modulesPath, ... }:
{
# for virtio kernel drivers
imports = [
"${toString modulesPath}/profiles/qemu-guest.nix"
];
options = {
boot = {
consoles = lib.mkOption {
default = [ "ttyS0" ] ++
(lib.optional (pkgs.stdenv.hostPlatform.isAarch) "ttyAMA0,115200") ++
(lib.optional (pkgs.stdenv.hostPlatform.isRiscV64) "ttySIF0,115200");
description = "Kernel console boot flags to pass to boot.kernelParams";
example = [ "ttyS2,115200" ];
};
diskSize = lib.mkOption {
default = "auto";
description = "The disk size in megabytes of the system disk image.";
type = with lib.types; oneOf [ ints.positive (enum [ "auto" ])];
};
};
};
config = {
fileSystems."/" = {
device = "/dev/disk/by-label/nixos";
autoResize = true;
fsType = "ext4";
};
fileSystems."/boot" = {
device = "/dev/disk/by-label/ESP";
fsType = "vfat";
};
boot.growPartition = true;
boot.kernelParams = map (c: "console=${c}") config.boot.consoles;
boot.loader.grub.device = "nodev";
boot.loader.grub.efiSupport = true;
boot.loader.grub.efiInstallAsRemovable = true;
boot.loader.timeout = 0;
system.build.qcow-efi = import "${toString modulesPath}/../lib/make-disk-image.nix" {
inherit lib config pkgs;
diskSize = config.boot.diskSize;
format = "qcow2";
partitionTableType = "efi";
};
formatAttr = "qcow-efi";
fileExtension = ".qcow2";
};
}