2015-12-09 06:30:15 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.virtualisation.azure.agent;
|
|
|
|
|
|
|
|
provisionedHook = pkgs.writeScript "provisioned-hook" ''
|
2018-03-01 20:38:53 +01:00
|
|
|
#!${pkgs.runtimeShell}
|
2020-05-21 10:34:11 +02:00
|
|
|
/run/current-system/systemd/bin/systemctl start provisioned.target
|
2015-12-09 06:30:15 +01:00
|
|
|
'';
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
2016-03-11 08:15:52 +01:00
|
|
|
options.virtualisation.azure.agent = {
|
|
|
|
enable = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = lib.mdDoc "Whether to enable the Windows Azure Linux Agent.";
|
|
|
|
};
|
|
|
|
verboseLogging = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = lib.mdDoc "Whether to enable verbose logging.";
|
|
|
|
};
|
2018-04-17 16:04:04 +02:00
|
|
|
mountResourceDisk = mkOption {
|
|
|
|
default = true;
|
|
|
|
description = lib.mdDoc "Whether the agent should format (ext4) and mount the resource disk to /mnt/resource.";
|
|
|
|
};
|
2015-12-09 06:30:15 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
2023-01-10 20:58:20 +01:00
|
|
|
config = lib.mkIf cfg.enable {
|
|
|
|
assertions = [{
|
2021-11-21 02:50:41 +01:00
|
|
|
assertion = pkgs.stdenv.hostPlatform.isx86;
|
2018-08-20 21:11:29 +02:00
|
|
|
message = "Azure not currently supported on ${pkgs.stdenv.hostPlatform.system}";
|
2023-01-10 20:58:20 +01:00
|
|
|
}
|
|
|
|
{
|
|
|
|
assertion = config.networking.networkmanager.enable == false;
|
|
|
|
message = "Windows Azure Linux Agent is not compatible with NetworkManager";
|
|
|
|
}];
|
2015-12-09 06:30:15 +01:00
|
|
|
|
|
|
|
boot.initrd.kernelModules = [ "ata_piix" ];
|
|
|
|
networking.firewall.allowedUDPPorts = [ 68 ];
|
|
|
|
|
|
|
|
|
|
|
|
environment.etc."waagent.conf".text = ''
|
|
|
|
#
|
2023-01-10 20:58:20 +01:00
|
|
|
# Microsoft Azure Linux Agent Configuration
|
2015-12-09 06:30:15 +01:00
|
|
|
#
|
|
|
|
|
2023-01-10 20:58:20 +01:00
|
|
|
# Enable extension handling. Do not disable this unless you do not need password reset,
|
|
|
|
# backup, monitoring, or any extension handling whatsoever.
|
|
|
|
Extensions.Enabled=y
|
2015-12-09 06:30:15 +01:00
|
|
|
|
2023-01-10 20:58:20 +01:00
|
|
|
# How often (in seconds) to poll for new goal states
|
|
|
|
Extensions.GoalStatePeriod=6
|
|
|
|
|
|
|
|
# Which provisioning agent to use. Supported values are "auto" (default), "waagent",
|
|
|
|
# "cloud-init", or "disabled".
|
|
|
|
Provisioning.Agent=disabled
|
2015-12-09 06:30:15 +01:00
|
|
|
|
|
|
|
# Password authentication for root account will be unavailable.
|
|
|
|
Provisioning.DeleteRootPassword=n
|
|
|
|
|
|
|
|
# Generate fresh host key pair.
|
2016-03-11 08:15:52 +01:00
|
|
|
Provisioning.RegenerateSshHostKeyPair=n
|
2015-12-09 06:30:15 +01:00
|
|
|
|
2023-01-10 20:58:20 +01:00
|
|
|
# Supported values are "rsa", "dsa", "ecdsa", "ed25519", and "auto".
|
|
|
|
# The "auto" option is supported on OpenSSH 5.9 (2011) and later.
|
2015-12-09 06:30:15 +01:00
|
|
|
Provisioning.SshHostKeyPairType=ed25519
|
|
|
|
|
|
|
|
# Monitor host name changes and publish changes via DHCP requests.
|
|
|
|
Provisioning.MonitorHostName=y
|
|
|
|
|
2023-01-10 20:58:20 +01:00
|
|
|
# How often (in seconds) to monitor host name changes.
|
|
|
|
Provisioning.MonitorHostNamePeriod=30
|
|
|
|
|
2015-12-09 06:30:15 +01:00
|
|
|
# Decode CustomData from Base64.
|
|
|
|
Provisioning.DecodeCustomData=n
|
|
|
|
|
|
|
|
# Execute CustomData after provisioning.
|
|
|
|
Provisioning.ExecuteCustomData=n
|
|
|
|
|
2023-01-10 20:58:20 +01:00
|
|
|
# Algorithm used by crypt when generating password hash.
|
|
|
|
#Provisioning.PasswordCryptId=6
|
|
|
|
|
|
|
|
# Length of random salt used when generating password hash.
|
|
|
|
#Provisioning.PasswordCryptSaltLength=10
|
|
|
|
|
|
|
|
# Allow reset password of sys user
|
|
|
|
Provisioning.AllowResetSysUser=n
|
|
|
|
|
2015-12-09 06:30:15 +01:00
|
|
|
# Format if unformatted. If 'n', resource disk will not be mounted.
|
2018-04-17 16:04:04 +02:00
|
|
|
ResourceDisk.Format=${if cfg.mountResourceDisk then "y" else "n"}
|
2015-12-09 06:30:15 +01:00
|
|
|
|
|
|
|
# File system on the resource disk
|
|
|
|
# Typically ext3 or ext4. FreeBSD images should use 'ufs2' here.
|
|
|
|
ResourceDisk.Filesystem=ext4
|
|
|
|
|
|
|
|
# Mount point for the resource disk
|
|
|
|
ResourceDisk.MountPoint=/mnt/resource
|
|
|
|
|
2023-01-10 20:58:20 +01:00
|
|
|
# Create and use swapfile on resource disk.
|
|
|
|
ResourceDisk.EnableSwap=n
|
|
|
|
|
|
|
|
# Size of the swapfile.
|
|
|
|
ResourceDisk.SwapSizeMB=0
|
2015-12-09 06:30:15 +01:00
|
|
|
|
2023-01-10 20:58:20 +01:00
|
|
|
# Comma-separated list of mount options. See mount(8) for valid options.
|
|
|
|
ResourceDisk.MountOptions=None
|
2015-12-09 06:30:15 +01:00
|
|
|
|
|
|
|
# Enable verbose logging (y|n)
|
2016-03-11 08:15:52 +01:00
|
|
|
Logs.Verbose=${if cfg.verboseLogging then "y" else "n"}
|
2015-12-09 06:30:15 +01:00
|
|
|
|
2023-01-10 20:58:20 +01:00
|
|
|
# Enable Console logging, default is y
|
|
|
|
# Logs.Console=y
|
|
|
|
|
|
|
|
# Enable periodic log collection, default is n
|
|
|
|
Logs.Collect=n
|
|
|
|
|
|
|
|
# How frequently to collect logs, default is each hour
|
|
|
|
Logs.CollectPeriod=3600
|
|
|
|
|
|
|
|
# Is FIPS enabled
|
|
|
|
OS.EnableFIPS=n
|
|
|
|
|
2015-12-09 06:30:15 +01:00
|
|
|
# Root device timeout in seconds.
|
|
|
|
OS.RootDeviceScsiTimeout=300
|
2023-01-10 20:58:20 +01:00
|
|
|
|
|
|
|
# How often (in seconds) to set the root device timeout.
|
|
|
|
OS.RootDeviceScsiTimeoutPeriod=30
|
|
|
|
|
|
|
|
# If "None", the system default version is used.
|
|
|
|
OS.OpensslPath=${pkgs.openssl_3.bin}/bin/openssl
|
|
|
|
|
|
|
|
# Set the SSH ClientAliveInterval
|
|
|
|
# OS.SshClientAliveInterval=180
|
|
|
|
|
|
|
|
# Set the path to SSH keys and configuration files
|
|
|
|
OS.SshDir=/etc/ssh
|
|
|
|
|
|
|
|
# If set, agent will use proxy server to access internet
|
|
|
|
#HttpProxy.Host=None
|
|
|
|
#HttpProxy.Port=None
|
|
|
|
|
|
|
|
# Detect Scvmm environment, default is n
|
|
|
|
# DetectScvmmEnv=n
|
|
|
|
|
|
|
|
#
|
|
|
|
# Lib.Dir=/var/lib/waagent
|
|
|
|
|
|
|
|
#
|
|
|
|
# DVD.MountPoint=/mnt/cdrom/secure
|
|
|
|
|
|
|
|
#
|
|
|
|
# Pid.File=/var/run/waagent.pid
|
|
|
|
|
|
|
|
#
|
|
|
|
# Extension.LogDir=/var/log/azure
|
|
|
|
|
|
|
|
#
|
|
|
|
# Home.Dir=/home
|
|
|
|
|
|
|
|
# Enable RDMA management and set up, should only be used in HPC images
|
|
|
|
OS.EnableRDMA=n
|
|
|
|
|
|
|
|
# Enable checking RDMA driver version and update
|
|
|
|
# OS.CheckRdmaDriver=y
|
|
|
|
|
|
|
|
# Enable or disable goal state processing auto-update, default is enabled
|
|
|
|
AutoUpdate.Enabled=n
|
|
|
|
|
|
|
|
# Determine the update family, this should not be changed
|
|
|
|
# AutoUpdate.GAFamily=Prod
|
|
|
|
|
|
|
|
# Determine if the overprovisioning feature is enabled. If yes, hold extension
|
|
|
|
# handling until inVMArtifactsProfile.OnHold is false.
|
|
|
|
# Default is enabled
|
|
|
|
EnableOverProvisioning=n
|
|
|
|
|
|
|
|
# Allow fallback to HTTP if HTTPS is unavailable
|
|
|
|
# Note: Allowing HTTP (vs. HTTPS) may cause security risks
|
|
|
|
# OS.AllowHTTP=n
|
|
|
|
|
|
|
|
# Add firewall rules to protect access to Azure host node services
|
|
|
|
OS.EnableFirewall=n
|
|
|
|
|
|
|
|
# How often (in seconds) to check the firewall rules
|
|
|
|
OS.EnableFirewallPeriod=30
|
|
|
|
|
|
|
|
# How often (in seconds) to remove the udev rules for persistent network interface
|
|
|
|
# names (75-persistent-net-generator.rules and /etc/udev/rules.d/70-persistent-net.rules)
|
|
|
|
OS.RemovePersistentNetRulesPeriod=30
|
|
|
|
|
|
|
|
# How often (in seconds) to monitor for DHCP client restarts
|
|
|
|
OS.MonitorDhcpClientRestartPeriod=30
|
2015-12-09 06:30:15 +01:00
|
|
|
'';
|
|
|
|
|
2023-01-10 20:58:20 +01:00
|
|
|
services.udev.packages = [ pkgs.waagent ];
|
2015-12-09 06:30:15 +01:00
|
|
|
|
|
|
|
networking.dhcpcd.persistent = true;
|
|
|
|
|
|
|
|
services.logrotate = {
|
|
|
|
enable = true;
|
2022-02-28 22:54:12 +01:00
|
|
|
settings."/var/log/waagent.log" = {
|
|
|
|
compress = true;
|
|
|
|
frequency = "monthly";
|
|
|
|
rotate = 6;
|
|
|
|
};
|
2015-12-09 06:30:15 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
systemd.targets.provisioned = {
|
|
|
|
description = "Services Requiring Azure VM provisioning to have finished";
|
|
|
|
};
|
|
|
|
|
2023-01-10 20:58:20 +01:00
|
|
|
systemd.services.consume-hypervisor-entropy =
|
|
|
|
{
|
|
|
|
description = "Consume entropy in ACPI table provided by Hyper-V";
|
|
|
|
|
|
|
|
wantedBy = [ "sshd.service" "waagent.service" ];
|
|
|
|
before = [ "sshd.service" "waagent.service" ];
|
|
|
|
|
|
|
|
path = [ pkgs.coreutils ];
|
|
|
|
script =
|
|
|
|
''
|
|
|
|
echo "Fetching entropy..."
|
|
|
|
cat /sys/firmware/acpi/tables/OEM0 > /dev/random
|
|
|
|
'';
|
|
|
|
serviceConfig.Type = "oneshot";
|
|
|
|
serviceConfig.RemainAfterExit = true;
|
|
|
|
serviceConfig.StandardError = "journal+console";
|
|
|
|
serviceConfig.StandardOutput = "journal+console";
|
|
|
|
};
|
2015-12-09 06:30:15 +01:00
|
|
|
|
|
|
|
systemd.services.waagent = {
|
2016-03-13 04:25:27 +01:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
2016-09-10 18:03:59 +02:00
|
|
|
after = [ "network-online.target" "sshd.service" ];
|
|
|
|
wants = [ "network-online.target" ];
|
2015-12-09 06:30:15 +01:00
|
|
|
|
2018-04-17 16:26:04 +02:00
|
|
|
path = [ pkgs.e2fsprogs pkgs.bash ];
|
2015-12-09 06:30:15 +01:00
|
|
|
description = "Windows Azure Agent Service";
|
|
|
|
unitConfig.ConditionPathExists = "/etc/waagent.conf";
|
|
|
|
serviceConfig = {
|
2023-01-10 20:58:20 +01:00
|
|
|
ExecStart = "${pkgs.waagent}/bin/waagent -daemon";
|
2015-12-09 06:30:15 +01:00
|
|
|
Type = "simple";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
}
|