at 23.11-pre 2.0 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 = lib.mdDoc '' 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 = lib.mdDoc '' 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 = lib.mdDoc '' 44 GZIP compression level of the resulting disk image (1-9). 45 ''; 46 }; 47 }; 48 49 #### implementation 50 config = { 51 52 system.build.googleComputeImage = import ../../lib/make-disk-image.nix { 53 name = "google-compute-image"; 54 postVM = '' 55 PATH=$PATH:${with pkgs; lib.makeBinPath [ gnutar gzip ]} 56 pushd $out 57 mv $diskImage disk.raw 58 tar -Sc disk.raw | gzip -${toString cfg.compressionLevel} > \ 59 nixos-image-${config.system.nixos.label}-${pkgs.stdenv.hostPlatform.system}.raw.tar.gz 60 rm $out/disk.raw 61 popd 62 ''; 63 format = "raw"; 64 configFile = if cfg.configFile == null then defaultConfigFile else cfg.configFile; 65 inherit (cfg) diskSize; 66 inherit config lib pkgs; 67 }; 68 69 }; 70 71}