at 25.11-pre 2.6 kB view raw
1{ 2 config, 3 lib, 4 pkgs, 5 ... 6}: 7 8with lib; 9let 10 cfg = config.virtualisation.digitalOceanImage; 11in 12{ 13 14 imports = [ 15 ./digital-ocean-config.nix 16 ./disk-size-option.nix 17 ../image/file-options.nix 18 (lib.mkRenamedOptionModuleWith { 19 sinceRelease = 2411; 20 from = [ 21 "virtualisation" 22 "digitalOceanImage" 23 "diskSize" 24 ]; 25 to = [ 26 "virtualisation" 27 "diskSize" 28 ]; 29 }) 30 ]; 31 32 options = { 33 virtualisation.digitalOceanImage.configFile = mkOption { 34 type = with types; nullOr path; 35 default = null; 36 description = '' 37 A path to a configuration file which will be placed at 38 `/etc/nixos/configuration.nix` and be used when switching 39 to a new configuration. If set to `null`, a default 40 configuration is used that imports 41 `(modulesPath + "/virtualisation/digital-ocean-config.nix")`. 42 ''; 43 }; 44 45 virtualisation.digitalOceanImage.compressionMethod = mkOption { 46 type = types.enum [ 47 "gzip" 48 "bzip2" 49 ]; 50 default = "gzip"; 51 example = "bzip2"; 52 description = '' 53 Disk image compression method. Choose bzip2 to generate smaller images that 54 take longer to generate but will consume less metered storage space on your 55 Digital Ocean account. 56 ''; 57 }; 58 }; 59 60 #### implementation 61 config = 62 let 63 format = "qcow2"; 64 in 65 { 66 image.extension = lib.concatStringsSep "." [ 67 format 68 ( 69 { 70 "gzip" = "gz"; 71 "bzip2" = "bz2"; 72 } 73 .${cfg.compressionMethod} 74 ) 75 ]; 76 system.nixos.tags = [ "digital-ocean" ]; 77 system.build.image = config.system.build.digitalOceanImage; 78 system.build.digitalOceanImage = import ../../lib/make-disk-image.nix { 79 name = "digital-ocean-image"; 80 inherit (config.image) baseName; 81 inherit (config.virtualisation) diskSize; 82 inherit 83 config 84 lib 85 pkgs 86 format 87 ; 88 postVM = 89 let 90 compress = 91 { 92 "gzip" = "${pkgs.gzip}/bin/gzip"; 93 "bzip2" = "${pkgs.bzip2}/bin/bzip2"; 94 } 95 .${cfg.compressionMethod}; 96 in 97 '' 98 ${compress} $diskImage 99 ''; 100 configFile = 101 if cfg.configFile == null then 102 config.virtualisation.digitalOcean.defaultConfigFile 103 else 104 cfg.configFile; 105 }; 106 107 }; 108 109 meta.maintainers = with maintainers; [ 110 arianvp 111 eamsden 112 ]; 113 114}