Repository navigation
Description
Describe the bug
The services.crowdsec NixOS module's ExecStartPre runs a crowdsec-setup script that unconditionally calls cscli hub update on every service start. In any environment without DNS at boot (hermetic nixos-test VMs, air-gapped deployments, first-boot before network-online.target is reached, networks with strict egress), this call fails. Because the setup script uses set -euo pipefail, the failure propagates and aborts service startup.
Once the bouncer-register service has run in this state, the failure becomes permanent via a DynamicUser + StateDirectory migration cascade. After that, the system cannot recover the service without manual filesystem cleanup.
This blocks pkgs.testers.nixosTest-based integration testing of the module and is observable on air-gapped or DNS-flaky-at-boot deployments.
Cascade
crowdsec.service'sExecStartPrerunscrowdsec-setup, which callscscli hub updateunconditionally (around lines 553–557 ofnixos/modules/services/security/crowdsec.nix).- In a hermetic environment, DNS fails →
cscli hub updateexits non-zero →set -euo pipefailaborts the script →crowdsec.servicestart fails. crowdsec-firewall-bouncer-register.serviceis configured withDynamicUser=true+StateDirectory=crowdsec. systemd'sStateDirectorysemantics see the pre-existing/var/lib/crowdsec(created by the upstream package) and migrate it to/var/lib/private/crowdsecunder the dynamic user.- Every subsequent invocation of
crowdsec-setupnow getsEACCESon/var/lib/crowdsec(the path the script still references — it was not aware of the DynamicUser migration). - The service is stuck in a fail loop until manual intervention.
Steps to reproduce
Minimal repro with pkgs.testers.nixosTest:
{ pkgs ? import <nixpkgs> {} }:
pkgs.testers.nixosTest {
name = "crowdsec-hermetic-repro";
nodes.machine = { ... }: {
services.crowdsec.enable = true;
services.crowdsec.allowLocalJournalAccess = true;
# No network in nixos-test VM by default — that's the trigger.
};
testScript = ''
machine.wait_for_unit("multi-user.target")
# crowdsec.service fails on ExecStartPre. Bouncer-register has run by now,
# so /var/lib/crowdsec is already migrated to /var/lib/private/crowdsec.
machine.succeed("systemctl status crowdsec.service || true")
'';
}The test driver hits its 900s timeout with crowdsec.service in activating or failed state.
Mitigation tried — does not help
Setting services.crowdsec.autoUpdateService = false was tried and is insufficient. That option only governs a separate daily timer (crowdsec-update-hub.service), not the unconditional hub update in crowdsec-setup's ExecStartPre. The fix has to address the ExecStartPre directly.
Proposed fixes (either or both)
(a) Make crowdsec-setup tolerant of offline boot. Wrap the cscli hub update call so that it logs a warning and continues on failure, rather than aborting. Hub updates that fail at boot can be retried by the daily crowdsec-update-hub.service once the network is available. The first-boot semantics should not be "fail closed" for an optional metadata refresh.
# Suggested shape — log on failure, continue
${cscli}/bin/cscli hub update || echo "crowdsec-setup: cscli hub update failed (will retry later)" >&2(b) Stop crowdsec-firewall-bouncer-register.service from claiming crowdsec as a StateDirectory. The bouncer-register's DynamicUser + StateDirectory=crowdsec migrates /var/lib/crowdsec away from where the rest of the module expects to find it. Either the bouncer-register should use its own state dir (e.g., crowdsec-firewall-bouncer) or drop DynamicUser on this service so the path stays canonical.
Fix (a) addresses the immediate hermetic-VM and air-gapped-boot scenarios. Fix (b) prevents the failure from being permanent once it has occurred.
Why this matters beyond hermetic tests
- Air-gapped deployments (industrial, healthcare, military) cannot use
services.crowdsectoday without manual workarounds. - First-boot-before-network deployments with DHCP delays hit this cascade.
- Networks with strict egress filtering (corporate, cloud VPCs without NAT) hit this cascade.
pkgs.testers.nixosTestintegration testing of any stack that includes CrowdSec is blocked.
Discovered via
Building a nixos-test for a Cloudflare-shaped self-hosted edge stack (Caddy + Coraza WAF + Knot DNS + nftables + CrowdSec). The other four components passed nixosTest integration validation; CrowdSec was the one that revealed the cascade. Full diagnosis and reproducer in SMC17/sovereign-edge PR #4.
Related (but not duplicate) issues
- crowdsec: crowdsec-update-hub can't restart crowdsec #473707 "crowdsec: crowdsec-update-hub can't restart crowdsec" — concerns the separate update-hub timer-service, not the
crowdsec.serviceExecStartPre. - nixos/crowdsec: Failed to start Update the crowdsec hub index #476728 "Failed to start Update the crowdsec hub index" — same separate service.
Notify maintainers
@n0emis @aldoborrero (cf. nixos/modules/services/security/crowdsec.nix maintainers field — please update mention if maintainership has changed)
Nixpkgs version
Reproduced on current nixos-unstable channel as of 2026-05-14 via flake-pinned input.
Activity
fleet: 4 more gap closures — substrate-week Type-Is closed + upstream…
fleet: 4 more gap closures — substrate-week Type-Is closed + upstream…
SMC17 commentedon May 19, 2026
PR up at #521985 — adds
services.crowdsec.hub.updateOnStart(defaulttrue, preserves existing behaviour) so operators can disable the unconditionalcscli hub updatecall inExecStartPrefor hermetic / air-gapped / pre-network-online deployments. Minimal-diff fix; 2 hunks; no breaking change. The secondary half of the cascade (DynamicUser + StateDirectory migration oncrowdsec-firewall-bouncer-register) is a separate concern and out of scope for this PR.TornaxO7 commentedon May 19, 2026
There has been a rewrite of the crowdsec module: #446307
Could you please try that one out?
Also note: Please ping the maintainers before ;)
nixos/crowdsec: add hub.updateOnStart for hermetic deploys