1{ config, lib, pkgs, ... }:
2
3with lib;
4let
5 cfg = config.virtualisation.linodeImage;
6 defaultConfigFile = pkgs.writeText "configuration.nix" ''
7 _: {
8 imports = [
9 <nixpkgs/nixos/modules/virtualisation/linode-image.nix>
10 ];
11 }
12 '';
13in
14{
15 imports = [ ./linode-config.nix ];
16
17 options = {
18 virtualisation.linodeImage.diskSize = mkOption {
19 type = with types; either (enum (singleton "auto")) ints.positive;
20 default = "auto";
21 example = 1536;
22 description = ''
23 Size of disk image in MB.
24 '';
25 };
26
27 virtualisation.linodeImage.configFile = mkOption {
28 type = with types; nullOr str;
29 default = null;
30 description = ''
31 A path to a configuration file which will be placed at `/etc/nixos/configuration.nix`
32 and be used when switching to a new configuration.
33 If set to `null`, a default configuration is used, where the only import is
34 `<nixpkgs/nixos/modules/virtualisation/linode-image.nix>`
35 '';
36 };
37
38 virtualisation.linodeImage.compressionLevel = mkOption {
39 type = types.ints.between 1 9;
40 default = 6;
41 description = ''
42 GZIP compression level of the resulting disk image (1-9).
43 '';
44 };
45 };
46
47 config = {
48 system.build.linodeImage = import ../../lib/make-disk-image.nix {
49 name = "linode-image";
50 # NOTE: Linode specifically requires images to be `gzip`-ed prior to upload
51 # See: https://www.linode.com/docs/products/tools/images/guides/upload-an-image/#requirements-and-considerations
52 postVM = ''
53 ${pkgs.gzip}/bin/gzip -${toString cfg.compressionLevel} -c -- $diskImage > \
54 $out/nixos-image-${config.system.nixos.label}-${pkgs.stdenv.hostPlatform.system}.img.gz
55 rm $diskImage
56 '';
57 format = "raw";
58 partitionTableType = "none";
59 configFile = if cfg.configFile == null then defaultConfigFile else cfg.configFile;
60 inherit (cfg) diskSize;
61 inherit config lib pkgs;
62 };
63 };
64
65 meta.maintainers = with maintainers; [ cyntheticfox ];
66}