at 24.11-pre 2.4 kB view raw
1{ config, lib, pkgs, ... }: 2 3with lib; 4let 5 cfg = config.virtualisation.googleComputeImage; 6 defaultConfigFile = pkgs.writeText "configuration.nix" '' 7 { ... }: 8 { 9 imports = [ 10 <nixpkgs/nixos/modules/virtualisation/google-compute-image.nix> 11 ]; 12 } 13 ''; 14in 15{ 16 17 imports = [ ./google-compute-config.nix ]; 18 19 options = { 20 virtualisation.googleComputeImage.diskSize = mkOption { 21 type = with types; either (enum [ "auto" ]) int; 22 default = "auto"; 23 example = 1536; 24 description = '' 25 Size of disk image. Unit is MB. 26 ''; 27 }; 28 29 virtualisation.googleComputeImage.configFile = mkOption { 30 type = with types; nullOr str; 31 default = null; 32 description = '' 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>`. 37 ''; 38 }; 39 40 virtualisation.googleComputeImage.compressionLevel = mkOption { 41 type = types.int; 42 default = 6; 43 description = '' 44 GZIP compression level of the resulting disk image (1-9). 45 ''; 46 }; 47 virtualisation.googleComputeImage.efi = mkEnableOption "EFI booting"; 48 }; 49 50 #### implementation 51 config = { 52 boot.initrd.availableKernelModules = [ "nvme" ]; 53 boot.loader.grub = mkIf cfg.efi { 54 device = mkForce "nodev"; 55 efiSupport = true; 56 efiInstallAsRemovable = true; 57 }; 58 59 fileSystems."/boot" = mkIf cfg.efi { 60 device = "/dev/disk/by-label/ESP"; 61 fsType = "vfat"; 62 }; 63 64 system.build.googleComputeImage = import ../../lib/make-disk-image.nix { 65 name = "google-compute-image"; 66 postVM = '' 67 PATH=$PATH:${with pkgs; lib.makeBinPath [ gnutar gzip ]} 68 pushd $out 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 72 rm $out/disk.raw 73 popd 74 ''; 75 format = "raw"; 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; 80 }; 81 82 }; 83 84}