Skip to content

Commit 4cec81a

Browse files
authored
Revert "modules/virtualisation: add shared options, merge various diskSize options" (#340894)
Breaks evaluation of all nixos tests, and is therefore a channel blocker.
1 parent 757e0a3 commit 4cec81a

15 files changed

+1297
-1763
lines changed
+106-143
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,24 @@
1-
{
2-
config,
3-
lib,
4-
pkgs,
5-
...
6-
}:
1+
{ config, lib, pkgs, ... }:
72

83
let
9-
inherit (lib)
10-
mkOption
11-
optionalString
12-
types
13-
versionAtLeast
14-
;
4+
inherit (lib) mkOption optionalString types versionAtLeast;
155
inherit (lib.options) literalExpression;
166
cfg = config.amazonImage;
177
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 ];
3812

3913
# Amazon recommends setting this to the highest possible value for a good EBS
4014
# experience, which prior to 4.15 was 255.
4115
# https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/nvme-ebs-volumes.html#timeout-nvme-ebs-volumes
4216
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}" ];
4822

4923
options.amazonImage = {
5024
name = mkOption {
@@ -60,30 +34,30 @@ in
6034
}
6135
]
6236
'';
63-
default = [ ];
37+
default = [];
6438
description = ''
6539
This option lists files to be copied to fixed locations in the
6640
generated image. Glob patterns work.
6741
'';
6842
};
6943

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+
7051
format = mkOption {
71-
type = types.enum [
72-
"raw"
73-
"qcow2"
74-
"vpc"
75-
];
52+
type = types.enum [ "raw" "qcow2" "vpc" ];
7653
default = "vpc";
7754
description = "The image format to output";
7855
};
7956
};
8057

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+
''
8761
{ modulesPath, ... }: {
8862
imports = [ "''${modulesPath}/virtualisation/amazon-image.nix" ];
8963
${optionalString config.ec2.efi ''
@@ -96,102 +70,91 @@ in
9670
}
9771
'';
9872

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;
15178

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";
19285
};
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;
195158

196159
meta.maintainers = with lib.maintainers; [ arianvp ];
197160
}

nixos/maintainers/scripts/openstack/openstack-image-zfs.nix

+18-36
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,18 @@
11
# nix-build '<nixpkgs/nixos>' -A config.system.build.openstackImage --arg configuration "{ imports = [ ./nixos/maintainers/scripts/openstack/openstack-image.nix ]; }"
22

3-
{
4-
config,
5-
lib,
6-
pkgs,
7-
...
8-
}:
3+
{ config, lib, pkgs, ... }:
94
let
105
inherit (lib) mkOption types;
116
copyChannel = true;
127
cfg = config.openstackImage;
138
imageBootMode = if config.openstack.efi then "uefi" else "legacy-bios";
14-
virtualisationOptions = import ../../../modules/virtualisation/virtualisation-options.nix;
159
in
1610
{
1711
imports = [
1812
../../../modules/virtualisation/openstack-config.nix
19-
virtualisationOptions.diskSize
20-
(lib.mkRenamedOptionModuleWith {
21-
sinceRelease = 2411;
22-
from = [
23-
"virtualisation"
24-
"openstackImage"
25-
"sizeMB"
26-
];
27-
to = [
28-
"virtualisation"
29-
"diskSize"
30-
];
31-
})
32-
3313
] ++ (lib.optional copyChannel ../../../modules/installer/cd-dvd/channel.nix);
3414

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

4223
ramMB = mkOption {
4324
type = types.int;
44-
default = (3 * 1024);
25+
default = 1024;
4526
description = "RAM allocation for build VM";
4627
};
4728

29+
sizeMB = mkOption {
30+
type = types.int;
31+
default = 8192;
32+
description = "The size in MB of the image";
33+
};
34+
4835
format = mkOption {
49-
type = types.enum [
50-
"raw"
51-
"qcow2"
52-
];
36+
type = types.enum [ "raw" "qcow2" ];
5337
default = "qcow2";
5438
description = "The image format to output";
5539
};
@@ -70,26 +54,24 @@ in
7054
};
7155
};
7256

73-
virtualisation.diskSize = lib.mkDefault (8 * 1024);
74-
virtualisation.diskSizeAutoSupported = false;
75-
7657
system.build.openstackImage = import ../../../lib/make-single-disk-zfs-image.nix {
7758
inherit lib config;
7859
inherit (cfg) contents format name;
7960
pkgs = import ../../../.. { inherit (pkgs) system; }; # ensure we use the regular qemu-kvm package
8061

81-
configFile = pkgs.writeText "configuration.nix" ''
82-
{ modulesPath, ... }: {
83-
imports = [ "''${modulesPath}/virtualisation/openstack-config.nix" ];
84-
openstack.zfs.enable = true;
85-
}
86-
'';
62+
configFile = pkgs.writeText "configuration.nix"
63+
''
64+
{ modulesPath, ... }: {
65+
imports = [ "''${modulesPath}/virtualisation/openstack-config.nix" ];
66+
openstack.zfs.enable = true;
67+
}
68+
'';
8769

8870
includeChannel = copyChannel;
8971

9072
bootSize = 1000;
9173
memSize = cfg.ramMB;
92-
rootSize = config.virtualisation.diskSize;
74+
rootSize = cfg.sizeMB;
9375
rootPoolProperties = {
9476
ashift = 12;
9577
autoexpand = "on";

0 commit comments

Comments
 (0)