Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nixos/waagent: init module #362101

Merged
merged 4 commits into from
Dec 12, 2024
Merged

nixos/waagent: init module #362101

merged 4 commits into from
Dec 12, 2024

Conversation

codgician
Copy link
Member

@codgician codgician commented Dec 5, 2024

Adds a module for waagent (Windows Azure Linux Agent), providing services.waagent option. With this change, the options available in waagent.conf could be defined using services.waagent.settings, which fix #272460.

The format of waagent.settings follow: https://learn.microsoft.com/en-us/azure/virtual-machines/extensions/agent-linux#configuration:

  • Typed options included in the module are a subset of the publicly documented ones in above link. I left out ones that may not be properly supported in NixOS due to its immutable nature (mostly Provisioning options, and they should be covered by cloud-init anyway in default configuration).
  • Users are still able to declare these options due to settings has a type of freeform.

Below provides an example of services.waagent (used as test) with further explanations in comments:

services.waagent = {
  enable = true;
  package = pkgs.waagent;
  # Allow defining extraPackages to add binaries into waagent's PATH environment
  extraPackages = [ pkgs.btrfs-progs ];
  # Settings are kept in alignment of waagent.conf options.
  # Undocumented options that are not explicitly defined in the module are also accepted for flexibility.
  settings = {
    Provisioning = {
      # Boolean values will be converted to "y" or "n"
      Enable = false;
      Agent = "waagent";
      DeleteRootPassword = false;
      RegenerateSshHostKeyPair = false;
      SshHostKeyPairType = "ed25519";
      MonitorHostName = false;
    };
    ResourceDisk = {
      Format = false;
      # List values will be concatenated with comma
      MountOptions = [
        "compress=lzo"
        "mode=0600"
      ];
    };

    # int values will also be converted to string
    OS.RootDeviceScsiTimeout = 300;

    # null values will make the option omitted in generated waagent.conf
    HttpProxy = {
      Host = null;
      Port = null;
    };

    CGroups = {
      # Declaring undocumented options are also supported
      EnforceLimits = false;
      # Empty lists will also be omitted
      Excluded = [];
    };
  };
};

The resulting /etc/waagent.conf of above definition should be:

AutoUpdate.Enable=n
CGroups.EnforceLimits=n
Logs.Verbose=n 
OS.EnableRDMA=n
OS.RootDeviceScsiTimeout=300
Provisioning.Agent=waagent
Provisioning.DeleteRootPassword=n
Provisioning.Enable=n
Provisioning.MonitorHostName=n
Provisioning.RegenerateSshHostKeyPair=n 
Provisioning.SshHostKeyPairType=ed25519
ResourceDisk.EnableSwap=n
ResourceDisk.FileSystem=ext4
ResourceDisk.Format=n
ResourceDisk.MountOptions=compress=lzo,mode=0600
ResourceDisk.MountPoint=/mnt/resource
ResourceDisk.SwapSizeMB=0

