Unverified Commit 2ba15d4f authored by Robert Hensing's avatar Robert Hensing Committed by GitHub
Browse files

modules/virtualisation: add shared options, merge various diskSize options (#341058)

parents 6385db14 c6da9ef3
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -192,3 +192,6 @@ ce21e97a1f20dee15da85c084f9d1148d84f853b

# percona: apply nixfmt
8d14fa2886fec877690c6d28cfcdba4503dbbcea

# nixos/virtualisation: format image-related files
88b285c01d84de82c0b2b052fd28eaf6709c2d26
+142 −106
Original line number Diff line number Diff line
{ config, lib, pkgs, ... }:
{
  config,
  lib,
  pkgs,
  ...
}:

let
  inherit (lib) mkOption optionalString types versionAtLeast;
  inherit (lib)
    mkOption
    optionalString
    types
    versionAtLeast
    ;
  inherit (lib.options) literalExpression;
  cfg = config.amazonImage;
  amiBootMode = if config.ec2.efi then "uefi" else "legacy-bios";

in {

  imports = [ ../../../modules/virtualisation/amazon-image.nix ];
in
{
  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.
  # https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/nvme-ebs-volumes.html#timeout-nvme-ebs-volumes
  config.boot.kernelParams =
    let timeout =
      if versionAtLeast config.boot.kernelPackages.kernel.version "4.15"
      then "4294967295"
      else  "255";
    in [ "nvme_core.io_timeout=${timeout}" ];
    let
      timeout =
        if versionAtLeast config.boot.kernelPackages.kernel.version "4.15" then "4294967295" else "255";
    in
    [ "nvme_core.io_timeout=${timeout}" ];

  options.amazonImage = {
    name = mkOption {
@@ -41,23 +64,25 @@ 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" "qcow2" "vpc" ];
      type = types.enum [
        "raw"
        "qcow2"
        "vpc"
      ];
      default = "vpc";
      description = "The image format to output";
    };
  };

  config.system.build.amazonImage = let
    configFile = pkgs.writeText "configuration.nix"
      ''
  # 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" ''
        { modulesPath, ... }: {
          imports = [ "''${modulesPath}/virtualisation/amazon-image.nix" ];
          ${optionalString config.ec2.efi ''
@@ -71,14 +96,19 @@ in {
      '';

      zfsBuilder = import ../../../lib/make-multi-disk-zfs-image.nix {
      inherit lib config configFile pkgs;
        inherit
          lib
          config
          configFile
          pkgs
          ;
        inherit (cfg) contents format name;

        includeChannel = true;

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

      rootSize = cfg.sizeMB;
        rootSize = config.virtualisation.diskSize;
        rootPoolProperties = {
          ashift = 12;
          autoexpand = "on";
@@ -119,14 +149,19 @@ in {
      };

      extBuilder = import ../../../lib/make-disk-image.nix {
      inherit lib config configFile pkgs;
        inherit
          lib
          config
          configFile
          pkgs
          ;

        inherit (cfg) contents format name;

        fsType = "ext4";
        partitionTableType = if config.ec2.efi then "efi" else "legacy+gpt";

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

        postVM = ''
           extension=''${diskImage##*.}
@@ -154,7 +189,8 @@ in {
             ' > $out/nix-support/image-info.json
        '';
      };
  in if config.ec2.zfs.enable then zfsBuilder else extBuilder;
    in
    if config.ec2.zfs.enable then zfsBuilder else extBuilder;

  meta.maintainers = with lib.maintainers; [ arianvp ];
}
+35 −18
Original line number Diff line number Diff line
# nix-build '<nixpkgs/nixos>' -A config.system.build.openstackImage --arg configuration "{ imports = [ ./nixos/maintainers/scripts/openstack/openstack-image.nix ]; }"

{ config, lib, pkgs, ... }:
{
  config,
  lib,
  pkgs,
  ...
}:
let
  inherit (lib) mkOption types;
  copyChannel = true;
@@ -10,9 +15,20 @@ 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 = {
    name = mkOption {
      type = types.str;
@@ -22,18 +38,15 @@ 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" "qcow2" ];
      type = types.enum [
        "raw"
        "qcow2"
      ];
      default = "qcow2";
      description = "The image format to output";
    };
@@ -54,13 +67,17 @@ 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;
      pkgs = import ../../../.. { inherit (pkgs) system; }; # ensure we use the regular qemu-kvm package

      configFile = pkgs.writeText "configuration.nix"
        ''
      configFile = pkgs.writeText "configuration.nix" ''
        { modulesPath, ... }: {
          imports = [ "''${modulesPath}/virtualisation/openstack-config.nix" ];
          openstack.zfs.enable = true;
@@ -71,7 +88,7 @@ in

      bootSize = 1000;
      memSize = cfg.ramMB;
      rootSize = cfg.sizeMB;
      rootSize = config.virtualisation.diskSize;
      rootPoolProperties = {
        ashift = 12;
        autoexpand = "on";
+30 −13
Original line number Diff line number Diff line
{ config, lib, pkgs, ... }:
{
  config,
  lib,
  pkgs,
  ...
}:

with lib;
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;
@@ -35,7 +46,12 @@ in
    };

    vmGeneration = mkOption {
      type = with types; enum [ "v1" "v2" ];
      type =
        with types;
        enum [
          "v1"
          "v2"
        ];
      default = "v1";
      description = ''
        VM Generation to use.
@@ -57,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;
    };
  };
+48 −26
Original line number Diff line number Diff line
{ config, lib, pkgs, ... }:
{
  config,
  lib,
  pkgs,
  ...
}:

with lib;
let
@@ -6,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;
@@ -31,7 +42,10 @@ in
    };

    virtualisation.digitalOceanImage.compressionMethod = mkOption {
      type = types.enum [ "gzip" "bzip2" ];
      type = types.enum [
        "gzip"
        "bzip2"
      ];
      default = "gzip";
      example = "bzip2";
      description = ''
@@ -44,27 +58,35 @@ in

  #### implementation
  config = {

    system.build.digitalOceanImage = import ../../lib/make-disk-image.nix {
      name = "digital-ocean-image";
      format = "qcow2";
      postVM = let
        compress = {
      postVM =
        let
          compress =
            {
              "gzip" = "${pkgs.gzip}/bin/gzip";
              "bzip2" = "${pkgs.bzip2}/bin/bzip2";
        }.${cfg.compressionMethod};
      in ''
            }
            .${cfg.compressionMethod};
        in
        ''
          ${compress} $diskImage
        '';
      configFile = if cfg.configFile == null
        then config.virtualisation.digitalOcean.defaultConfigFile
        else cfg.configFile;
      inherit (cfg) diskSize;
      configFile =
        if cfg.configFile == null then
          config.virtualisation.digitalOcean.defaultConfigFile
        else
          cfg.configFile;
      inherit (config.virtualisation) diskSize;
      inherit config lib pkgs;
    };

  };

  meta.maintainers = with maintainers; [ arianvp eamsden ];
  meta.maintainers = with maintainers; [
    arianvp
    eamsden
  ];

}
Loading