|
1 |
| -{ |
2 |
| - config, |
3 |
| - lib, |
4 |
| - pkgs, |
5 |
| - ... |
6 |
| -}: |
| 1 | +{ config, lib, pkgs, ... }: |
7 | 2 |
|
8 | 3 | let
|
9 |
| - inherit (lib) |
10 |
| - mkOption |
11 |
| - optionalString |
12 |
| - types |
13 |
| - versionAtLeast |
14 |
| - ; |
| 4 | + inherit (lib) mkOption optionalString types versionAtLeast; |
15 | 5 | inherit (lib.options) literalExpression;
|
16 | 6 | cfg = config.amazonImage;
|
17 | 7 | amiBootMode = if config.ec2.efi then "uefi" else "legacy-bios";
|
18 |
| - virtualisationOptions = import ../../../modules/virtualisation/virtualisation-options.nix; |
19 |
| - |
20 |
| -in |
21 |
| -{ |
22 |
| - imports = [ |
23 |
| - ../../../modules/virtualisation/amazon-image.nix |
24 |
| - virtualisationOptions.diskSize |
25 |
| - (lib.mkRenamedOptionModuleWith { |
26 |
| - sinceRelease = 2411; |
27 |
| - from = [ |
28 |
| - "virtualisation" |
29 |
| - "amazonImage" |
30 |
| - "sizeMB" |
31 |
| - ]; |
32 |
| - to = [ |
33 |
| - "virtualisation" |
34 |
| - "diskSize" |
35 |
| - ]; |
36 |
| - }) |
37 |
| - ]; |
| 8 | + |
| 9 | +in { |
| 10 | + |
| 11 | + imports = [ ../../../modules/virtualisation/amazon-image.nix ]; |
38 | 12 |
|
39 | 13 | # Amazon recommends setting this to the highest possible value for a good EBS
|
40 | 14 | # experience, which prior to 4.15 was 255.
|
41 | 15 | # https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/nvme-ebs-volumes.html#timeout-nvme-ebs-volumes
|
42 | 16 | config.boot.kernelParams =
|
43 |
| - let |
44 |
| - timeout = |
45 |
| - if versionAtLeast config.boot.kernelPackages.kernel.version "4.15" then "4294967295" else "255"; |
46 |
| - in |
47 |
| - [ "nvme_core.io_timeout=${timeout}" ]; |
| 17 | + let timeout = |
| 18 | + if versionAtLeast config.boot.kernelPackages.kernel.version "4.15" |
| 19 | + then "4294967295" |
| 20 | + else "255"; |
| 21 | + in [ "nvme_core.io_timeout=${timeout}" ]; |
48 | 22 |
|
49 | 23 | options.amazonImage = {
|
50 | 24 | name = mkOption {
|
|
60 | 34 | }
|
61 | 35 | ]
|
62 | 36 | '';
|
63 |
| - default = [ ]; |
| 37 | + default = []; |
64 | 38 | description = ''
|
65 | 39 | This option lists files to be copied to fixed locations in the
|
66 | 40 | generated image. Glob patterns work.
|
67 | 41 | '';
|
68 | 42 | };
|
69 | 43 |
|
| 44 | + sizeMB = mkOption { |
| 45 | + type = with types; either (enum [ "auto" ]) int; |
| 46 | + default = 3072; |
| 47 | + example = 8192; |
| 48 | + description = "The size in MB of the image"; |
| 49 | + }; |
| 50 | + |
70 | 51 | format = mkOption {
|
71 |
| - type = types.enum [ |
72 |
| - "raw" |
73 |
| - "qcow2" |
74 |
| - "vpc" |
75 |
| - ]; |
| 52 | + type = types.enum [ "raw" "qcow2" "vpc" ]; |
76 | 53 | default = "vpc";
|
77 | 54 | description = "The image format to output";
|
78 | 55 | };
|
79 | 56 | };
|
80 | 57 |
|
81 |
| - config.virtualisation.diskSize = lib.mkDefault (3 * 1024); |
82 |
| - config.virtualisation.diskSizeAutoSupported = !config.ec2.zfs.enable; |
83 |
| - |
84 |
| - config.system.build.amazonImage = |
85 |
| - let |
86 |
| - configFile = pkgs.writeText "configuration.nix" '' |
| 58 | + config.system.build.amazonImage = let |
| 59 | + configFile = pkgs.writeText "configuration.nix" |
| 60 | + '' |
87 | 61 | { modulesPath, ... }: {
|
88 | 62 | imports = [ "''${modulesPath}/virtualisation/amazon-image.nix" ];
|
89 | 63 | ${optionalString config.ec2.efi ''
|
|
96 | 70 | }
|
97 | 71 | '';
|
98 | 72 |
|
99 |
| - zfsBuilder = import ../../../lib/make-multi-disk-zfs-image.nix { |
100 |
| - inherit |
101 |
| - lib |
102 |
| - config |
103 |
| - configFile |
104 |
| - pkgs |
105 |
| - ; |
106 |
| - inherit (cfg) contents format name; |
107 |
| - |
108 |
| - includeChannel = true; |
109 |
| - |
110 |
| - bootSize = 1000; # 1G is the minimum EBS volume |
111 |
| - |
112 |
| - rootSize = config.virtualisation.diskSize; |
113 |
| - rootPoolProperties = { |
114 |
| - ashift = 12; |
115 |
| - autoexpand = "on"; |
116 |
| - }; |
117 |
| - |
118 |
| - datasets = config.ec2.zfs.datasets; |
119 |
| - |
120 |
| - postVM = '' |
121 |
| - extension=''${rootDiskImage##*.} |
122 |
| - friendlyName=$out/${cfg.name} |
123 |
| - rootDisk="$friendlyName.root.$extension" |
124 |
| - bootDisk="$friendlyName.boot.$extension" |
125 |
| - mv "$rootDiskImage" "$rootDisk" |
126 |
| - mv "$bootDiskImage" "$bootDisk" |
127 |
| -
|
128 |
| - mkdir -p $out/nix-support |
129 |
| - echo "file ${cfg.format} $bootDisk" >> $out/nix-support/hydra-build-products |
130 |
| - echo "file ${cfg.format} $rootDisk" >> $out/nix-support/hydra-build-products |
131 |
| -
|
132 |
| - ${pkgs.jq}/bin/jq -n \ |
133 |
| - --arg system_label ${lib.escapeShellArg config.system.nixos.label} \ |
134 |
| - --arg system ${lib.escapeShellArg pkgs.stdenv.hostPlatform.system} \ |
135 |
| - --arg root_logical_bytes "$(${pkgs.qemu_kvm}/bin/qemu-img info --output json "$rootDisk" | ${pkgs.jq}/bin/jq '."virtual-size"')" \ |
136 |
| - --arg boot_logical_bytes "$(${pkgs.qemu_kvm}/bin/qemu-img info --output json "$bootDisk" | ${pkgs.jq}/bin/jq '."virtual-size"')" \ |
137 |
| - --arg boot_mode "${amiBootMode}" \ |
138 |
| - --arg root "$rootDisk" \ |
139 |
| - --arg boot "$bootDisk" \ |
140 |
| - '{} |
141 |
| - | .label = $system_label |
142 |
| - | .boot_mode = $boot_mode |
143 |
| - | .system = $system |
144 |
| - | .disks.boot.logical_bytes = $boot_logical_bytes |
145 |
| - | .disks.boot.file = $boot |
146 |
| - | .disks.root.logical_bytes = $root_logical_bytes |
147 |
| - | .disks.root.file = $root |
148 |
| - ' > $out/nix-support/image-info.json |
149 |
| - ''; |
150 |
| - }; |
| 73 | + zfsBuilder = import ../../../lib/make-multi-disk-zfs-image.nix { |
| 74 | + inherit lib config configFile pkgs; |
| 75 | + inherit (cfg) contents format name; |
| 76 | + |
| 77 | + includeChannel = true; |
151 | 78 |
|
152 |
| - extBuilder = import ../../../lib/make-disk-image.nix { |
153 |
| - inherit |
154 |
| - lib |
155 |
| - config |
156 |
| - configFile |
157 |
| - pkgs |
158 |
| - ; |
159 |
| - |
160 |
| - inherit (cfg) contents format name; |
161 |
| - |
162 |
| - fsType = "ext4"; |
163 |
| - partitionTableType = if config.ec2.efi then "efi" else "legacy+gpt"; |
164 |
| - |
165 |
| - inherit (config.virtualisation) diskSize; |
166 |
| - |
167 |
| - postVM = '' |
168 |
| - extension=''${diskImage##*.} |
169 |
| - friendlyName=$out/${cfg.name}.$extension |
170 |
| - mv "$diskImage" "$friendlyName" |
171 |
| - diskImage=$friendlyName |
172 |
| -
|
173 |
| - mkdir -p $out/nix-support |
174 |
| - echo "file ${cfg.format} $diskImage" >> $out/nix-support/hydra-build-products |
175 |
| -
|
176 |
| - ${pkgs.jq}/bin/jq -n \ |
177 |
| - --arg system_label ${lib.escapeShellArg config.system.nixos.label} \ |
178 |
| - --arg system ${lib.escapeShellArg pkgs.stdenv.hostPlatform.system} \ |
179 |
| - --arg logical_bytes "$(${pkgs.qemu_kvm}/bin/qemu-img info --output json "$diskImage" | ${pkgs.jq}/bin/jq '."virtual-size"')" \ |
180 |
| - --arg boot_mode "${amiBootMode}" \ |
181 |
| - --arg file "$diskImage" \ |
182 |
| - '{} |
183 |
| - | .label = $system_label |
184 |
| - | .boot_mode = $boot_mode |
185 |
| - | .system = $system |
186 |
| - | .logical_bytes = $logical_bytes |
187 |
| - | .file = $file |
188 |
| - | .disks.root.logical_bytes = $logical_bytes |
189 |
| - | .disks.root.file = $file |
190 |
| - ' > $out/nix-support/image-info.json |
191 |
| - ''; |
| 79 | + bootSize = 1000; # 1G is the minimum EBS volume |
| 80 | + |
| 81 | + rootSize = cfg.sizeMB; |
| 82 | + rootPoolProperties = { |
| 83 | + ashift = 12; |
| 84 | + autoexpand = "on"; |
192 | 85 | };
|
193 |
| - in |
194 |
| - if config.ec2.zfs.enable then zfsBuilder else extBuilder; |
| 86 | + |
| 87 | + datasets = config.ec2.zfs.datasets; |
| 88 | + |
| 89 | + postVM = '' |
| 90 | + extension=''${rootDiskImage##*.} |
| 91 | + friendlyName=$out/${cfg.name} |
| 92 | + rootDisk="$friendlyName.root.$extension" |
| 93 | + bootDisk="$friendlyName.boot.$extension" |
| 94 | + mv "$rootDiskImage" "$rootDisk" |
| 95 | + mv "$bootDiskImage" "$bootDisk" |
| 96 | +
|
| 97 | + mkdir -p $out/nix-support |
| 98 | + echo "file ${cfg.format} $bootDisk" >> $out/nix-support/hydra-build-products |
| 99 | + echo "file ${cfg.format} $rootDisk" >> $out/nix-support/hydra-build-products |
| 100 | +
|
| 101 | + ${pkgs.jq}/bin/jq -n \ |
| 102 | + --arg system_label ${lib.escapeShellArg config.system.nixos.label} \ |
| 103 | + --arg system ${lib.escapeShellArg pkgs.stdenv.hostPlatform.system} \ |
| 104 | + --arg root_logical_bytes "$(${pkgs.qemu_kvm}/bin/qemu-img info --output json "$rootDisk" | ${pkgs.jq}/bin/jq '."virtual-size"')" \ |
| 105 | + --arg boot_logical_bytes "$(${pkgs.qemu_kvm}/bin/qemu-img info --output json "$bootDisk" | ${pkgs.jq}/bin/jq '."virtual-size"')" \ |
| 106 | + --arg boot_mode "${amiBootMode}" \ |
| 107 | + --arg root "$rootDisk" \ |
| 108 | + --arg boot "$bootDisk" \ |
| 109 | + '{} |
| 110 | + | .label = $system_label |
| 111 | + | .boot_mode = $boot_mode |
| 112 | + | .system = $system |
| 113 | + | .disks.boot.logical_bytes = $boot_logical_bytes |
| 114 | + | .disks.boot.file = $boot |
| 115 | + | .disks.root.logical_bytes = $root_logical_bytes |
| 116 | + | .disks.root.file = $root |
| 117 | + ' > $out/nix-support/image-info.json |
| 118 | + ''; |
| 119 | + }; |
| 120 | + |
| 121 | + extBuilder = import ../../../lib/make-disk-image.nix { |
| 122 | + inherit lib config configFile pkgs; |
| 123 | + |
| 124 | + inherit (cfg) contents format name; |
| 125 | + |
| 126 | + fsType = "ext4"; |
| 127 | + partitionTableType = if config.ec2.efi then "efi" else "legacy+gpt"; |
| 128 | + |
| 129 | + diskSize = cfg.sizeMB; |
| 130 | + |
| 131 | + postVM = '' |
| 132 | + extension=''${diskImage##*.} |
| 133 | + friendlyName=$out/${cfg.name}.$extension |
| 134 | + mv "$diskImage" "$friendlyName" |
| 135 | + diskImage=$friendlyName |
| 136 | +
|
| 137 | + mkdir -p $out/nix-support |
| 138 | + echo "file ${cfg.format} $diskImage" >> $out/nix-support/hydra-build-products |
| 139 | +
|
| 140 | + ${pkgs.jq}/bin/jq -n \ |
| 141 | + --arg system_label ${lib.escapeShellArg config.system.nixos.label} \ |
| 142 | + --arg system ${lib.escapeShellArg pkgs.stdenv.hostPlatform.system} \ |
| 143 | + --arg logical_bytes "$(${pkgs.qemu_kvm}/bin/qemu-img info --output json "$diskImage" | ${pkgs.jq}/bin/jq '."virtual-size"')" \ |
| 144 | + --arg boot_mode "${amiBootMode}" \ |
| 145 | + --arg file "$diskImage" \ |
| 146 | + '{} |
| 147 | + | .label = $system_label |
| 148 | + | .boot_mode = $boot_mode |
| 149 | + | .system = $system |
| 150 | + | .logical_bytes = $logical_bytes |
| 151 | + | .file = $file |
| 152 | + | .disks.root.logical_bytes = $logical_bytes |
| 153 | + | .disks.root.file = $file |
| 154 | + ' > $out/nix-support/image-info.json |
| 155 | + ''; |
| 156 | + }; |
| 157 | + in if config.ec2.zfs.enable then zfsBuilder else extBuilder; |
195 | 158 |
|
196 | 159 | meta.maintainers = with lib.maintainers; [ arianvp ];
|
197 | 160 | }
|
0 commit comments