1 { config, lib, pkgs, ... }:
5 cfg = config.virtualisation.googleComputeImage;
6 defaultConfigFile = pkgs.writeText "configuration.nix" ''
10 <nixpkgs/nixos/modules/virtualisation/google-compute-image.nix>
17 imports = [ ./google-compute-config.nix ];
20 virtualisation.googleComputeImage.diskSize = mkOption {
21 type = with types; either (enum [ "auto" ]) int;
25 Size of disk image. Unit is MB.
29 virtualisation.googleComputeImage.configFile = mkOption {
30 type = with types; nullOr str;
33 A path to a configuration file which will be placed at `/etc/nixos/configuration.nix`
34 and be used when switching to a new configuration.
35 If set to `null`, a default configuration is used, where the only import is
36 `<nixpkgs/nixos/modules/virtualisation/google-compute-image.nix>`.
40 virtualisation.googleComputeImage.compressionLevel = mkOption {
44 GZIP compression level of the resulting disk image (1-9).
47 virtualisation.googleComputeImage.efi = mkEnableOption "EFI booting";
52 boot.initrd.availableKernelModules = [ "nvme" ];
53 boot.loader.grub = mkIf cfg.efi {
54 device = mkForce "nodev";
56 efiInstallAsRemovable = true;
59 fileSystems."/boot" = mkIf cfg.efi {
60 device = "/dev/disk/by-label/ESP";
64 system.build.googleComputeImage = import ../../lib/make-disk-image.nix {
65 name = "google-compute-image";
67 PATH=$PATH:${with pkgs; lib.makeBinPath [ gnutar gzip ]}
69 mv $diskImage disk.raw
70 tar -Sc disk.raw | gzip -${toString cfg.compressionLevel} > \
71 nixos-image-${config.system.nixos.label}-${pkgs.stdenv.hostPlatform.system}.raw.tar.gz
76 configFile = if cfg.configFile == null then defaultConfigFile else cfg.configFile;
77 partitionTableType = if cfg.efi then "efi" else "legacy";
78 inherit (cfg) diskSize;
79 inherit config lib pkgs;