virtualisation-options: init

see header comment in virtualisation-options.nix
This commit is contained in:
phaer 2024-08-30 13:24:22 +02:00
parent 04fadac429
commit 39df221e77
2 changed files with 66 additions and 8 deletions

View File

@ -325,11 +325,15 @@ let
OVMF = cfg.efi.OVMF;
};
virtualisationOptions = import ./virtualisation-options.nix;
in
{
imports = [
./virtualisation-options.nix
../profiles/qemu-guest.nix
virtualisationOptions.diskSize
(mkRenamedOptionModule
[
"virtualisation"
@ -385,14 +389,6 @@ in
'';
};
virtualisation.diskSize = mkOption {
type = types.ints.positive;
default = 1024;
description = ''
The disk size in megabytes of the virtual machine.
'';
};
virtualisation.diskImage = mkOption {
type = types.nullOr types.str;
default = "./${config.system.name}.qcow2";
@ -1238,6 +1234,8 @@ in
# override by setting `virtualisation.fileSystems = lib.mkForce { };`.
fileSystems = lib.mkIf (cfg.fileSystems != { }) (mkVMOverride cfg.fileSystems);
virtualisation.diskSizeAutoSupported = false;
virtualisation.fileSystems =
let
mkSharedDir = tag: share: {

View File

@ -0,0 +1,60 @@
# This modules declares shared options for virtual machines,
# containers and anything else in `virtualisation`.
#
# This is useful to declare e.g. defaults for
# `virtualisation.diskSize` once, while building multiple
# different image formats of a NixOS configuration.
#
# Additional options can be migrated over time from
# `modules/virtualisation/qemu-vm.nix` and others.
# Please keep defaults and descriptions here generic
# and independent of i.e. hypervisor-specific notes
# and defaults where.
# Those can be added in the consuming modules where needed.
# needed.
let
_file = ./virtualisation-options.nix;
key = _file;
in
{
diskSize =
{ lib, config, ... }:
let
t = lib.types;
in
{
inherit _file key;
options = {
virtualisation.diskSizeAutoSupported = lib.mkOption {
type = t.bool;
default = true;
description = ''
Whether the current image builder or vm runner supports `virtualisation.diskSize = "auto".`
'';
internal = true;
};
virtualisation.diskSize = lib.mkOption {
type = t.either (t.enum [ "auto" ]) t.ints.positive;
default = "auto";
description = ''
The disk size in megabytes of the virtual machine.
'';
};
};
config =
let
inherit (config.virtualisation) diskSize diskSizeAutoSupported;
in
{
assertions = [
{
assertion = diskSize != "auto" || diskSizeAutoSupported;
message = "Setting virtualisation.diskSize to `auto` is not supported by the current image build or vm runner; use an explicit size.";
}
];
};
};
}