mirror of
https://github.com/nix-community/disko.git
synced 2026-12-04 15:03:28 +01:00
make-disk-image: support vmTools kernelModules with backward compatibility (#1301)
Closes #1298 Supersedes #1277 Supersedes #1299 ### Problem Following nixpkgs commit 68d32ed6cbd986a84582b88780168d22adebd6fc (PR #530764), `pkgs.vmTools` split the boot kernel image (`kernel`) from the initrd modules tree (`kernelModules`). When building disk images or `vmWithDisko` against recent `nixpkgs-unstable`, `make-disk-image.nix` fails during evaluation: ``` error: vmTools: the `kernel` argument (kernel-modules) has no `target` attribute, so the kernel image filename cannot be determined. If you are passing a module tree (e.g. from `pkgs.aggregateModules`) to make extra modules available, pass it via `kernelModules` instead and keep `kernel` pointing at a real kernel derivation. ``` Previous attempts (#1277, #1299) attempted an unconditional pass of `kernelModules`, but this fails on older nixpkgs (including disko's current locked nixpkgs) with `unexpected argument 'kernelModules'`. ### Fix 1. Added helper `diskoLib.vmToolsSupportsKernelModules`: ```nix vmToolsSupportsKernelModules = pkgs: (pkgs.vmTools.override.__functionArgs or ( if lib.isFunction pkgs.vmTools.override then builtins.functionArgs pkgs.vmTools.override else { } ) ) ? kernelModules; ``` 2. In `lib/make-disk-image.nix`, conditionally pass `kernel` and `kernelModules` if supported by `pkgs.vmTools`, else fall back to `kernel = modulesTree`. This ensures full backward compatibility across nixpkgs versions without requiring a `flake.lock` bump. ### Verification - **Modern nixpkgs**: Evaluated `nix eval --override-input nixpkgs nixpkgs .#checks.x86_64-linux.make-disk-image.drvPath` — successfully produces derivation (previously failed with the error above). - **Locked nixpkgs**: Evaluated `nix eval .#checks.x86_64-linux.make-disk-image.drvPath` — passes cleanly. - **Checks & formatting**: `nix build .#checks.x86_64-linux.treefmt`, `checkJqSyntax`, and `jsonTypes` all pass cleanly.
This commit is contained in:
2 files changed
+33
-9
No files matched your search
@@ -646,6 +646,19 @@ let
|
|||||||
*/
|
*/
|
||||||
vmToolsSupportsCustomQemu = final_lib: lib.versionAtLeast final_lib.version "24.11.20240709";
|
vmToolsSupportsCustomQemu = final_lib: lib.versionAtLeast final_lib.version "24.11.20240709";
|
||||||
|
|
||||||
|
/*
|
||||||
|
Checks whether vmTools supports the kernelModules argument.
|
||||||
|
Older nixpkgs versions only supported overriding `kernel` with an aggregated modules tree.
|
||||||
|
|
||||||
|
vmToolsSupportsKernelModules :: pkgs -> bool
|
||||||
|
*/
|
||||||
|
vmToolsSupportsKernelModules =
|
||||||
|
pkgs:
|
||||||
|
(pkgs.vmTools.override.__functionArgs or (
|
||||||
|
if lib.isFunction pkgs.vmTools.override then builtins.functionArgs pkgs.vmTools.override else { }
|
||||||
|
)
|
||||||
|
) ? kernelModules;
|
||||||
|
|
||||||
optionTypes = rec {
|
optionTypes = rec {
|
||||||
filename = lib.mkOptionType {
|
filename = lib.mkOptionType {
|
||||||
name = "filename";
|
name = "filename";
|
||||||
|
|||||||
+20
-9
@@ -27,6 +27,15 @@ let
|
|||||||
${pkgs.systemdMinimal}/lib/systemd/systemd-binfmt <(echo ${lib.strings.escapeShellArg binfmt.binfmtRegistration})
|
${pkgs.systemdMinimal}/lib/systemd/systemd-binfmt <(echo ${lib.strings.escapeShellArg binfmt.binfmtRegistration})
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
modulesTree = pkgs.aggregateModules (
|
||||||
|
[
|
||||||
|
cfg.kernelPackages.kernel
|
||||||
|
]
|
||||||
|
++ lib.optional (cfg.kernelPackages.kernel ? modules) cfg.kernelPackages.kernel.modules
|
||||||
|
++ lib.optional (
|
||||||
|
lib.elem "zfs" cfg.extraRootModules || configSupportsZfs
|
||||||
|
) cfg.kernelPackages.${config.boot.zfs.package.kernelModuleAttribute}
|
||||||
|
);
|
||||||
vmTools = pkgs.vmTools.override (
|
vmTools = pkgs.vmTools.override (
|
||||||
{
|
{
|
||||||
rootModules = [
|
rootModules = [
|
||||||
@@ -41,16 +50,18 @@ let
|
|||||||
]
|
]
|
||||||
++ (lib.optional configSupportsZfs "zfs")
|
++ (lib.optional configSupportsZfs "zfs")
|
||||||
++ cfg.extraRootModules;
|
++ cfg.extraRootModules;
|
||||||
kernel = pkgs.aggregateModules (
|
|
||||||
[
|
|
||||||
cfg.kernelPackages.kernel
|
|
||||||
]
|
|
||||||
++ lib.optional (cfg.kernelPackages.kernel ? modules) cfg.kernelPackages.kernel.modules
|
|
||||||
++ lib.optional (
|
|
||||||
lib.elem "zfs" cfg.extraRootModules || configSupportsZfs
|
|
||||||
) cfg.kernelPackages.${config.boot.zfs.package.kernelModuleAttribute}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
// (
|
||||||
|
if diskoLib.vmToolsSupportsKernelModules pkgs then
|
||||||
|
{
|
||||||
|
kernel = cfg.kernelPackages.kernel;
|
||||||
|
kernelModules = modulesTree;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
kernel = modulesTree;
|
||||||
|
}
|
||||||
|
)
|
||||||
// lib.optionalAttrs (diskoLib.vmToolsSupportsCustomQemu lib) {
|
// lib.optionalAttrs (diskoLib.vmToolsSupportsCustomQemu lib) {
|
||||||
customQemu = cfg.qemu;
|
customQemu = cfg.qemu;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user