From f5cc4b55e5adc8a19b1e986245f632e006226e01 Mon Sep 17 00:00:00 2001 From: matthewcroughan Date: Wed, 3 Jul 2024 19:53:13 +0100 Subject: [PATCH 1/3] make-disk-image: allow kernel to be overriden by disko configuration This is especially useful when trying to build images for embedded systems such as the pi, which have a vendor kernel that can't be booted as part of the disko image builder process --- lib/make-disk-image.nix | 2 +- module.nix | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/make-disk-image.nix b/lib/make-disk-image.nix index a61e937..e1f7e36 100644 --- a/lib/make-disk-image.nix +++ b/lib/make-disk-image.nix @@ -10,7 +10,7 @@ let vmTools = pkgs.vmTools.override { rootModules = [ "9p" "9pnet_virtio" "virtio_pci" "virtio_blk" ] ++ nixosConfig.config.disko.extraRootModules; kernel = pkgs.aggregateModules - (with nixosConfig.config.boot.kernelPackages; [ kernel ] + (with nixosConfig.config.disko.imageBuilderKernelPackages; [ kernel ] ++ lib.optional (lib.elem "zfs" nixosConfig.config.disko.extraRootModules) zfs); }; cleanedConfig = diskoLib.testLib.prepareDiskoConfig nixosConfig.config diskoLib.testLib.devices; diff --git a/module.nix b/module.nix index 8c8fbc3..33b58dc 100644 --- a/module.nix +++ b/module.nix @@ -10,6 +10,17 @@ let in { options.disko = { + imageBuilderKernel = lib.mkOption { + type = lib.types.package; + imageBuilderKernelPackages = lib.mkOption { + type = lib.types.attrs; + description = '' + the kernel used when building disk images via make-disk-image.nix. + Useful when the config's kernel won't boot in the image-builder. + ''; + default = config.boot.kernelPackages; + example = lib.literalExpression "pkgs.linuxPackages_testing"; + }; extraRootModules = lib.mkOption { type = lib.types.listOf lib.types.str; description = '' From de015d2a44632ea1102522e609c0beba0e57a18b Mon Sep 17 00:00:00 2001 From: matthewcroughan Date: Mon, 8 Jul 2024 20:11:00 +0100 Subject: [PATCH 2/3] make-disk-image: allow pkgs to be overriden by disko configuration This is needed when the nixosConfig you're building for modifies nixpkgs options that lead to evaluation failing unnecessarily --- lib/make-disk-image.nix | 2 +- module.nix | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/make-disk-image.nix b/lib/make-disk-image.nix index e1f7e36..9979b21 100644 --- a/lib/make-disk-image.nix +++ b/lib/make-disk-image.nix @@ -1,6 +1,6 @@ { nixosConfig , diskoLib -, pkgs ? nixosConfig.pkgs +, pkgs ? nixosConfig.config.disko.imageBuilderPkgs , lib ? pkgs.lib , name ? "${nixosConfig.config.networking.hostName}-disko-images" , extraPostVM ? nixosConfig.config.disko.extraPostVM diff --git a/module.nix b/module.nix index 33b58dc..321cc0e 100644 --- a/module.nix +++ b/module.nix @@ -12,6 +12,15 @@ in options.disko = { imageBuilderKernel = lib.mkOption { type = lib.types.package; + imageBuilderPkgs = lib.mkOption { + type = lib.types.attrs; + description = '' + the pkgs instance used when building disk images via make-disk-image.nix. + Useful when the config's kernel won't boot in the image-builder. + ''; + default = pkgs; + example = lib.literalExpression "pkgs"; + }; imageBuilderKernelPackages = lib.mkOption { type = lib.types.attrs; description = '' From d8a1d5e1f0885d151801ef3e35251a475f53691e Mon Sep 17 00:00:00 2001 From: matthewcroughan Date: Mon, 8 Jul 2024 20:12:36 +0100 Subject: [PATCH 3/3] make-disk-image: allow vmTools qemu usage to be overriden by disko configuration This is needed to prevent two layers of emulation when offering a build for a host running binfmt such as an x86 host trying to compile for aarch64 via binfmt --- lib/make-disk-image.nix | 1 + module.nix | 12 ++++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/make-disk-image.nix b/lib/make-disk-image.nix index 9979b21..c03676e 100644 --- a/lib/make-disk-image.nix +++ b/lib/make-disk-image.nix @@ -9,6 +9,7 @@ let vmTools = pkgs.vmTools.override { rootModules = [ "9p" "9pnet_virtio" "virtio_pci" "virtio_blk" ] ++ nixosConfig.config.disko.extraRootModules; + customQemu = nixosConfig.config.disko.imageBuilderQemu; kernel = pkgs.aggregateModules (with nixosConfig.config.disko.imageBuilderKernelPackages; [ kernel ] ++ lib.optional (lib.elem "zfs" nixosConfig.config.disko.extraRootModules) zfs); diff --git a/module.nix b/module.nix index 321cc0e..d58f6ef 100644 --- a/module.nix +++ b/module.nix @@ -10,8 +10,16 @@ let in { options.disko = { - imageBuilderKernel = lib.mkOption { - type = lib.types.package; + imageBuilderQemu = lib.mkOption { + type = lib.types.nullOr lib.types.str; + description = '' + the qemu emulator string used when building disk images via make-disk-image.nix. + Useful when using binfmt on your build host, and wanting to build disk + images for a foreign architecture + ''; + default = null; + example = lib.literalExpression "''${pkgs.qemu_kvm}/bin/qemu-system-aarch64"; + }; imageBuilderPkgs = lib.mkOption { type = lib.types.attrs; description = ''