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