1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6 cfg = config.amazonImage;
7in {
8
9 imports = [ ../../../modules/virtualisation/amazon-image.nix ];
10
11 options.amazonImage = {
12 name = mkOption {
13 type = types.str;
14 description = "The name of the generated derivation";
15 default = "nixos-disk-image";
16 };
17
18 contents = mkOption {
19 example = literalExample ''
20 [ { source = pkgs.memtest86 + "/memtest.bin";
21 target = "boot/memtest.bin";
22 }
23 ]
24 '';
25 default = [];
26 description = ''
27 This option lists files to be copied to fixed locations in the
28 generated image. Glob patterns work.
29 '';
30 };
31
32 sizeMB = mkOption {
33 type = types.int;
34 default = if config.ec2.hvm then 2048 else 8192;
35 description = "The size in MB of the image";
36 };
37
38 format = mkOption {
39 type = types.enum [ "raw" "qcow2" "vpc" ];
40 default = "qcow2";
41 description = "The image format to output";
42 };
43 };
44
45 config.system.build.amazonImage = import ../../../lib/make-disk-image.nix {
46 inherit lib config;
47 inherit (cfg) contents format name;
48 pkgs = import ../../../.. { inherit (pkgs) system; }; # ensure we use the regular qemu-kvm package
49 partitionTableType = if config.ec2.hvm then "legacy" else "none";
50 diskSize = cfg.sizeMB;
51 configFile = pkgs.writeText "configuration.nix"
52 ''
53 {
54 imports = [ <nixpkgs/nixos/modules/virtualisation/amazon-image.nix> ];
55 ${optionalString config.ec2.hvm ''
56 ec2.hvm = true;
57 ''}
58 }
59 '';
60 };
61}