virtualisation-options: init
see header comment in virtualisation-options.nix
This commit is contained in:
@@ -325,11 +325,15 @@ let
|
|||||||
OVMF = cfg.efi.OVMF;
|
OVMF = cfg.efi.OVMF;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
virtualisationOptions = import ./virtualisation-options.nix;
|
||||||
|
|
||||||
in
|
in
|
||||||
|
|
||||||
{
|
{
|
||||||
imports = [
|
imports = [
|
||||||
|
./virtualisation-options.nix
|
||||||
../profiles/qemu-guest.nix
|
../profiles/qemu-guest.nix
|
||||||
|
virtualisationOptions.diskSize
|
||||||
(mkRenamedOptionModule
|
(mkRenamedOptionModule
|
||||||
[
|
[
|
||||||
"virtualisation"
|
"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 {
|
virtualisation.diskImage = mkOption {
|
||||||
type = types.nullOr types.str;
|
type = types.nullOr types.str;
|
||||||
default = "./${config.system.name}.qcow2";
|
default = "./${config.system.name}.qcow2";
|
||||||
@@ -1238,6 +1234,8 @@ in
|
|||||||
# override by setting `virtualisation.fileSystems = lib.mkForce { };`.
|
# override by setting `virtualisation.fileSystems = lib.mkForce { };`.
|
||||||
fileSystems = lib.mkIf (cfg.fileSystems != { }) (mkVMOverride cfg.fileSystems);
|
fileSystems = lib.mkIf (cfg.fileSystems != { }) (mkVMOverride cfg.fileSystems);
|
||||||
|
|
||||||
|
virtualisation.diskSizeAutoSupported = false;
|
||||||
|
|
||||||
virtualisation.fileSystems =
|
virtualisation.fileSystems =
|
||||||
let
|
let
|
||||||
mkSharedDir = tag: share: {
|
mkSharedDir = tag: share: {
|
||||||
|
|||||||
60
nixos/modules/virtualisation/virtualisation-options.nix
Normal file
60
nixos/modules/virtualisation/virtualisation-options.nix
Normal 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.";
|
||||||
|
}
|
||||||
|
];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user