Commit c6da9ef3 authored by phaer's avatar phaer
Browse files

modules/virtualisation: add unified diskSize opt

parent 6071ee8e
Loading
Loading
Loading
Loading
+22 −12
Original line number Diff line number Diff line
@@ -15,11 +15,23 @@ let
  inherit (lib.options) literalExpression;
  cfg = config.amazonImage;
  amiBootMode = if config.ec2.efi then "uefi" else "legacy-bios";

in
{

  imports = [ ../../../modules/virtualisation/amazon-image.nix ];
  imports = [
    ../../../modules/virtualisation/amazon-image.nix
    ../../../modules/virtualisation/disk-size-option.nix
    (lib.mkRenamedOptionModuleWith {
      sinceRelease = 2411;
      from = [
        "amazonImage"
        "sizeMB"
      ];
      to = [
        "virtualisation"
        "diskSize"
      ];
    })
  ];

  # Amazon recommends setting this to the highest possible value for a good EBS
  # experience, which prior to 4.15 was 255.
@@ -52,13 +64,6 @@ in
      '';
    };

    sizeMB = mkOption {
      type = with types; either (enum [ "auto" ]) int;
      default = 3072;
      example = 8192;
      description = "The size in MB of the image";
    };

    format = mkOption {
      type = types.enum [
        "raw"
@@ -70,6 +75,11 @@ in
    };
  };

  # Use a priority just below mkOptionDefault (1500) instead of lib.mkDefault
  # to avoid breaking existing configs using that.
  config.virtualisation.diskSize = lib.mkOverride 1490 (3 * 1024);
  config.virtualisation.diskSizeAutoSupported = !config.ec2.zfs.enable;

  config.system.build.amazonImage =
    let
      configFile = pkgs.writeText "configuration.nix" ''
@@ -98,7 +108,7 @@ in

        bootSize = 1000; # 1G is the minimum EBS volume

        rootSize = cfg.sizeMB;
        rootSize = config.virtualisation.diskSize;
        rootPoolProperties = {
          ashift = 12;
          autoexpand = "on";
@@ -151,7 +161,7 @@ in
        fsType = "ext4";
        partitionTableType = if config.ec2.efi then "efi" else "legacy+gpt";

        diskSize = cfg.sizeMB;
        inherit (config.virtualisation) diskSize;

        postVM = ''
           extension=''${diskImage##*.}
+19 −8
Original line number Diff line number Diff line
@@ -15,6 +15,18 @@ in
{
  imports = [
    ../../../modules/virtualisation/openstack-config.nix
    ../../../modules/virtualisation/disk-size-option.nix
    (lib.mkRenamedOptionModuleWith {
      sinceRelease = 2411;
      from = [
        "openstackImage"
        "sizeMB"
      ];
      to = [
        "virtualisation"
        "diskSize"
      ];
    })
  ] ++ (lib.optional copyChannel ../../../modules/installer/cd-dvd/channel.nix);

  options.openstackImage = {
@@ -26,16 +38,10 @@ in

    ramMB = mkOption {
      type = types.int;
      default = 1024;
      default = (3 * 1024);
      description = "RAM allocation for build VM";
    };

    sizeMB = mkOption {
      type = types.int;
      default = 8192;
      description = "The size in MB of the image";
    };

    format = mkOption {
      type = types.enum [
        "raw"
@@ -61,6 +67,11 @@ in
      };
    };

    # Use a priority just below mkOptionDefault (1500) instead of lib.mkDefault
    # to avoid breaking existing configs using that.
    virtualisation.diskSize = lib.mkOverride 1490 (8 * 1024);
    virtualisation.diskSizeAutoSupported = false;

    system.build.openstackImage = import ../../../lib/make-single-disk-zfs-image.nix {
      inherit lib config;
      inherit (cfg) contents format name;
@@ -77,7 +88,7 @@ in

      bootSize = 1000;
      memSize = cfg.ramMB;
      rootSize = cfg.sizeMB;
      rootSize = config.virtualisation.diskSize;
      rootPoolProperties = {
        ashift = 12;
        autoexpand = "on";
+18 −11
Original line number Diff line number Diff line
@@ -10,18 +10,24 @@ let
  cfg = config.virtualisation.azureImage;
in
{
  imports = [ ./azure-common.nix ];
  imports = [
    ./azure-common.nix
    ./disk-size-option.nix
    (lib.mkRenamedOptionModuleWith {
      sinceRelease = 2411;
      from = [
        "virtualisation"
        "azureImage"
        "diskSize"
      ];
      to = [
        "virtualisation"
        "diskSize"
      ];
    })
  ];

  options.virtualisation.azureImage = {
    diskSize = mkOption {
      type = with types; either (enum [ "auto" ]) int;
      default = "auto";
      example = 2048;
      description = ''
        Size of disk image. Unit is MB.
      '';
    };

    bootSize = mkOption {
      type = types.int;
      default = 256;
@@ -67,7 +73,8 @@ in
      bootSize = "${toString cfg.bootSize}M";
      partitionTableType = if cfg.vmGeneration == "v2" then "efi" else "legacy";

      inherit (cfg) diskSize contents;
      inherit (cfg) contents;
      inherit (config.virtualisation) diskSize;
      inherit config lib pkgs;
    };
  };
+17 −12
Original line number Diff line number Diff line
@@ -11,18 +11,24 @@ let
in
{

  imports = [ ./digital-ocean-config.nix ];
  imports = [
    ./digital-ocean-config.nix
    ./disk-size-option.nix
    (lib.mkRenamedOptionModuleWith {
      sinceRelease = 2411;
      from = [
        "virtualisation"
        "digitalOceanImage"
        "diskSize"
      ];
      to = [
        "virtualisation"
        "diskSize"
      ];
    })
  ];

  options = {
    virtualisation.digitalOceanImage.diskSize = mkOption {
      type = with types; either (enum [ "auto" ]) int;
      default = "auto";
      example = 4096;
      description = ''
        Size of disk image. Unit is MB.
      '';
    };

    virtualisation.digitalOceanImage.configFile = mkOption {
      type = with types; nullOr path;
      default = null;
@@ -52,7 +58,6 @@ in

  #### implementation
  config = {

    system.build.digitalOceanImage = import ../../lib/make-disk-image.nix {
      name = "digital-ocean-image";
      format = "qcow2";
@@ -73,7 +78,7 @@ in
          config.virtualisation.digitalOcean.defaultConfigFile
        else
          cfg.configFile;
      inherit (cfg) diskSize;
      inherit (config.virtualisation) diskSize;
      inherit config lib pkgs;
    };

+38 −0
Original line number Diff line number Diff line
{ lib, config, ... }:
let
  t = lib.types;
in
{
  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 = if config.virtualisation.diskSizeAutoSupported then "auto" else 1024;
      defaultText = "\"auto\" if diskSizeAutoSupported, else 1024";
      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.";
        }
      ];
    };
}
Loading