2022-09-28 22:25:03 +00:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
pkgs,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
let
|
|
|
|
cfg = config.virtualisation.linodeImage;
|
|
|
|
defaultConfigFile = pkgs.writeText "configuration.nix" ''
|
|
|
|
_: {
|
|
|
|
imports = [
|
|
|
|
<nixpkgs/nixos/modules/virtualisation/linode-image.nix>
|
|
|
|
];
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
in
|
|
|
|
{
|
2024-09-10 17:14:43 +00:00
|
|
|
imports = [
|
|
|
|
./linode-config.nix
|
|
|
|
./disk-size-option.nix
|
2024-11-14 23:02:35 +00:00
|
|
|
../image/file-options.nix
|
2024-09-10 17:14:43 +00:00
|
|
|
(lib.mkRenamedOptionModuleWith {
|
|
|
|
sinceRelease = 2411;
|
|
|
|
from = [
|
|
|
|
"virtualisation"
|
|
|
|
"linodeImage"
|
|
|
|
"diskSize"
|
|
|
|
];
|
|
|
|
to = [
|
|
|
|
"virtualisation"
|
|
|
|
"diskSize"
|
|
|
|
];
|
|
|
|
})
|
|
|
|
];
|
2022-09-28 22:25:03 +00:00
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
virtualisation.linodeImage.configFile = mkOption {
|
|
|
|
type = with types; nullOr str;
|
|
|
|
default = null;
|
|
|
|
description = ''
|
|
|
|
A path to a configuration file which will be placed at `/etc/nixos/configuration.nix`
|
|
|
|
and be used when switching to a new configuration.
|
|
|
|
If set to `null`, a default configuration is used, where the only import is
|
|
|
|
`<nixpkgs/nixos/modules/virtualisation/linode-image.nix>`
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
virtualisation.linodeImage.compressionLevel = mkOption {
|
|
|
|
type = types.ints.between 1 9;
|
|
|
|
default = 6;
|
|
|
|
description = ''
|
|
|
|
GZIP compression level of the resulting disk image (1-9).
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = {
|
2024-11-14 23:02:35 +00:00
|
|
|
system.nixos.tags = [ "linode" ];
|
|
|
|
image.extension = "img.gz";
|
|
|
|
system.build.image = config.system.build.linodeImage;
|
2022-09-28 22:25:03 +00:00
|
|
|
system.build.linodeImage = import ../../lib/make-disk-image.nix {
|
|
|
|
name = "linode-image";
|
2024-11-14 23:02:35 +00:00
|
|
|
baseName = config.image.baseName;
|
2022-09-28 22:25:03 +00:00
|
|
|
# NOTE: Linode specifically requires images to be `gzip`-ed prior to upload
|
|
|
|
# See: https://www.linode.com/docs/products/tools/images/guides/upload-an-image/#requirements-and-considerations
|
|
|
|
postVM = ''
|
|
|
|
${pkgs.gzip}/bin/gzip -${toString cfg.compressionLevel} -c -- $diskImage > \
|
2024-11-14 23:02:35 +00:00
|
|
|
$out/${config.image.fileName}
|
2022-09-28 22:25:03 +00:00
|
|
|
rm $diskImage
|
|
|
|
'';
|
|
|
|
format = "raw";
|
|
|
|
partitionTableType = "none";
|
|
|
|
configFile = if cfg.configFile == null then defaultConfigFile else cfg.configFile;
|
2024-09-10 17:14:43 +00:00
|
|
|
inherit (config.virtualisation) diskSize;
|
2022-09-28 22:25:03 +00:00
|
|
|
inherit config lib pkgs;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-03-30 22:35:50 +00:00
|
|
|
meta.maintainers = with maintainers; [ cyntheticfox ];
|
2022-09-28 22:25:03 +00:00
|
|
|
}
|