2020-04-24 23:36:52 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
let
|
|
|
|
cfg = config.virtualisation.azureImage;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
imports = [ ./azure-common.nix ];
|
2020-08-20 17:08:02 +00:00
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
options.virtualisation.azureImage = {
|
|
|
|
diskSize = mkOption {
|
2021-04-26 19:14:03 +00:00
|
|
|
type = with types; either (enum [ "auto" ]) int;
|
|
|
|
default = "auto";
|
|
|
|
example = 2048;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Size of disk image. Unit is MB.
|
|
|
|
'';
|
|
|
|
};
|
2024-09-19 14:19:46 +00:00
|
|
|
|
|
|
|
bootSize = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 256;
|
|
|
|
description = ''
|
|
|
|
ESP partition size. Unit is MB.
|
|
|
|
Only effective when vmGeneration is `v2`.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
contents = mkOption {
|
2023-10-09 19:29:22 +00:00
|
|
|
type = with types; listOf attrs;
|
|
|
|
default = [ ];
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2023-10-09 19:29:22 +00:00
|
|
|
Extra contents to add to the image.
|
|
|
|
'';
|
|
|
|
};
|
2024-09-19 14:19:46 +00:00
|
|
|
|
|
|
|
vmGeneration = mkOption {
|
|
|
|
type = with types; enum [ "v1" "v2" ];
|
|
|
|
default = "v1";
|
|
|
|
description = ''
|
|
|
|
VM Generation to use.
|
|
|
|
For v2, secure boot needs to be turned off during creation.
|
|
|
|
'';
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
2024-09-19 14:19:46 +00:00
|
|
|
|
2020-04-24 23:36:52 +00: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
|
|
|
|
rm $diskImage
|
|
|
|
'';
|
|
|
|
configFile = ./azure-config-user.nix;
|
|
|
|
format = "raw";
|
2024-09-19 14:19:46 +00:00
|
|
|
|
|
|
|
bootSize = "${toString cfg.bootSize}M";
|
|
|
|
partitionTableType = if cfg.vmGeneration == "v2" then "efi" else "legacy";
|
|
|
|
|
2023-10-09 19:29:22 +00:00
|
|
|
inherit (cfg) diskSize contents;
|
2020-04-24 23:36:52 +00:00
|
|
|
inherit config lib pkgs;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|