2014-04-14 15:26:48 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
2013-12-11 14:32:27 +00:00
|
|
|
|
2014-04-14 15:26:48 +01:00
|
|
|
with lib;
|
2014-03-21 13:55:42 +00:00
|
|
|
let
|
2018-11-26 14:51:00 +00:00
|
|
|
cfg = config.virtualisation.googleComputeImage;
|
|
|
|
defaultConfigFile = pkgs.writeText "configuration.nix" ''
|
|
|
|
{ ... }:
|
|
|
|
{
|
|
|
|
imports = [
|
|
|
|
<nixpkgs/nixos/modules/virtualisation/google-compute-image.nix>
|
|
|
|
];
|
|
|
|
}
|
|
|
|
'';
|
2014-03-21 13:55:42 +00:00
|
|
|
in
|
2013-12-11 14:32:27 +00:00
|
|
|
{
|
2017-05-29 15:33:24 +01:00
|
|
|
|
2018-11-26 14:51:00 +00:00
|
|
|
imports = [ ./google-compute-config.nix ];
|
2017-05-29 15:33:24 +01:00
|
|
|
|
2018-11-26 14:51:00 +00:00
|
|
|
options = {
|
|
|
|
virtualisation.googleComputeImage.diskSize = mkOption {
|
2020-12-19 18:41:11 +00:00
|
|
|
type = with types; either (enum [ "auto" ]) int;
|
|
|
|
default = "auto";
|
|
|
|
example = 1536;
|
2022-08-15 06:16:25 +01:00
|
|
|
description = lib.mdDoc ''
|
2018-11-26 14:51:00 +00:00
|
|
|
Size of disk image. Unit is MB.
|
|
|
|
'';
|
2017-05-29 15:33:24 +01:00
|
|
|
};
|
|
|
|
|
2018-11-26 14:51:00 +00:00
|
|
|
virtualisation.googleComputeImage.configFile = mkOption {
|
|
|
|
type = with types; nullOr str;
|
|
|
|
default = null;
|
2022-08-14 08:03:30 +01:00
|
|
|
description = lib.mdDoc ''
|
2018-11-26 14:51:00 +00:00
|
|
|
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/google-compute-image.nix>`.
|
|
|
|
'';
|
2017-05-29 15:33:24 +01:00
|
|
|
};
|
2021-07-13 15:53:09 +01:00
|
|
|
|
|
|
|
virtualisation.googleComputeImage.compressionLevel = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 6;
|
2022-08-15 06:16:25 +01:00
|
|
|
description = lib.mdDoc ''
|
2021-07-13 15:53:09 +01:00
|
|
|
GZIP compression level of the resulting disk image (1-9).
|
|
|
|
'';
|
|
|
|
};
|
2017-05-29 15:33:24 +01:00
|
|
|
};
|
|
|
|
|
2018-11-26 14:51:00 +00:00
|
|
|
#### implementation
|
|
|
|
config = {
|
|
|
|
|
|
|
|
system.build.googleComputeImage = import ../../lib/make-disk-image.nix {
|
|
|
|
name = "google-compute-image";
|
|
|
|
postVM = ''
|
2021-01-17 20:14:59 +00:00
|
|
|
PATH=$PATH:${with pkgs; lib.makeBinPath [ gnutar gzip ]}
|
2018-11-26 14:51:00 +00:00
|
|
|
pushd $out
|
|
|
|
mv $diskImage disk.raw
|
2021-07-13 15:53:09 +01:00
|
|
|
tar -Sc disk.raw | gzip -${toString cfg.compressionLevel} > \
|
|
|
|
nixos-image-${config.system.nixos.label}-${pkgs.stdenv.hostPlatform.system}.raw.tar.gz
|
2018-11-26 14:51:00 +00:00
|
|
|
rm $out/disk.raw
|
|
|
|
popd
|
|
|
|
'';
|
|
|
|
format = "raw";
|
2019-04-24 04:48:22 +01:00
|
|
|
configFile = if cfg.configFile == null then defaultConfigFile else cfg.configFile;
|
2018-11-26 14:51:00 +00:00
|
|
|
inherit (cfg) diskSize;
|
|
|
|
inherit config lib pkgs;
|
2015-03-26 09:09:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2013-12-11 14:32:27 +00:00
|
|
|
}
|