1{ config, lib, pkgs, ... }:
2
3with lib;
4let
5 cfg = config.virtualisation.digitalOceanImage;
6in
7{
8
9 imports = [ ./digital-ocean-config.nix ];
10
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 };
20
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 };
32
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 };
44
45 #### implementation
46 config = {
47
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 };
65
66 };
67
68 meta.maintainers = with maintainers; [ arianvp eamsden ];
69
70}