···
1
+
{ config, lib, pkgs, ... }:
7
+
cfg = config.virtualisation.azure.agent;
9
+
waagent = with pkgs; stdenv.mkDerivation rec {
10
+
name = "waagent-2.0";
11
+
src = pkgs.fetchgit {
12
+
url = https://github.com/Phreedom/WALinuxAgent.git;
13
+
rev = "9dba81c7b1239c7971ec96e405e403c7cd224e6b";
14
+
sha256 = "0khxk3ns3z37v26f2qj6m3m698a0vqpc9bxg5p7fyr3xza5gzwhs";
16
+
buildInputs = [ makeWrapper python pythonPackages.wrapPython ];
17
+
runtimeDeps = [ findutils gnugrep gawk coreutils openssl openssh
18
+
nettools # for hostname
20
+
shadow # for useradd, usermod
21
+
utillinux # for (u)mount, fdisk, sfdisk, mkswap
24
+
pythonPath = [ pythonPackages.pyasn1 ];
26
+
configurePhase = false;
30
+
substituteInPlace config/99-azure-product-uuid.rules \
31
+
--replace /bin/chmod "${coreutils}/bin/chmod"
32
+
mkdir -p $out/lib/udev/rules.d
33
+
cp config/*.rules $out/lib/udev/rules.d
36
+
cp waagent $out/bin/
37
+
chmod +x $out/bin/waagent
39
+
wrapProgram "$out/bin/waagent" \
40
+
--prefix PYTHONPATH : $PYTHONPATH \
41
+
--prefix PATH : "${makeSearchPath "bin" runtimeDeps}"
45
+
provisionedHook = pkgs.writeScript "provisioned-hook" ''
46
+
#!${pkgs.stdenv.shell}
47
+
${config.systemd.package}/bin/systemctl start provisioned.target
56
+
options.virtualisation.azure.agent.enable = mkOption {
58
+
description = "Whether to enable the Windows Azure Linux Agent.";
61
+
###### implementation
63
+
config = mkIf cfg.enable {
65
+
assertion = pkgs.stdenv.isi686 || pkgs.stdenv.isx86_64;
66
+
message = "Azure not currently supported on ${pkgs.stdenv.system}";
68
+
assertion = config.networking.networkmanager.enable == false;
69
+
message = "Windows Azure Linux Agent is not compatible with NetworkManager";
72
+
boot.initrd.kernelModules = [ "ata_piix" ];
73
+
networking.firewall.allowedUDPPorts = [ 68 ];
76
+
environment.etc."waagent.conf".text = ''
78
+
# Windows Azure Linux Agent Configuration
81
+
Role.StateConsumer=${provisionedHook}
83
+
# Enable instance creation
84
+
Provisioning.Enabled=y
86
+
# Password authentication for root account will be unavailable.
87
+
Provisioning.DeleteRootPassword=n
89
+
# Generate fresh host key pair.
90
+
Provisioning.RegenerateSshHostKeyPair=y
92
+
# Supported values are "rsa", "dsa" and "ecdsa".
93
+
Provisioning.SshHostKeyPairType=ed25519
95
+
# Monitor host name changes and publish changes via DHCP requests.
96
+
Provisioning.MonitorHostName=y
98
+
# Decode CustomData from Base64.
99
+
Provisioning.DecodeCustomData=n
101
+
# Execute CustomData after provisioning.
102
+
Provisioning.ExecuteCustomData=n
104
+
# Format if unformatted. If 'n', resource disk will not be mounted.
105
+
ResourceDisk.Format=y
107
+
# File system on the resource disk
108
+
# Typically ext3 or ext4. FreeBSD images should use 'ufs2' here.
109
+
ResourceDisk.Filesystem=ext4
111
+
# Mount point for the resource disk
112
+
ResourceDisk.MountPoint=/mnt/resource
114
+
# Respond to load balancer probes if requested by Windows Azure.
117
+
# Enable logging to serial console (y|n)
118
+
# When stdout is not enough...
122
+
# Enable verbose logging (y|n)
125
+
# Root device timeout in seconds.
126
+
OS.RootDeviceScsiTimeout=300
129
+
services.udev.packages = [ waagent ];
131
+
networking.dhcpcd.persistent = true;
133
+
services.logrotate = {
136
+
/var/log/waagent.log {
146
+
systemd.targets.provisioned = {
147
+
description = "Services Requiring Azure VM provisioning to have finished";
148
+
wantedBy = [ "sshd.service" ];
149
+
before = [ "sshd.service" ];
153
+
systemd.services.waagent = {
154
+
wantedBy = [ "sshd.service" ];
155
+
before = [ "sshd.service" ];
156
+
after = [ "ip-up.target" ];
157
+
wants = [ "ip-up.target" ];
159
+
path = [ pkgs.e2fsprogs ];
160
+
description = "Windows Azure Agent Service";
161
+
unitConfig.ConditionPathExists = "/etc/waagent.conf";
163
+
ExecStart = "${waagent}/bin/waagent -daemon";