Some other notable changes include:

  • Updated waagent.service definition referencing unit tests of Azure/WALinuxAgent
  • Added deprecation warning for existing azure-agent.nix (which is not imported automatically).
  • Added test for ensuring the correctness of generated /etc/waagent.conf.
  • Added passthru.updateScript for waagent package, and added myself as maintainer.

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 25.05 Release Notes (or backporting 24.11 and 25.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@github-actions github-actions bot added 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` labels Dec 5, 2024
@github-actions github-actions bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 1-10 labels Dec 5, 2024
@codgician codgician force-pushed the waagent-module branch 2 times, most recently from cc57a8d to 45c2def Compare December 6, 2024 08:05
@github-actions github-actions bot added 8.has: documentation This PR adds or changes documentation 8.has: changelog labels Dec 6, 2024
@codgician codgician force-pushed the waagent-module branch 7 times, most recently from 81f3397 to fa1c48a Compare December 6, 2024 15:20
@codgician codgician marked this pull request as ready for review December 6, 2024 15:21
@codgician codgician requested review from drupol and getchoo December 6, 2024 15:24
@codgician codgician requested a review from flokli December 6, 2024 15:29
@codgician
Copy link
Member Author

@ofborg build waagent

@FliegendeWurst FliegendeWurst changed the title waagent: init module nixos/waagent: init module Dec 7, 2024
Copy link
Member

@getchoo getchoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not very familiar with anything Azure, so I'm not sure how much help I can be -- but here are some issues I found on the Nix code side. Everything else looks good at a glance

nixos/doc/manual/release-notes/rl-2505.section.md Outdated Show resolved Hide resolved
nixos/modules/virtualisation/waagent.nix Outdated Show resolved Hide resolved
@@ -63,14 +65,24 @@ python.pkgs.buildPythonApplication rec {

dontWrapPythonPrograms = false;

meta = {
passthru = {
tests = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
tests = {
tests = lib.optionalAttrs stdenv.hostPlatform.isLinux {

These prevents OfBorg from attempting to evaluate and build this test on non-Linux platforms (where it will never work)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the latest iteration I added meta.platforms = lib.platforms.linux; to make this package Linux-only, as the project does not support Darwin officially.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

passthru.tests are still evaluated on Darwin regardless IIRC

pkgs/by-name/wa/waagent/package.nix Outdated Show resolved Hide resolved
@codgician
Copy link
Member Author

@ofborg build waagent

@codgician
Copy link
Member Author

@ofborg build waagent

@codgician codgician requested a review from getchoo December 8, 2024 06:45
@h7x4 h7x4 added 8.has: module (new) This PR adds a module in `nixos/` 8.has: tests This PR has tests labels Dec 8, 2024
@ofborg ofborg bot added 2.status: merge conflict This PR has merge conflicts with the target branch 8.has: clean-up and removed 2.status: merge conflict This PR has merge conflicts with the target branch labels Dec 8, 2024
Copy link
Member

@getchoo getchoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how to test this, but everything LGTM

Should probably have someone else actually test it before a merge, though :p

@getchoo getchoo added the 12.approvals: 1 This PR was reviewed and approved by one reputable person label Dec 8, 2024
@codgician
Copy link
Member Author

Not sure how to test this, but everything LGTM

Should probably have someone else actually test it before a merge, though :p

I did some quick tests on my existing Azure VM and made sure it is compatible with existing configurations.

If anyone is interested one can fork codgician:azure-aarch64-nixos and change the flake's nixpkgs input to the branch of this PR for generating a new vhdx to upload and validate with new Azure VM.

@flokli flokli merged commit 4e7a971 into NixOS:master Dec 12, 2024
45 of 47 checks passed
@flokli
Copy link
Contributor

flokli commented Dec 12, 2024

Let's get this in! Thanks for the work.

@camelpunch
Copy link
Contributor

Hey there! We found that after this change, OpenSSL errors prevented new machines from completing their provisioning. The openssl binary was expected to be at /usr/bin/openssl.

The fix for us was to set:

services.waagent.settings.OS.OpensslPath = "${pkgs.openssl}/bin/openssl";

Not sure where the fix should go: perhaps a rewrite of /usr/bin/openssl paths, or this setting always applied to the config unless it's changed away from a default?

@flokli
Copy link
Contributor

flokli commented Jan 20, 2025

We already add openssl to the $PATH of waagent. Ideally we can patch waagent source to pick it up from there.

@codgician
Copy link
Member Author

codgician commented Jan 20, 2025

Hey there! We found that after this change, OpenSSL errors prevented new machines from completing their provisioning. The openssl binary was expected to be at /usr/bin/openssl.

The fix for us was to set:

services.waagent.settings.OS.OpensslPath = "${pkgs.openssl}/bin/openssl";

Not sure where the fix should go: perhaps a rewrite of /usr/bin/openssl paths, or this setting always applied to the config unless it's changed away from a default?

This is intended to be fixed with #359365, where a default value of ervices.waagent.settings.OS.OpensslPath would be added.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: changelog 8.has: clean-up 8.has: documentation This PR adds or changes documentation 8.has: module (new) This PR adds a module in `nixos/` 8.has: module (update) This PR changes an existing module in `nixos/` 8.has: tests This PR has tests 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 1-10 12.approvals: 1 This PR was reviewed and approved by one reputable person
Projects
None yet
Development

Successfully merging this pull request may close these issues.

azure-agent: waagent.conf is hardcoded
5 participants