diff --git a/nix/host-modules/swarm-otel.nix b/nix/host-modules/swarm-otel.nix index 2493f91c..d1e16055 100644 --- a/nix/host-modules/swarm-otel.nix +++ b/nix/host-modules/swarm-otel.nix @@ -700,6 +700,39 @@ in leaving both log destinations unset. ''; } + { + # The assertion above covers *which* units to collect; this one + # covers whether there is a journal on disk to collect them from. + # A `bindMounts` entry never creates its `hostPath`, and unlike + # the CA bind source above there is no unit to order after — the + # directory exists because journald was told to store + # persistently, or not at all. `auto` is deliberately not + # rejected: it uses the directory when it exists, and eval cannot + # see whether it does. + assertion = + !collectLogs + || !(lib.elem config.services.journald.storage [ + "volatile" + "none" + ]); + message = '' + The swarm collector is configured to ship journal logs, but + services.journald.storage is + "${config.services.journald.storage}" on this host. + + journald only writes ${hostJournalDir} when it stores + persistently: with "volatile" the journal lives in + /run/log/journal, and with "none" there is none at all. This + collector's journald receiver reads ${hostJournalDir} and the + container bind-mounts that path, so the collector would not + start at all — nixos-container refuses to start when a bind + source is missing. + + Set services.journald.storage = "persistent" (the NixOS + default), or turn off log collection by leaving both log + destinations unset. + ''; + } { # Without a roster there are no receivers at all, so this # collector would listen on nothing while looking configured.