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;
|
2018-11-26 14:51:00 +00:00
|
|
|
description = ''
|
|
|
|
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;
|
|
|
|
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/google-compute-image.nix>`.
|
|
|
|
'';
|
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
|
|
|
|
tar -Szcf nixos-image-${config.system.nixos.label}-${pkgs.stdenv.hostPlatform.system}.raw.tar.gz disk.raw
|
|
|
|
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
|
|
|
}
|