typioca: 2.7.0 -> 2.8.0
[NixPkgs.git] / nixos / modules / virtualisation / digital-ocean-image.nix
bloba57c89245f2e186c3cee7b043a4a7fec72b2f638
1 { config, lib, pkgs, ... }:
3 with lib;
4 let
5   cfg = config.virtualisation.digitalOceanImage;
6 in
9   imports = [ ./digital-ocean-config.nix ];
11   options = {
12     virtualisation.digitalOceanImage.diskSize = mkOption {
13       type = with types; either (enum [ "auto" ]) int;
14       default = "auto";
15       example = 4096;
16       description = lib.mdDoc ''
17         Size of disk image. Unit is MB.
18       '';
19     };
21     virtualisation.digitalOceanImage.configFile = mkOption {
22       type = with types; nullOr path;
23       default = null;
24       description = lib.mdDoc ''
25         A path to a configuration file which will be placed at
26         `/etc/nixos/configuration.nix` and be used when switching
27         to a new configuration. If set to `null`, a default
28         configuration is used that imports
29         `(modulesPath + "/virtualisation/digital-ocean-config.nix")`.
30       '';
31     };
33     virtualisation.digitalOceanImage.compressionMethod = mkOption {
34       type = types.enum [ "gzip" "bzip2" ];
35       default = "gzip";
36       example = "bzip2";
37       description = lib.mdDoc ''
38         Disk image compression method. Choose bzip2 to generate smaller images that
39         take longer to generate but will consume less metered storage space on your
40         Digital Ocean account.
41       '';
42     };
43   };
45   #### implementation
46   config = {
48     system.build.digitalOceanImage = import ../../lib/make-disk-image.nix {
49       name = "digital-ocean-image";
50       format = "qcow2";
51       postVM = let
52         compress = {
53           "gzip" = "${pkgs.gzip}/bin/gzip";
54           "bzip2" = "${pkgs.bzip2}/bin/bzip2";
55         }.${cfg.compressionMethod};
56       in ''
57         ${compress} $diskImage
58       '';
59       configFile = if cfg.configFile == null
60         then config.virtualisation.digitalOcean.defaultConfigFile
61         else cfg.configFile;
62       inherit (cfg) diskSize;
63       inherit config lib pkgs;
64     };
66   };
68   meta.maintainers = with maintainers; [ arianvp eamsden ];