Unverified Commit 4cec81a9 authored by Martin Weinelt's avatar Martin Weinelt Committed by GitHub
Browse files

Revert "modules/virtualisation: add shared options, merge various diskSize options" (#340894)

Breaks evaluation of all nixos tests, and is therefore a channel blocker.
parent 757e0a34
Loading
Loading
Loading
Loading
+106 −143
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";
  virtualisationOptions = import ../../../modules/virtualisation/virtualisation-options.nix;

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

in {

  imports = [ ../../../modules/virtualisation/amazon-image.nix ];

  # 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 {
@@ -67,23 +41,23 @@ 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.virtualisation.diskSize = lib.mkDefault (3 * 1024);
  config.virtualisation.diskSizeAutoSupported = !config.ec2.zfs.enable;

  config.system.build.amazonImage =
    let
      configFile = pkgs.writeText "configuration.nix" ''
  config.system.build.amazonImage = let
    configFile = pkgs.writeText "configuration.nix"
      ''
        { modulesPath, ... }: {
          imports = [ "''${modulesPath}/virtualisation/amazon-image.nix" ];
          ${optionalString config.ec2.efi ''
@@ -97,19 +71,14 @@ 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 = config.virtualisation.diskSize;
      rootSize = cfg.sizeMB;
      rootPoolProperties = {
        ashift = 12;
        autoexpand = "on";
@@ -150,19 +119,14 @@ 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";

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

      postVM = ''
        extension=''${diskImage##*.}
@@ -190,8 +154,7 @@ 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 ];
}
+18 −36
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;
  cfg = config.openstackImage;
  imageBootMode = if config.openstack.efi then "uefi" else "legacy-bios";
  virtualisationOptions = import ../../../modules/virtualisation/virtualisation-options.nix;
in
{
  imports = [
    ../../../modules/virtualisation/openstack-config.nix
    virtualisationOptions.diskSize
    (lib.mkRenamedOptionModuleWith {
      sinceRelease = 2411;
      from = [
        "virtualisation"
        "openstackImage"
        "sizeMB"
      ];
      to = [
        "virtualisation"
        "diskSize"
      ];
    })

  ] ++ (lib.optional copyChannel ../../../modules/installer/cd-dvd/channel.nix);


  options.openstackImage = {
    name = mkOption {
      type = types.str;
@@ -41,15 +22,18 @@ in

    ramMB = mkOption {
      type = types.int;
      default = (3 * 1024);
      default = 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";
    };
@@ -70,15 +54,13 @@ in
      };
    };

    virtualisation.diskSize = lib.mkDefault (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;
@@ -89,7 +71,7 @@ in

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

let
  keysDirectory = "/var/keys";
@@ -20,19 +15,6 @@ in
  imports = [
    ../virtualisation/qemu-vm.nix

    (lib.mkRenamedOptionModuleWith {
      sinceRelease = 2411;
      from = [
        "virtualisation"
        "darwin-builder"
        "diskSize"
      ];
      to = [
        "virtualisation"
        "diskSize"
      ];
    })

    # Avoid a dependency on stateVersion
    {
      disabledModules = [
@@ -41,16 +23,17 @@ in
      ];
      # swraid's default depends on stateVersion
      config.boot.swraid.enable = false;
      options.boot.isContainer = lib.mkOption {
        default = false;
        internal = true;
      };
      options.boot.isContainer = lib.mkOption { default = false; internal = true; };
    }
  ];

  options.virtualisation.description = "The maximum disk space allocated to the runner in megabytes";

  options.virtualisation.darwin-builder = with lib; {
    diskSize = mkOption {
      default = 20 * 1024;
      type = types.int;
      example = 30720;
      description = "The maximum disk space allocated to the runner in MB";
    };
    memorySize = mkOption {
      default = 3 * 1024;
      type = types.int;
@@ -175,20 +158,13 @@ in
        script = hostPkgs.writeShellScriptBin "create-builder" (
          ''
            set -euo pipefail
          ''
          +
          '' +
          # When running as non-interactively as part of a DarwinConfiguration the working directory
          # must be set to a writeable directory.
            (
              if cfg.workingDirectory != "." then
                ''
        (if cfg.workingDirectory != "." then ''
          ${hostPkgs.coreutils}/bin/mkdir --parent "${cfg.workingDirectory}"
          cd "${cfg.workingDirectory}"
                ''
              else
                ""
            )
          + ''
        '' else "") + ''
          KEYS="''${KEYS:-./keys}"
          ${hostPkgs.coreutils}/bin/mkdir --parent "''${KEYS}"
          PRIVATE_KEY="''${KEYS}/${user}_${keyType}"
@@ -201,8 +177,7 @@ in
            (set -x; sudo --reset-timestamp ${installCredentials} "''${KEYS}")
          fi
          KEYS="$(${hostPkgs.nix}/bin/nix-store --add "$KEYS")" ${lib.getExe config.system.build.vm}
          ''
        );
        '');

      in
      script.overrideAttrs (old: {
@@ -248,16 +223,12 @@ in
    '';

    virtualisation = {
      diskSize = lib.mkDefault (20 * 1024);
      diskSize = cfg.diskSize;

      memorySize = cfg.memorySize;

      forwardPorts = [
        {
          from = "host";
          guest.port = 22;
          host.port = cfg.hostPort;
        }
        { from = "host"; guest.port = 22; host.port = cfg.hostPort; }
      ];

      # Disable graphics for the builder since users will likely want to run it
+13 −31
Original line number Diff line number Diff line
{
  config,
  lib,
  pkgs,
  ...
}:
{ config, lib, pkgs, ... }:

with lib;
let
  cfg = config.virtualisation.azureImage;
  virtualisationOptions = import ./virtualisation-options.nix;
in
{
  imports = [
    ./azure-common.nix
    virtualisationOptions.diskSize
    (lib.mkRenamedOptionModuleWith {
      sinceRelease = 2411;
      from = [
        "virtualisation"
        "azureImage"
        "diskSize"
      ];
      to = [
        "virtualisation"
        "diskSize"
      ];
    })
  ];
  imports = [ ./azure-common.nix ];

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

    vmGeneration = mkOption {
      type =
        with types;
        enum [
          "v1"
          "v2"
        ];
      type = with types; enum [ "v1" "v2" ];
      default = "v1";
      description = ''
        VM Generation to use.
@@ -74,8 +57,7 @@ in
      bootSize = "${toString cfg.bootSize}M";
      partitionTableType = if cfg.vmGeneration == "v2" then "efi" else "legacy";

      inherit (cfg) contents;
      inherit (config.virtualisation) diskSize;
      inherit (cfg) diskSize contents;
      inherit config lib pkgs;
    };
  };
+26 −49
Original line number Diff line number Diff line
{
  config,
  lib,
  pkgs,
  ...
}:
{ config, lib, pkgs, ... }:

with lib;
let
  cfg = config.virtualisation.digitalOceanImage;
  virtualisationOptions = import ./virtualisation-options.nix;
in
{

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

  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;
@@ -43,10 +31,7 @@ in
    };

    virtualisation.digitalOceanImage.compressionMethod = mkOption {
      type = types.enum [
        "gzip"
        "bzip2"
      ];
      type = types.enum [ "gzip" "bzip2" ];
      default = "gzip";
      example = "bzip2";
      description = ''
@@ -59,35 +44,27 @@ 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 (config.virtualisation) diskSize;
      configFile = if cfg.configFile == null
        then config.virtualisation.digitalOcean.defaultConfigFile
        else cfg.configFile;
      inherit (cfg) diskSize;
      inherit config lib pkgs;
    };

  };

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

}
Loading