2024-09-10 03:12:55 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
2013-12-11 15:32:27 +01:00
|
|
|
|
2014-04-14 16:26:48 +02:00
|
|
|
with lib;
|
2014-03-21 14:55:42 +01:00
|
|
|
let
|
2018-11-26 15:51:00 +01:00
|
|
|
cfg = config.virtualisation.googleComputeImage;
|
|
|
|
defaultConfigFile = pkgs.writeText "configuration.nix" ''
|
|
|
|
{ ... }:
|
|
|
|
{
|
|
|
|
imports = [
|
|
|
|
<nixpkgs/nixos/modules/virtualisation/google-compute-image.nix>
|
|
|
|
];
|
|
|
|
}
|
|
|
|
'';
|
2014-03-21 14:55:42 +01:00
|
|
|
in
|
2013-12-11 15:32:27 +01:00
|
|
|
{
|
2017-05-29 16:33:24 +02:00
|
|
|
|
2024-09-10 03:12:55 +02:00
|
|
|
imports = [ ./google-compute-config.nix ];
|
2017-05-29 16:33:24 +02:00
|
|
|
|
2018-11-26 15:51:00 +01:00
|
|
|
options = {
|
2024-09-10 03:12:55 +02:00
|
|
|
virtualisation.googleComputeImage.diskSize = mkOption {
|
|
|
|
type = with types; either (enum [ "auto" ]) int;
|
|
|
|
default = "auto";
|
|
|
|
example = 1536;
|
|
|
|
description = ''
|
|
|
|
Size of disk image. Unit is MB.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-11-26 15:51:00 +01:00
|
|
|
virtualisation.googleComputeImage.configFile = mkOption {
|
|
|
|
type = with types; nullOr str;
|
|
|
|
default = null;
|
|
|
|
description = ''
|
|
|
|
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>`.
|
|
|
|
'';
|
2017-05-29 16:33:24 +02:00
|
|
|
};
|
2021-07-13 16:53:09 +02:00
|
|
|
|
|
|
|
virtualisation.googleComputeImage.compressionLevel = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 6;
|
|
|
|
description = ''
|
|
|
|
GZIP compression level of the resulting disk image (1-9).
|
|
|
|
'';
|
|
|
|
};
|
2023-11-07 19:59:58 +01:00
|
|
|
virtualisation.googleComputeImage.efi = mkEnableOption "EFI booting";
|
2017-05-29 16:33:24 +02:00
|
|
|
};
|
|
|
|
|
2018-11-26 15:51:00 +01:00
|
|
|
#### implementation
|
|
|
|
config = {
|
2023-11-07 19:59:58 +01:00
|
|
|
boot.initrd.availableKernelModules = [ "nvme" ];
|
|
|
|
boot.loader.grub = mkIf cfg.efi {
|
|
|
|
device = mkForce "nodev";
|
|
|
|
efiSupport = true;
|
|
|
|
efiInstallAsRemovable = true;
|
|
|
|
};
|
2018-11-26 15:51:00 +01:00
|
|
|
|
2023-11-16 02:29:57 +01:00
|
|
|
fileSystems."/boot" = mkIf cfg.efi {
|
|
|
|
device = "/dev/disk/by-label/ESP";
|
|
|
|
fsType = "vfat";
|
|
|
|
};
|
|
|
|
|
2018-11-26 15:51:00 +01:00
|
|
|
system.build.googleComputeImage = import ../../lib/make-disk-image.nix {
|
|
|
|
name = "google-compute-image";
|
|
|
|
postVM = ''
|
2024-09-10 03:12:55 +02:00
|
|
|
PATH=$PATH:${with pkgs; lib.makeBinPath [ gnutar gzip ]}
|
2018-11-26 15:51:00 +01:00
|
|
|
pushd $out
|
|
|
|
mv $diskImage disk.raw
|
2021-07-13 16:53:09 +02:00
|
|
|
tar -Sc disk.raw | gzip -${toString cfg.compressionLevel} > \
|
|
|
|
nixos-image-${config.system.nixos.label}-${pkgs.stdenv.hostPlatform.system}.raw.tar.gz
|
2018-11-26 15:51:00 +01:00
|
|
|
rm $out/disk.raw
|
|
|
|
popd
|
|
|
|
'';
|
|
|
|
format = "raw";
|
2019-04-24 05:48:22 +02:00
|
|
|
configFile = if cfg.configFile == null then defaultConfigFile else cfg.configFile;
|
2023-11-07 19:59:58 +01:00
|
|
|
partitionTableType = if cfg.efi then "efi" else "legacy";
|
2024-09-10 03:12:55 +02:00
|
|
|
inherit (cfg) diskSize;
|
2018-11-26 15:51:00 +01:00
|
|
|
inherit config lib pkgs;
|
2015-03-26 10:09:18 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2013-12-11 15:32:27 +01:00
|
|
|
}
|