From 5d094c2338d5fcf9c5e4b7071b8e66a8d7e0677a Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Fri, 18 Apr 2025 23:35:51 +0200 Subject: [PATCH] nixos/alloy: set After=network.target MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This prevents the network from being torn down before alloy itself it stopped. Alloy tries to flush its WAL on SIGTERM, and if the network stack is already down, it tries to flush logs up to 90s during shutdown/reboot. From https://www.freedesktop.org/wiki/Software/systemd/NetworkTarget/: > network.target has very little meaning during start-up. It only > indicates that the network management stack is up after it has been > reached. Whether any network interfaces are already configured when > it is reached is undefined. Its primary purpose is for ordering > things properly at shutdown: since the shutdown ordering of units in > systemd is the reverse of the startup ordering, any unit that is order > After=network.target can be sure that it is stopped before the network > is shut down if the system is powered off. This allows services to > cleanly terminate connections before going down, instead of abruptly > losing connectivity for ongoing connections, leaving them in an > undefined state. […] --- nixos/modules/services/monitoring/alloy.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/nixos/modules/services/monitoring/alloy.nix b/nixos/modules/services/monitoring/alloy.nix index 73f967addc91..fe0ed2cab8b3 100644 --- a/nixos/modules/services/monitoring/alloy.nix +++ b/nixos/modules/services/monitoring/alloy.nix @@ -65,6 +65,7 @@ in config = lib.mkIf cfg.enable { systemd.services.alloy = { + after = [ "network.target" ]; wantedBy = [ "multi-user.target" ]; reloadTriggers = lib.mapAttrsToList (_: v: v.source or null) ( lib.filterAttrs (n: _: lib.hasPrefix "alloy/" n && lib.hasSuffix ".alloy" n) config.environment.etc