2020-04-24 23:36:52 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
let
|
|
|
|
cfg = config.virtualisation.googleComputeImage;
|
|
|
|
defaultConfigFile = pkgs.writeText "configuration.nix" ''
|
|
|
|
{ ... }:
|
|
|
|
{
|
|
|
|
imports = [
|
|
|
|
<nixpkgs/nixos/modules/virtualisation/google-compute-image.nix>
|
|
|
|
];
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
in
|
|
|
|
{
|
|
|
|
|
|
|
|
imports = [ ./google-compute-config.nix ];
|
|
|
|
|
|
|
|
options = {
|
|
|
|
virtualisation.googleComputeImage.diskSize = mkOption {
|
2021-04-26 19:14:03 +00:00
|
|
|
type = with types; either (enum [ "auto" ]) int;
|
|
|
|
default = "auto";
|
|
|
|
example = 1536;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Size of disk image. Unit is MB.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
virtualisation.googleComputeImage.configFile = mkOption {
|
|
|
|
type = with types; nullOr str;
|
|
|
|
default = null;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-04-24 23:36:52 +00:00
|
|
|
A path to a configuration file which will be placed at `/etc/nixos/configuration.nix`
|
|
|
|
and be used when switching to a new configuration.
|
|
|
|
If set to `null`, a default configuration is used, where the only import is
|
|
|
|
`<nixpkgs/nixos/modules/virtualisation/google-compute-image.nix>`.
|
|
|
|
'';
|
|
|
|
};
|
2021-08-18 13:19:15 +00:00
|
|
|
|
|
|
|
virtualisation.googleComputeImage.compressionLevel = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 6;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2021-08-18 13:19:15 +00:00
|
|
|
GZIP compression level of the resulting disk image (1-9).
|
|
|
|
'';
|
|
|
|
};
|
2023-11-16 04:20:00 +00:00
|
|
|
virtualisation.googleComputeImage.efi = mkEnableOption "EFI booting";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#### implementation
|
|
|
|
config = {
|
2023-11-16 04:20:00 +00:00
|
|
|
boot.initrd.availableKernelModules = [ "nvme" ];
|
|
|
|
boot.loader.grub = mkIf cfg.efi {
|
|
|
|
device = mkForce "nodev";
|
|
|
|
efiSupport = true;
|
|
|
|
efiInstallAsRemovable = true;
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2024-01-02 11:29:13 +00:00
|
|
|
fileSystems."/boot" = mkIf cfg.efi {
|
|
|
|
device = "/dev/disk/by-label/ESP";
|
|
|
|
fsType = "vfat";
|
|
|
|
};
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
system.build.googleComputeImage = import ../../lib/make-disk-image.nix {
|
|
|
|
name = "google-compute-image";
|
|
|
|
postVM = ''
|
2021-02-05 17:12:51 +00:00
|
|
|
PATH=$PATH:${with pkgs; lib.makeBinPath [ gnutar gzip ]}
|
2020-04-24 23:36:52 +00:00
|
|
|
pushd $out
|
|
|
|
mv $diskImage disk.raw
|
2021-08-18 13:19:15 +00:00
|
|
|
tar -Sc disk.raw | gzip -${toString cfg.compressionLevel} > \
|
|
|
|
nixos-image-${config.system.nixos.label}-${pkgs.stdenv.hostPlatform.system}.raw.tar.gz
|
2020-04-24 23:36:52 +00:00
|
|
|
rm $out/disk.raw
|
|
|
|
popd
|
|
|
|
'';
|
|
|
|
format = "raw";
|
|
|
|
configFile = if cfg.configFile == null then defaultConfigFile else cfg.configFile;
|
2023-11-16 04:20:00 +00:00
|
|
|
partitionTableType = if cfg.efi then "efi" else "legacy";
|
2020-04-24 23:36:52 +00:00
|
|
|
inherit (cfg) diskSize;
|
|
|
|
inherit config lib pkgs;
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|