1 { config, lib, pkgs, ... }:
6 cfg = config.virtualisation.azure.agent;
8 provisionedHook = pkgs.writeScript "provisioned-hook" ''
10 /run/current-system/systemd/bin/systemctl start provisioned.target
19 options.virtualisation.azure.agent = {
22 description = lib.mdDoc "Whether to enable the Windows Azure Linux Agent.";
24 verboseLogging = mkOption {
26 description = lib.mdDoc "Whether to enable verbose logging.";
28 mountResourceDisk = mkOption {
30 description = lib.mdDoc "Whether the agent should format (ext4) and mount the resource disk to /mnt/resource.";
36 config = lib.mkIf cfg.enable {
38 assertion = pkgs.stdenv.hostPlatform.isx86;
39 message = "Azure not currently supported on ${pkgs.stdenv.hostPlatform.system}";
42 assertion = config.networking.networkmanager.enable == false;
43 message = "Windows Azure Linux Agent is not compatible with NetworkManager";
46 boot.initrd.kernelModules = [ "ata_piix" ];
47 networking.firewall.allowedUDPPorts = [ 68 ];
50 environment.etc."waagent.conf".text = ''
52 # Microsoft Azure Linux Agent Configuration
55 # Enable extension handling. Do not disable this unless you do not need password reset,
56 # backup, monitoring, or any extension handling whatsoever.
59 # How often (in seconds) to poll for new goal states
60 Extensions.GoalStatePeriod=6
62 # Which provisioning agent to use. Supported values are "auto" (default), "waagent",
63 # "cloud-init", or "disabled".
64 Provisioning.Agent=auto
66 # Password authentication for root account will be unavailable.
67 Provisioning.DeleteRootPassword=n
69 # Generate fresh host key pair.
70 Provisioning.RegenerateSshHostKeyPair=n
72 # Supported values are "rsa", "dsa", "ecdsa", "ed25519", and "auto".
73 # The "auto" option is supported on OpenSSH 5.9 (2011) and later.
74 Provisioning.SshHostKeyPairType=ed25519
76 # Monitor host name changes and publish changes via DHCP requests.
77 Provisioning.MonitorHostName=y
79 # How often (in seconds) to monitor host name changes.
80 Provisioning.MonitorHostNamePeriod=30
82 # Decode CustomData from Base64.
83 Provisioning.DecodeCustomData=n
85 # Execute CustomData after provisioning.
86 Provisioning.ExecuteCustomData=n
88 # Algorithm used by crypt when generating password hash.
89 #Provisioning.PasswordCryptId=6
91 # Length of random salt used when generating password hash.
92 #Provisioning.PasswordCryptSaltLength=10
94 # Allow reset password of sys user
95 Provisioning.AllowResetSysUser=n
97 # Format if unformatted. If 'n', resource disk will not be mounted.
98 ResourceDisk.Format=${if cfg.mountResourceDisk then "y" else "n"}
100 # File system on the resource disk
101 # Typically ext3 or ext4. FreeBSD images should use 'ufs2' here.
102 ResourceDisk.Filesystem=ext4
104 # Mount point for the resource disk
105 ResourceDisk.MountPoint=/mnt/resource
107 # Create and use swapfile on resource disk.
108 ResourceDisk.EnableSwap=n
110 # Size of the swapfile.
111 ResourceDisk.SwapSizeMB=0
113 # Comma-separated list of mount options. See mount(8) for valid options.
114 ResourceDisk.MountOptions=None
116 # Enable verbose logging (y|n)
117 Logs.Verbose=${if cfg.verboseLogging then "y" else "n"}
119 # Enable Console logging, default is y
122 # Enable periodic log collection, default is n
125 # How frequently to collect logs, default is each hour
126 Logs.CollectPeriod=3600
131 # Root device timeout in seconds.
132 OS.RootDeviceScsiTimeout=300
134 # How often (in seconds) to set the root device timeout.
135 OS.RootDeviceScsiTimeoutPeriod=30
137 # If "None", the system default version is used.
138 OS.OpensslPath=${pkgs.openssl_3.bin}/bin/openssl
140 # Set the SSH ClientAliveInterval
141 # OS.SshClientAliveInterval=180
143 # Set the path to SSH keys and configuration files
146 # If set, agent will use proxy server to access internet
150 # Detect Scvmm environment, default is n
154 # Lib.Dir=/var/lib/waagent
157 # DVD.MountPoint=/mnt/cdrom/secure
160 # Pid.File=/var/run/waagent.pid
163 # Extension.LogDir=/var/log/azure
168 # Enable RDMA management and set up, should only be used in HPC images
171 # Enable checking RDMA driver version and update
172 # OS.CheckRdmaDriver=y
174 # Enable or disable goal state processing auto-update, default is enabled
177 # Determine the update family, this should not be changed
178 # AutoUpdate.GAFamily=Prod
180 # Determine if the overprovisioning feature is enabled. If yes, hold extension
181 # handling until inVMArtifactsProfile.OnHold is false.
183 EnableOverProvisioning=n
185 # Allow fallback to HTTP if HTTPS is unavailable
186 # Note: Allowing HTTP (vs. HTTPS) may cause security risks
189 # Add firewall rules to protect access to Azure host node services
192 # How often (in seconds) to check the firewall rules
193 OS.EnableFirewallPeriod=30
195 # How often (in seconds) to remove the udev rules for persistent network interface
196 # names (75-persistent-net-generator.rules and /etc/udev/rules.d/70-persistent-net.rules)
197 OS.RemovePersistentNetRulesPeriod=30
199 # How often (in seconds) to monitor for DHCP client restarts
200 OS.MonitorDhcpClientRestartPeriod=30
203 services.udev.packages = [ pkgs.waagent ];
205 networking.dhcpcd.persistent = true;
207 services.logrotate = {
209 settings."/var/log/waagent.log" = {
211 frequency = "monthly";
216 systemd.targets.provisioned = {
217 description = "Services Requiring Azure VM provisioning to have finished";
220 systemd.services.consume-hypervisor-entropy =
222 description = "Consume entropy in ACPI table provided by Hyper-V";
224 wantedBy = [ "sshd.service" "waagent.service" ];
225 before = [ "sshd.service" "waagent.service" ];
227 path = [ pkgs.coreutils ];
230 echo "Fetching entropy..."
231 cat /sys/firmware/acpi/tables/OEM0 > /dev/random
233 serviceConfig.Type = "oneshot";
234 serviceConfig.RemainAfterExit = true;
235 serviceConfig.StandardError = "journal+console";
236 serviceConfig.StandardOutput = "journal+console";
239 systemd.services.waagent = {
240 wantedBy = [ "multi-user.target" ];
241 after = [ "network-online.target" "sshd.service" ];
242 wants = [ "network-online.target" ];
248 # waagent's Microsoft.OSTCExtensions.VMAccessForLinux needs Python 3
251 # waagent's Microsoft.CPlat.Core.RunCommandLinux needs lsof
254 description = "Windows Azure Agent Service";
255 unitConfig.ConditionPathExists = "/etc/waagent.conf";
257 ExecStart = "${pkgs.waagent}/bin/waagent -daemon";
262 # waagent will generate files under /etc/sudoers.d during provisioning
263 security.sudo.extraConfig = ''
264 #includedir /etc/sudoers.d