2014-09-06 19:37:46 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
let
|
2019-11-18 20:39:18 +00:00
|
|
|
cfg = config.virtualisation.azureImage;
|
2014-09-06 19:37:46 +00:00
|
|
|
in
|
|
|
|
{
|
2015-05-03 17:18:18 +00:00
|
|
|
imports = [ ./azure-common.nix ];
|
2020-08-07 13:43:58 +00:00
|
|
|
|
2019-11-18 20:39:18 +00:00
|
|
|
options = {
|
|
|
|
virtualisation.azureImage.diskSize = mkOption {
|
2020-12-19 18:41:11 +00:00
|
|
|
type = with types; either (enum [ "auto" ]) int;
|
|
|
|
default = "auto";
|
|
|
|
example = 2048;
|
2019-11-18 20:39:18 +00:00
|
|
|
description = lib.mdDoc ''
|
|
|
|
Size of disk image. Unit is MB.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
config = {
|
|
|
|
system.build.azureImage = import ../../lib/make-disk-image.nix {
|
|
|
|
name = "azure-image";
|
|
|
|
postVM = ''
|
|
|
|
${pkgs.vmTools.qemu}/bin/qemu-img convert -f raw -o subformat=fixed,force_size -O vpc $diskImage $out/disk.vhd
|
2020-03-26 06:11:54 +00:00
|
|
|
rm $diskImage
|
2019-11-18 20:39:18 +00:00
|
|
|
'';
|
|
|
|
configFile = ./azure-config-user.nix;
|
|
|
|
format = "raw";
|
|
|
|
inherit (cfg) diskSize;
|
|
|
|
inherit config lib pkgs;
|
|
|
|
};
|
2014-09-06 19:37:46 +00:00
|
|
|
|
2019-11-18 20:39:18 +00:00
|
|
|
# Azure metadata is available as a CD-ROM drive.
|
|
|
|
fileSystems."/metadata".device = "/dev/sr0";
|
2014-09-06 19:53:10 +00:00
|
|
|
|
2019-11-18 20:39:18 +00:00
|
|
|
systemd.services.fetch-ssh-keys = {
|
|
|
|
description = "Fetch host keys and authorized_keys for root user";
|
2015-02-16 14:54:30 +00:00
|
|
|
|
2015-12-09 05:39:17 +00:00
|
|
|
wantedBy = [ "sshd.service" "waagent.service" ];
|
|
|
|
before = [ "sshd.service" "waagent.service" ];
|
2015-02-16 14:54:30 +00:00
|
|
|
|
|
|
|
path = [ pkgs.coreutils ];
|
|
|
|
script =
|
|
|
|
''
|
2016-01-10 09:35:44 +00:00
|
|
|
eval "$(cat /metadata/CustomData.bin)"
|
2015-02-16 14:54:30 +00:00
|
|
|
if ! [ -z "$ssh_host_ecdsa_key" ]; then
|
|
|
|
echo "downloaded ssh_host_ecdsa_key"
|
2015-12-09 05:39:17 +00:00
|
|
|
echo "$ssh_host_ecdsa_key" > /etc/ssh/ssh_host_ed25519_key
|
|
|
|
chmod 600 /etc/ssh/ssh_host_ed25519_key
|
2015-02-16 14:54:30 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if ! [ -z "$ssh_host_ecdsa_key_pub" ]; then
|
|
|
|
echo "downloaded ssh_host_ecdsa_key_pub"
|
2015-12-09 05:39:17 +00:00
|
|
|
echo "$ssh_host_ecdsa_key_pub" > /etc/ssh/ssh_host_ed25519_key.pub
|
|
|
|
chmod 644 /etc/ssh/ssh_host_ed25519_key.pub
|
2015-02-16 14:54:30 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if ! [ -z "$ssh_root_auth_key" ]; then
|
|
|
|
echo "downloaded ssh_root_auth_key"
|
|
|
|
mkdir -m 0700 -p /root/.ssh
|
|
|
|
echo "$ssh_root_auth_key" > /root/.ssh/authorized_keys
|
|
|
|
chmod 600 /root/.ssh/authorized_keys
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
serviceConfig.Type = "oneshot";
|
|
|
|
serviceConfig.RemainAfterExit = true;
|
|
|
|
serviceConfig.StandardError = "journal+console";
|
|
|
|
serviceConfig.StandardOutput = "journal+console";
|
2019-11-18 20:39:18 +00:00
|
|
|
};
|
|
|
|
};
|
2014-09-06 19:37:46 +00:00
|
|
|
}
|