mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-06-09 17:46:29 +09:00

This produced an unnecessarily infinitely deep config tree. The "cut off" option can be written to, but not read from. Being written to is important, because it allows users to conveniently define vmVariant config without having to check isVmVariant. There's a small chance that someone *reads* from vmVariant config in their normal config, and for them it will not be possible to evaluate with `nixos-rebuild build-vm` anymore. If this is a problem, we could perhaps make the vmVariant root appear instead of the `throw` error. This could also be done using mkOption apply.
77 lines
1.8 KiB
Nix
77 lines
1.8 KiB
Nix
{
|
|
config,
|
|
extendModules,
|
|
lib,
|
|
...
|
|
}:
|
|
let
|
|
|
|
inherit (lib)
|
|
mkOption
|
|
;
|
|
|
|
vmVariant = extendModules {
|
|
modules = [ ./qemu-vm.nix ];
|
|
};
|
|
|
|
vmVariantWithBootLoader = vmVariant.extendModules {
|
|
modules = [
|
|
(
|
|
{ config, ... }:
|
|
{
|
|
_file = "nixos/default.nix##vmWithBootLoader";
|
|
virtualisation.useBootLoader = true;
|
|
virtualisation.useEFIBoot =
|
|
config.boot.loader.systemd-boot.enable || config.boot.loader.efi.canTouchEfiVariables;
|
|
}
|
|
)
|
|
];
|
|
};
|
|
in
|
|
{
|
|
options = {
|
|
|
|
virtualisation.vmVariant = mkOption {
|
|
description = ''
|
|
Machine configuration to be added for the vm script produced by `nixos-rebuild build-vm`.
|
|
'';
|
|
inherit (vmVariant) type;
|
|
default = { };
|
|
visible = "shallow";
|
|
};
|
|
|
|
virtualisation.vmVariantWithBootLoader = mkOption {
|
|
description = ''
|
|
Machine configuration to be added for the vm script produced by `nixos-rebuild build-vm-with-bootloader`.
|
|
'';
|
|
inherit (vmVariantWithBootLoader) type;
|
|
default = { };
|
|
visible = "shallow";
|
|
};
|
|
|
|
};
|
|
|
|
config = {
|
|
|
|
system.build = {
|
|
vm = lib.mkDefault config.virtualisation.vmVariant.system.build.vm;
|
|
vmWithBootLoader = lib.mkDefault config.virtualisation.vmVariantWithBootLoader.system.build.vm;
|
|
};
|
|
|
|
virtualisation.vmVariant = {
|
|
options = {
|
|
virtualisation.vmVariant = lib.mkOption {
|
|
apply = _: throw "virtualisation.vmVariant*.virtualisation.vmVariant is not supported";
|
|
};
|
|
virtualisation.vmVariantWithBootLoader = lib.mkOption {
|
|
apply =
|
|
_: throw "virtualisation.vmVariant*.virtualisation.vmVariantWithBootloader is not supported";
|
|
};
|
|
};
|
|
};
|
|
|
|
};
|
|
|
|
# uses extendModules
|
|
meta.buildDocsInSandbox = false;
|
|
}
|