2014-09-06 21:37:46 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
let
|
2019-11-18 21:39:18 +01:00
|
|
|
cfg = config.virtualisation.azureImage;
|
2014-09-06 21:37:46 +02:00
|
|
|
in
|
|
|
|
{
|
2015-05-03 19:18:18 +02:00
|
|
|
imports = [ ./azure-common.nix ];
|
2019-11-18 21:39:18 +01:00
|
|
|
|
|
|
|
options = {
|
|
|
|
virtualisation.azureImage.diskSize = mkOption {
|
|
|
|
type = with types; int;
|
|
|
|
default = 2048;
|
|
|
|
description = ''
|
|
|
|
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 07:11:54 +01:00
|
|
|
rm $diskImage
|
2019-11-18 21:39:18 +01:00
|
|
|
'';
|
|
|
|
configFile = ./azure-config-user.nix;
|
|
|
|
format = "raw";
|
|
|
|
inherit (cfg) diskSize;
|
|
|
|
inherit config lib pkgs;
|
|
|
|
};
|
2014-09-06 21:37:46 +02:00
|
|
|
|
2019-11-18 21:39:18 +01:00
|
|
|
# Azure metadata is available as a CD-ROM drive.
|
|
|
|
fileSystems."/metadata".device = "/dev/sr0";
|
2014-09-06 21:53:10 +02:00
|
|
|
|
2019-11-18 21:39:18 +01:00
|
|
|
systemd.services.fetch-ssh-keys = {
|
|
|
|
description = "Fetch host keys and authorized_keys for root user";
|
2015-02-16 15:54:30 +01:00
|
|
|
|
2015-12-09 06:39:17 +01:00
|
|
|
wantedBy = [ "sshd.service" "waagent.service" ];
|
|
|
|
before = [ "sshd.service" "waagent.service" ];
|
2015-02-16 15:54:30 +01:00
|
|
|
|
|
|
|
path = [ pkgs.coreutils ];
|
|
|
|
script =
|
|
|
|
''
|
2016-01-10 10:35:44 +01:00
|
|
|
eval "$(cat /metadata/CustomData.bin)"
|
2015-02-16 15:54:30 +01:00
|
|
|
if ! [ -z "$ssh_host_ecdsa_key" ]; then
|
|
|
|
echo "downloaded ssh_host_ecdsa_key"
|
2015-12-09 06:39:17 +01:00
|
|
|
echo "$ssh_host_ecdsa_key" > /etc/ssh/ssh_host_ed25519_key
|
|
|
|
chmod 600 /etc/ssh/ssh_host_ed25519_key
|
2015-02-16 15:54:30 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
if ! [ -z "$ssh_host_ecdsa_key_pub" ]; then
|
|
|
|
echo "downloaded ssh_host_ecdsa_key_pub"
|
2015-12-09 06:39:17 +01: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 15:54:30 +01: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 21:39:18 +01:00
|
|
|
};
|
|
|
|
};
|
2014-09-06 21:37:46 +02:00
|
|
|
}
|