2024-09-05 12:14:16 +02:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
pkgs,
|
|
|
|
...
|
|
|
|
}:
|
2014-09-06 21:37:46 +02:00
|
|
|
|
|
|
|
with lib;
|
|
|
|
let
|
2019-11-18 12:39:18 -08:00
|
|
|
cfg = config.virtualisation.azureImage;
|
2024-09-05 13:06:25 +02:00
|
|
|
virtualisationOptions = import ./virtualisation-options.nix;
|
2014-09-06 21:37:46 +02:00
|
|
|
in
|
|
|
|
{
|
2024-09-05 13:06:25 +02:00
|
|
|
imports = [
|
|
|
|
./azure-common.nix
|
|
|
|
virtualisationOptions.diskSize
|
|
|
|
(lib.mkRenamedOptionModuleWith {
|
|
|
|
sinceRelease = 2411;
|
|
|
|
from = [
|
|
|
|
"virtualisation"
|
|
|
|
"azureImage"
|
|
|
|
"diskSize"
|
|
|
|
];
|
|
|
|
to = [
|
|
|
|
"virtualisation"
|
|
|
|
"diskSize"
|
|
|
|
];
|
|
|
|
})
|
|
|
|
];
|
2020-08-07 14:43:58 +01:00
|
|
|
|
2024-08-09 14:47:30 +08:00
|
|
|
options.virtualisation.azureImage = {
|
|
|
|
bootSize = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 256;
|
|
|
|
description = ''
|
|
|
|
ESP partition size. Unit is MB.
|
|
|
|
Only effective when vmGeneration is `v2`.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
contents = mkOption {
|
2023-10-08 19:35:14 +02:00
|
|
|
type = with types; listOf attrs;
|
|
|
|
default = [ ];
|
|
|
|
description = ''
|
|
|
|
Extra contents to add to the image.
|
|
|
|
'';
|
|
|
|
};
|
2024-08-09 14:47:30 +08:00
|
|
|
|
|
|
|
vmGeneration = mkOption {
|
2024-09-05 12:14:16 +02:00
|
|
|
type =
|
|
|
|
with types;
|
|
|
|
enum [
|
|
|
|
"v1"
|
|
|
|
"v2"
|
|
|
|
];
|
2024-08-09 14:47:30 +08:00
|
|
|
default = "v1";
|
|
|
|
description = ''
|
|
|
|
VM Generation to use.
|
|
|
|
For v2, secure boot needs to be turned off during creation.
|
|
|
|
'';
|
|
|
|
};
|
2019-11-18 12:39:18 -08:00
|
|
|
};
|
2024-08-09 14:47:30 +08:00
|
|
|
|
2019-11-18 12:39:18 -08:00
|
|
|
config = {
|
|
|
|
system.build.azureImage = import ../../lib/make-disk-image.nix {
|
|
|
|
name = "azure-image";
|
|
|
|
postVM = ''
|
|
|
|
${pkgs.vmTools.qemu}/bin/qemu-img convert -f raw -o subformat=fixed,force_size -O vpc $diskImage $out/disk.vhd
|
2020-03-26 06:11:54 +00:00
|
|
|
rm $diskImage
|
2019-11-18 12:39:18 -08:00
|
|
|
'';
|
|
|
|
configFile = ./azure-config-user.nix;
|
|
|
|
format = "raw";
|
2024-08-09 14:47:30 +08:00
|
|
|
|
|
|
|
bootSize = "${toString cfg.bootSize}M";
|
|
|
|
partitionTableType = if cfg.vmGeneration == "v2" then "efi" else "legacy";
|
|
|
|
|
2024-09-05 13:06:25 +02:00
|
|
|
inherit (cfg) contents;
|
|
|
|
inherit (config.virtualisation) diskSize;
|
2019-11-18 12:39:18 -08:00
|
|
|
inherit config lib pkgs;
|
|
|
|
};
|
|
|
|
};
|
2014-09-06 21:37:46 +02:00
|
|
|
}
|