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

amazon-ec2-net-utils: init at 2.5.2 #355111

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

commiterate
Copy link
Contributor

@commiterate commiterate commented Nov 11, 2024

Initialize amazon-ec2-net-utils at 2.5.2.

This includes udev rules which create systemd units and timers for refreshing systemd-networkd policies for Elastic Network Interfaces (ENIs) which can be hot-attached/detached.

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/)
  • 24.11 Release Notes (or backporting 23.11 and 24.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: documentation This PR adds or changes documentation 8.has: changelog 8.has: module (update) This PR changes an existing module in `nixos/` labels Nov 11, 2024
@commiterate commiterate force-pushed the init/amazon-ec2-net-utils branch 3 times, most recently from 35b20bc to 92d48af Compare November 11, 2024 02:31
@h7x4 h7x4 added the 8.has: module (new) This PR adds a module in `nixos/` label Nov 11, 2024
@ofborg ofborg bot added 8.has: package (new) This PR adds a new package 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 1-10 labels Nov 11, 2024
@commiterate commiterate force-pushed the init/amazon-ec2-net-utils branch from 92d48af to d5907ec Compare November 11, 2024 17:23
@commiterate commiterate force-pushed the init/amazon-ec2-net-utils branch 3 times, most recently from e7ce8c4 to 9a1df5d Compare November 11, 2024 18:16
startLimitIntervalSec = 10;
startLimitBurst = 5;
wants = [ "refresh-policy-routes@%i.timer" ];
# TODO: Need [Install] for Also = "refresh-policy-routes@%i.timer". systemd.services.<name> has no installConfig attribute.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Need to update nixos/lib/systemd*.nix to add an installConfig attribute to systemd.services.<name>.

Copy link
Contributor Author

@commiterate commiterate Nov 11, 2024

Choose a reason for hiding this comment

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

@dasJ @ElvishJerricco Do either of you happen to know if just making the NixOS systemd libs add in a user-specified [Install] section is good enough, or is there something specific about how NixOS handles systemd units that may create complications?

For context, amazon-ec2-net-utils relies on systemd template units. When a network interface is hot-attached/detached, the udev rules will create/delete per-interface systemd service + timer units which update systemd-networkd policies and reload systemd-networkd.

https://github.com/amazonlinux/amazon-ec2-net-utils/blob/v2.5.1/udev/99-vpc-policy-routes.rules

Copy link
Contributor

Choose a reason for hiding this comment

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

@commiterate [Install] does absolutely nothing on NixOS. That's why you'll see wantedBy defined in most services in nixos modules. We populate [Install] with the contents of the wantedBy option and its friends, but that's largely for illustrative purposes; we don't actually use the [Install] section. We've thought about changing that, but it hasn't been done yet.

Copy link
Contributor Author

@commiterate commiterate Nov 19, 2024

Choose a reason for hiding this comment

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

Good to know. Would packaging up the patched systemd units into $out and using systemd.packages = [ pkgs.amazon-ec2-net-utils ]; as suggested work around that?

Copy link
Contributor

@ElvishJerricco ElvishJerricco Nov 19, 2024

Choose a reason for hiding this comment

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

Even the [Install] sections of units from systemd.packages are ignored in NixOS. But, AFAICT, the [Install] sections of those upstream units are doing absolutely nothing anyway. The only thing that [Install] does is create Wants= dependencies and its friends by creating /etc/systemd/system/*.wants/* symlinks when systemctl enable is run. e.g. Having WantedBy=foo.service in the [Install] section of bar.service means that running systemctl enable bar.service will create /etc/systemd/system/foo.service.wants/bar.service -> ../bar.service.

Of course this isn't a thing on NixOS; we create those statically during system build via the systemd.$unittype.$name.wantedBy options and its friends. The Also= directive just means that when you run systemctl enable bar.service, it also does the enable operation for anything in Also=. Given that none of the units in the upstream amazon-ec2-net-utils source tree do anything like WantedBy= in their [Install] sections, that means it all does effectively nothing.

Now, I've just realized that what that udev rule does is marvelously stupid. It runs systemctl enable/disable --now on those units. This is really poorly done. First of all, as I've just discussed, the enable operation will have no effect for these units normally. But if it did, it wouldn't work on NixOS thanks to the immutable store and /etc/systemd/system/. But the --now flag causes the units to be started/stopped too. So really that udev rule should be using start and stop, not enable and disable.

Wow. Really badly done by the amazon folks. enable/disable is supposed to be an administrator's decision, not the vendor's.

You'll want to fix the rule to not be stupid, and then merely adding the upstream units to systemd.packages (with patched paths) will work.

Copy link
Contributor Author

@commiterate commiterate Nov 19, 2024

Choose a reason for hiding this comment

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

Yup, will need to get that fixed upstream.

Will swap this PR back to draft in the meanwhile as I figure out what to do. Doesn't make sense to merge this package until the systemd stuff it provides is usable.

Copy link
Member

@arianvp arianvp Nov 19, 2024

Choose a reason for hiding this comment

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

Instead of systemctl start/enable, they could use https://www.freedesktop.org/software/systemd/man/latest/systemd.device.html#SYSTEMD_WANTS= in the udev rule.

But i think this has the downside it will never stop the unit. Only start .

So they probably still want systemctl start

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think removal works as long as you tag the remove udev rule as well.

systemd/systemd#7587 (comment)

Copy link
Member

@arianvp arianvp Nov 19, 2024

Choose a reason for hiding this comment

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

Actually I think systemctl enable --now might work fine if the service has no WantedBy in the install section (which is the case). It will just silently degrade to systemctl start and systemctl stop

I think we can use these udev rules as is without problems

Copy link
Contributor Author

@commiterate commiterate Nov 19, 2024

Choose a reason for hiding this comment

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

Opened an issue upstream requesting a swap to systemd device units.

amazonlinux/amazon-ec2-net-utils#112

@commiterate commiterate force-pushed the init/amazon-ec2-net-utils branch 4 times, most recently from 7d08481 to e221f80 Compare November 11, 2024 19:54
@commiterate commiterate force-pushed the init/amazon-ec2-net-utils branch from e221f80 to d838d9d Compare November 11, 2024 20:14
@commiterate commiterate force-pushed the init/amazon-ec2-net-utils branch 3 times, most recently from de158a4 to 0f3be63 Compare November 19, 2024 00:20
Copy link
Contributor

@ElvishJerricco ElvishJerricco left a comment

Choose a reason for hiding this comment

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

I think if I were you, I'd have the package copy those systemd units from the source tree into $out, patch up the paths to point to the nix store paths, and use systemd.packages = [ pkgs.amazon-ec2-net-utils ]; rather than duplicating the units in nix.

@commiterate commiterate force-pushed the init/amazon-ec2-net-utils branch from 0f3be63 to 8ed8c0f Compare November 19, 2024 04:22
@github-actions github-actions bot removed the 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS label Nov 19, 2024
@github-actions github-actions bot removed 8.has: documentation This PR adds or changes documentation 8.has: changelog 8.has: module (update) This PR changes an existing module in `nixos/` labels Nov 19, 2024
@commiterate commiterate marked this pull request as ready for review November 19, 2024 04:22
@commiterate
Copy link
Contributor Author

Might want to add NixOS tests that check if the template units are available when this package is added to the systemd.packages NixOS option. I think there's some systemd-related helpers in the NixOS test utilities.

@ElvishJerricco
Copy link
Contributor

Might want to add NixOS tests that check if the template units are available when this package is added to the systemd.packages NixOS option. I think there's some systemd-related helpers in the NixOS test utilities.

@commiterate That would be overkill. That's covered by the existing systemd test suite.

@commiterate commiterate force-pushed the init/amazon-ec2-net-utils branch from d754971 to 5b1abd0 Compare December 15, 2024 17:40
@commiterate commiterate changed the title amazon-ec2-net-utils: init at 2.5.1 amazon-ec2-net-utils: init at 2.5.2 Dec 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
8.has: module (new) This PR adds a module in `nixos/` 8.has: package (new) This PR adds a new package 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 1-10
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants