tangled
alpha
login
or
join now
pyrox.dev
/
nixpkgs
0
fork
atom
lol
0
fork
atom
overview
issues
pulls
pipelines
Azure image: package and add azure agent
Evgeny Egorochkin
10 years ago
6db67186
2838161c
+173
2 changed files
expand all
collapse all
unified
split
nixos
modules
virtualisation
azure-agent.nix
azure-common.nix
+170
nixos/modules/virtualisation/azure-agent.nix
···
1
1
+
{ config, lib, pkgs, ... }:
2
2
+
3
3
+
with lib;
4
4
+
5
5
+
let
6
6
+
7
7
+
cfg = config.virtualisation.azure.agent;
8
8
+
9
9
+
waagent = with pkgs; stdenv.mkDerivation rec {
10
10
+
name = "waagent-2.0";
11
11
+
src = pkgs.fetchgit {
12
12
+
url = https://github.com/Phreedom/WALinuxAgent.git;
13
13
+
rev = "9dba81c7b1239c7971ec96e405e403c7cd224e6b";
14
14
+
sha256 = "0khxk3ns3z37v26f2qj6m3m698a0vqpc9bxg5p7fyr3xza5gzwhs";
15
15
+
};
16
16
+
buildInputs = [ makeWrapper python pythonPackages.wrapPython ];
17
17
+
runtimeDeps = [ findutils gnugrep gawk coreutils openssl openssh
18
18
+
nettools # for hostname
19
19
+
procps # for pidof
20
20
+
shadow # for useradd, usermod
21
21
+
utillinux # for (u)mount, fdisk, sfdisk, mkswap
22
22
+
parted
23
23
+
];
24
24
+
pythonPath = [ pythonPackages.pyasn1 ];
25
25
+
26
26
+
configurePhase = false;
27
27
+
buildPhase = false;
28
28
+
29
29
+
installPhase = ''
30
30
+
substituteInPlace config/99-azure-product-uuid.rules \
31
31
+
--replace /bin/chmod "${coreutils}/bin/chmod"
32
32
+
mkdir -p $out/lib/udev/rules.d
33
33
+
cp config/*.rules $out/lib/udev/rules.d
34
34
+
35
35
+
mkdir -p $out/bin
36
36
+
cp waagent $out/bin/
37
37
+
chmod +x $out/bin/waagent
38
38
+
39
39
+
wrapProgram "$out/bin/waagent" \
40
40
+
--prefix PYTHONPATH : $PYTHONPATH \
41
41
+
--prefix PATH : "${makeSearchPath "bin" runtimeDeps}"
42
42
+
'';
43
43
+
};
44
44
+
45
45
+
provisionedHook = pkgs.writeScript "provisioned-hook" ''
46
46
+
#!${pkgs.stdenv.shell}
47
47
+
${config.systemd.package}/bin/systemctl start provisioned.target
48
48
+
'';
49
49
+
50
50
+
in
51
51
+
52
52
+
{
53
53
+
54
54
+
###### interface
55
55
+
56
56
+
options.virtualisation.azure.agent.enable = mkOption {
57
57
+
default = false;
58
58
+
description = "Whether to enable the Windows Azure Linux Agent.";
59
59
+
};
60
60
+
61
61
+
###### implementation
62
62
+
63
63
+
config = mkIf cfg.enable {
64
64
+
assertions = [ {
65
65
+
assertion = pkgs.stdenv.isi686 || pkgs.stdenv.isx86_64;
66
66
+
message = "Azure not currently supported on ${pkgs.stdenv.system}";
67
67
+
} {
68
68
+
assertion = config.networking.networkmanager.enable == false;
69
69
+
message = "Windows Azure Linux Agent is not compatible with NetworkManager";
70
70
+
} ];
71
71
+
72
72
+
boot.initrd.kernelModules = [ "ata_piix" ];
73
73
+
networking.firewall.allowedUDPPorts = [ 68 ];
74
74
+
75
75
+
76
76
+
environment.etc."waagent.conf".text = ''
77
77
+
#
78
78
+
# Windows Azure Linux Agent Configuration
79
79
+
#
80
80
+
81
81
+
Role.StateConsumer=${provisionedHook}
82
82
+
83
83
+
# Enable instance creation
84
84
+
Provisioning.Enabled=y
85
85
+
86
86
+
# Password authentication for root account will be unavailable.
87
87
+
Provisioning.DeleteRootPassword=n
88
88
+
89
89
+
# Generate fresh host key pair.
90
90
+
Provisioning.RegenerateSshHostKeyPair=y
91
91
+
92
92
+
# Supported values are "rsa", "dsa" and "ecdsa".
93
93
+
Provisioning.SshHostKeyPairType=ed25519
94
94
+
95
95
+
# Monitor host name changes and publish changes via DHCP requests.
96
96
+
Provisioning.MonitorHostName=y
97
97
+
98
98
+
# Decode CustomData from Base64.
99
99
+
Provisioning.DecodeCustomData=n
100
100
+
101
101
+
# Execute CustomData after provisioning.
102
102
+
Provisioning.ExecuteCustomData=n
103
103
+
104
104
+
# Format if unformatted. If 'n', resource disk will not be mounted.
105
105
+
ResourceDisk.Format=y
106
106
+
107
107
+
# File system on the resource disk
108
108
+
# Typically ext3 or ext4. FreeBSD images should use 'ufs2' here.
109
109
+
ResourceDisk.Filesystem=ext4
110
110
+
111
111
+
# Mount point for the resource disk
112
112
+
ResourceDisk.MountPoint=/mnt/resource
113
113
+
114
114
+
# Respond to load balancer probes if requested by Windows Azure.
115
115
+
LBProbeResponder=y
116
116
+
117
117
+
# Enable logging to serial console (y|n)
118
118
+
# When stdout is not enough...
119
119
+
# 'y' if not set
120
120
+
Logs.Console=y
121
121
+
122
122
+
# Enable verbose logging (y|n)
123
123
+
Logs.Verbose=n
124
124
+
125
125
+
# Root device timeout in seconds.
126
126
+
OS.RootDeviceScsiTimeout=300
127
127
+
'';
128
128
+
129
129
+
services.udev.packages = [ waagent ];
130
130
+
131
131
+
networking.dhcpcd.persistent = true;
132
132
+
133
133
+
services.logrotate = {
134
134
+
enable = true;
135
135
+
config = ''
136
136
+
/var/log/waagent.log {
137
137
+
compress
138
138
+
monthly
139
139
+
rotate 6
140
140
+
notifempty
141
141
+
missingok
142
142
+
}
143
143
+
'';
144
144
+
};
145
145
+
146
146
+
systemd.targets.provisioned = {
147
147
+
description = "Services Requiring Azure VM provisioning to have finished";
148
148
+
wantedBy = [ "sshd.service" ];
149
149
+
before = [ "sshd.service" ];
150
150
+
};
151
151
+
152
152
+
153
153
+
systemd.services.waagent = {
154
154
+
wantedBy = [ "sshd.service" ];
155
155
+
before = [ "sshd.service" ];
156
156
+
after = [ "ip-up.target" ];
157
157
+
wants = [ "ip-up.target" ];
158
158
+
159
159
+
path = [ pkgs.e2fsprogs ];
160
160
+
description = "Windows Azure Agent Service";
161
161
+
unitConfig.ConditionPathExists = "/etc/waagent.conf";
162
162
+
serviceConfig = {
163
163
+
ExecStart = "${waagent}/bin/waagent -daemon";
164
164
+
Type = "simple";
165
165
+
};
166
166
+
};
167
167
+
168
168
+
};
169
169
+
170
170
+
}
+3
nixos/modules/virtualisation/azure-common.nix
···
4
4
{
5
5
imports = [ ../profiles/headless.nix ];
6
6
7
7
+
require = [ ./azure-agent.nix ];
8
8
+
virtualisation.azure.agent.enable = true;
9
9
+
7
10
boot.kernelParams = [ "console=ttyS0" "earlyprintk=ttyS0" "rootdelay=300" "panic=1" "boot.panic_on_fail" ];
8
11
boot.initrd.kernelModules = [ "hv_vmbus" "hv_netvsc" "hv_utils" "hv_storvsc" ];
9
12