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