2015-09-27 20:01:43 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
2017-02-22 23:47:24 +00:00
|
|
|
let
|
|
|
|
cfg = config.amazonImage;
|
|
|
|
in {
|
2015-09-27 20:01:43 +01:00
|
|
|
|
2017-04-17 04:08:37 +01:00
|
|
|
imports = [ ../../../modules/virtualisation/amazon-image.nix ];
|
2015-09-27 20:01:43 +01:00
|
|
|
|
2018-05-09 15:15:16 +01:00
|
|
|
# Required to provide good EBS experience,
|
2018-05-02 16:13:13 +01:00
|
|
|
# https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/nvme-ebs-volumes.html#timeout-nvme-ebs-volumes
|
|
|
|
# TODO change value to 4294967295 when kernel is updated to 4.15 or later
|
|
|
|
config.boot.kernelParams = [ "nvme_core.io_timeout=255" ];
|
|
|
|
|
2017-02-22 23:47:24 +00:00
|
|
|
options.amazonImage = {
|
2017-10-23 21:22:16 +01:00
|
|
|
name = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
description = "The name of the generated derivation";
|
2019-05-31 20:19:18 +01:00
|
|
|
default = "nixos-amazon-image-${config.system.nixos.label}-${pkgs.stdenv.hostPlatform.system}";
|
2017-10-23 21:22:16 +01:00
|
|
|
};
|
|
|
|
|
2017-02-22 23:47:24 +00:00
|
|
|
contents = mkOption {
|
|
|
|
example = literalExample ''
|
|
|
|
[ { source = pkgs.memtest86 + "/memtest.bin";
|
|
|
|
target = "boot/memtest.bin";
|
|
|
|
}
|
|
|
|
]
|
|
|
|
'';
|
|
|
|
default = [];
|
|
|
|
description = ''
|
|
|
|
This option lists files to be copied to fixed locations in the
|
|
|
|
generated image. Glob patterns work.
|
|
|
|
'';
|
|
|
|
};
|
2017-08-10 22:40:21 +01:00
|
|
|
|
2017-08-11 02:57:38 +01:00
|
|
|
sizeMB = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = if config.ec2.hvm then 2048 else 8192;
|
|
|
|
description = "The size in MB of the image";
|
|
|
|
};
|
|
|
|
|
2017-08-10 22:40:21 +01:00
|
|
|
format = mkOption {
|
2017-08-10 23:57:26 +01:00
|
|
|
type = types.enum [ "raw" "qcow2" "vpc" ];
|
2019-05-31 18:21:24 +01:00
|
|
|
default = "vpc";
|
2017-08-10 22:40:21 +01:00
|
|
|
description = "The image format to output";
|
|
|
|
};
|
2017-02-22 23:47:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
config.system.build.amazonImage = import ../../../lib/make-disk-image.nix {
|
2016-03-30 20:48:12 +01:00
|
|
|
inherit lib config;
|
2017-10-23 21:22:16 +01:00
|
|
|
inherit (cfg) contents format name;
|
2016-03-30 20:48:12 +01:00
|
|
|
pkgs = import ../../../.. { inherit (pkgs) system; }; # ensure we use the regular qemu-kvm package
|
2019-05-25 10:53:15 +01:00
|
|
|
partitionTableType = if config.ec2.efi then "efi"
|
|
|
|
else if config.ec2.hvm then "legacy"
|
|
|
|
else "none";
|
2017-08-11 03:12:39 +01:00
|
|
|
diskSize = cfg.sizeMB;
|
2019-03-14 09:30:20 +00:00
|
|
|
fsType = "ext4";
|
2015-09-27 20:01:43 +01:00
|
|
|
configFile = pkgs.writeText "configuration.nix"
|
|
|
|
''
|
|
|
|
{
|
|
|
|
imports = [ <nixpkgs/nixos/modules/virtualisation/amazon-image.nix> ];
|
|
|
|
${optionalString config.ec2.hvm ''
|
|
|
|
ec2.hvm = true;
|
|
|
|
''}
|
2019-05-25 10:53:15 +01:00
|
|
|
${optionalString config.ec2.efi ''
|
|
|
|
ec2.efi = true;
|
|
|
|
''}
|
2015-09-27 20:01:43 +01:00
|
|
|
}
|
|
|
|
'';
|
2019-05-31 20:19:18 +01:00
|
|
|
postVM = ''
|
|
|
|
extension=''${diskImage##*.}
|
|
|
|
friendlyName=$out/${cfg.name}.$extension
|
|
|
|
mv "$diskImage" "$friendlyName"
|
|
|
|
diskImage=$friendlyName
|
|
|
|
|
|
|
|
mkdir -p $out/nix-support
|
|
|
|
echo "file ${cfg.format} $diskImage" >> $out/nix-support/hydra-build-products
|
2019-06-04 16:10:47 +01:00
|
|
|
|
|
|
|
${pkgs.jq}/bin/jq -n \
|
|
|
|
--arg label ${lib.escapeShellArg config.system.nixos.label} \
|
|
|
|
--arg system ${lib.escapeShellArg pkgs.stdenv.hostPlatform.system} \
|
|
|
|
--arg logical_bytes "$(${pkgs.qemu}/bin/qemu-img info --output json "$diskImage" | ${pkgs.jq}/bin/jq '."virtual-size"')" \
|
|
|
|
--arg file "$diskImage" \
|
|
|
|
'$ARGS.named' \
|
|
|
|
> $out/nix-support/image-info.json
|
2019-05-31 20:19:18 +01:00
|
|
|
'';
|
2015-09-27 20:01:43 +01:00
|
|
|
};
|
|
|
|
}
|