2020-04-24 23:36:52 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
let
|
|
|
|
cfg = config.virtualisation.digitalOceanImage;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
|
|
|
|
imports = [ ./digital-ocean-config.nix ];
|
|
|
|
|
|
|
|
options = {
|
|
|
|
virtualisation.digitalOceanImage.diskSize = mkOption {
|
2021-04-26 19:14:03 +00:00
|
|
|
type = with types; either (enum [ "auto" ]) int;
|
|
|
|
default = "auto";
|
|
|
|
example = 4096;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Size of disk image. Unit is MB.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
virtualisation.digitalOceanImage.configFile = mkOption {
|
|
|
|
type = with types; nullOr path;
|
|
|
|
default = null;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
A path to a configuration file which will be placed at
|
2022-08-12 12:06:08 +00:00
|
|
|
`/etc/nixos/configuration.nix` and be used when switching
|
|
|
|
to a new configuration. If set to `null`, a default
|
2020-04-24 23:36:52 +00:00
|
|
|
configuration is used that imports
|
2022-08-12 12:06:08 +00:00
|
|
|
`(modulesPath + "/virtualisation/digital-ocean-config.nix")`.
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
virtualisation.digitalOceanImage.compressionMethod = mkOption {
|
|
|
|
type = types.enum [ "gzip" "bzip2" ];
|
|
|
|
default = "gzip";
|
|
|
|
example = "bzip2";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Disk image compression method. Choose bzip2 to generate smaller images that
|
|
|
|
take longer to generate but will consume less metered storage space on your
|
|
|
|
Digital Ocean account.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
#### implementation
|
|
|
|
config = {
|
|
|
|
|
|
|
|
system.build.digitalOceanImage = import ../../lib/make-disk-image.nix {
|
|
|
|
name = "digital-ocean-image";
|
|
|
|
format = "qcow2";
|
|
|
|
postVM = let
|
|
|
|
compress = {
|
|
|
|
"gzip" = "${pkgs.gzip}/bin/gzip";
|
|
|
|
"bzip2" = "${pkgs.bzip2}/bin/bzip2";
|
|
|
|
}.${cfg.compressionMethod};
|
|
|
|
in ''
|
|
|
|
${compress} $diskImage
|
|
|
|
'';
|
|
|
|
configFile = if cfg.configFile == null
|
|
|
|
then config.virtualisation.digitalOcean.defaultConfigFile
|
|
|
|
else cfg.configFile;
|
|
|
|
inherit (cfg) diskSize;
|
|
|
|
inherit config lib pkgs;
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
meta.maintainers = with maintainers; [ arianvp eamsden ];
|
|
|
|
|
|
|
|
}
|