Skip to content

Commit

Permalink
Merge pull request #851 from nix-community/fix-eval-error-unexpected-…
Browse files Browse the repository at this point in the history
…argument-customQemu

disk-image: Fix "unexpected argument 'customQemu'" eval error
  • Loading branch information
phaer authored Oct 28, 2024
2 parents 89e458a + bba79f6 commit 3163b27
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 18 deletions.
21 changes: 15 additions & 6 deletions lib/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,13 @@ let
hexEscapeUdevSymlink "all0these@char#acters+_are-allow.ed"
=> "all0these@char#acters+_are-allow.ed"
*/
hexEscapeUdevSymlink = let
allowedChars = "[0-9A-Za-z#+-.:=@_/]";
charToHex = c: lib.toHexString (lib.strings.charToInt c);
in
lib.stringAsChars
(c: if lib.match allowedChars c != null || c == "" then c else "\\x" + charToHex c);
hexEscapeUdevSymlink =
let
allowedChars = "[0-9A-Za-z#+-.:=@_/]";
charToHex = c: lib.toHexString (lib.strings.charToInt c);
in
lib.stringAsChars
(c: if lib.match allowedChars c != null || c == "" then c else "\\x" + charToHex c);

/* get the index an item in a list
Expand Down Expand Up @@ -334,6 +335,14 @@ let
*/
packages = toplevel: toplevel._packages;

/* Checks whether nixpkgs is recent enough for vmTools to support the customQemu argument.
Returns false, which is technically incorrect, for a few commits on 2024-07-08, but we can't be more accurate.
vmToolsSupportsCustomQemu :: pkgs -> bool
*/
vmToolsSupportsCustomQemu = pkgs: lib.versionAtLeast pkgs.lib.version "24.11.20240709";

optionTypes = rec {
filename = lib.mkOptionType {
name = "filename";
Expand Down
22 changes: 13 additions & 9 deletions lib/make-disk-image.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,19 @@ let
checked = diskoCfg.checkScripts;

configSupportsZfs = config.boot.supportedFilesystems.zfs or false;
vmTools = pkgs.vmTools.override {
rootModules = [ "9p" "9pnet_virtio" "virtio_pci" "virtio_blk" ]
++ (lib.optional configSupportsZfs "zfs")
++ cfg.extraRootModules;
customQemu = cfg.qemu;
kernel = pkgs.aggregateModules
(with cfg.kernelPackages; [ kernel ]
++ lib.optional (lib.elem "zfs" cfg.extraRootModules || configSupportsZfs) zfs);
};
vmTools = pkgs.vmTools.override
{
rootModules = [ "9p" "9pnet_virtio" "virtio_pci" "virtio_blk" ]
++ (lib.optional configSupportsZfs "zfs")
++ cfg.extraRootModules;
kernel = pkgs.aggregateModules
(with cfg.kernelPackages; [ kernel ]
++ lib.optional (lib.elem "zfs" cfg.extraRootModules || configSupportsZfs) zfs);
}
// lib.optionalAttrs (diskoLib.vmToolsSupportsCustomQemu pkgs)
{
customQemu = cfg.qemu;
};
cleanedConfig = diskoLib.testLib.prepareDiskoConfig config diskoLib.testLib.devices;
systemToInstall = extendModules {
modules = [
Expand Down
20 changes: 17 additions & 3 deletions module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,17 @@ in
};

config = {
assertions = [
{
assertion = config.disko.imageBuilder.qemu != null -> diskoLib.vmToolsSupportsCustomQemu pkgs;
message = ''
You have set config.disko.imageBuild.qemu, but vmTools in your nixpkgs version "${lib.version}"
does not support overriding the qemu package with the customQemu option yet.
Please upgrade nixpkgs so that `lib.version` is at least "24.11.20240709".
'';
}
];

_module.args.diskoLib = import ./lib {
inherit lib;
rootMountPoint = config.disko.rootMountPoint;
Expand Down Expand Up @@ -226,8 +237,11 @@ in

# we need to specify the keys here, so we don't get an infinite recursion error
# Remember to add config keys here if they are added to types
fileSystems = lib.mkIf cfg.enableConfig cfg.devices._config.fileSystems or { };
boot = lib.mkIf cfg.enableConfig cfg.devices._config.boot or { };
swapDevices = lib.mkIf cfg.enableConfig cfg.devices._config.swapDevices or [ ];
fileSystems = lib.mkIf
cfg.enableConfig cfg.devices._config.fileSystems or { };
boot = lib.mkIf
cfg.enableConfig cfg.devices._config.boot or { };
swapDevices = lib.mkIf
cfg.enableConfig cfg.devices._config.swapDevices or [ ];
};
}

0 comments on commit 3163b27

Please sign in to comment.