Skip to content

nixos/crowdsec: refactor architecture - #446307

Closed
TornaxO7 wants to merge 3 commits into
NixOS:masterfrom
TornaxO7:crowdsec
Closed

TornaxO7 wants to merge 3 commits into
NixOS:masterfrom
TornaxO7:crowdsec

Conversation

@TornaxO7

@TornaxO7 TornaxO7 commented Sep 26, 2025 •

Copy link
Copy Markdown
Contributor

This PR should just refactor the crowdsec module. It's almost a total rewrite. So I recommend just to look at the new file instead of the diff.

Alright, so after looking a bit through the code, I've got the following suggestion:

Feel free to share your thoughts on my suggestions!

Closes #473707
Closes #469519
Closes #459224
Closes #458206
Closes #445342
Closes #445337

Things done

  • Built on platform:
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • Tested, as applicable:
  • Ran nixpkgs-review on this PR. See nixpkgs-review usage.
  • Tested basic functionality of all binary files, usually in ./result/bin/.
  • Nixpkgs Release Notes
    • Package update: when the change is major or breaking.
  • NixOS Release Notes
    • Module addition: when adding a new NixOS module.
    • Module update: when the change is significant.
  • Fits CONTRIBUTING.md, pkgs/README.md, maintainers/README.md and other READMEs.

Add a 👍 reaction to pull requests you find important.

@nixpkgs-ci nixpkgs-ci Bot added 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 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 Sep 26, 2025
@TornaxO7

TornaxO7 commented Sep 26, 2025 •

Copy link
Copy Markdown
Contributor Author

Alright, I added my changes for now.

The only option which I currently have is services.crowdsec.enable = true;.
However, I'm getting the following error after restarting the service:

Screenshot_2025-09-26_22-47-36

and I'm unsure what the cause may be.

Another big change is, that there's now only services.crowdsec.settings which combines the stuff from services.crowdsec.localConfig and services.crowdsec.settings.

@nicomem may I ask if you can try out my branch if it fixes #445342 for you? Do you get the same error as I do?

@nicomem

nicomem commented Sep 27, 2025

Copy link
Copy Markdown
Contributor

Thanks, I'll try your branch and get back to you on my results.

I also got this error when I was trying to make it work on my machine but I don't remember exactly what fixed it.

@nicomem nicomem left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Some feedback from me, looking at the changes before testing it

@nicomem

nicomem commented Sep 27, 2025

Copy link
Copy Markdown
Contributor

After applying #446307 (comment) and #446307 (comment), the crowdsec service runs without failing.

However, it does not work correctly as if I call cscli parsers list, I get the following:

WARNING Ignoring file /etc/crowdsec/parsers/s00-raw/syslog-logs.yaml: lstat /var/lib/crowdsec/state/hub/parsers/s00-raw/crowdsecurity/syslog-logs.yaml: no such file or directory 
WARNING Ignoring file /etc/crowdsec/parsers/s01-parse/authelia-logs.yaml: lstat /var/lib/crowdsec/state/hub/parsers/s01-parse/LePresidente/authelia-logs.yaml: no such file or directory 
WARNING Ignoring file /etc/crowdsec/parsers/s01-parse/caddy-logs.yaml: lstat /var/lib/crowdsec/state/hub/parsers/s01-parse/crowdsecurity/caddy-logs.yaml: no such file or directory 
WARNING Ignoring file /etc/crowdsec/parsers/s01-parse/gitea-logs.yaml: lstat /var/lib/crowdsec/state/hub/parsers/s01-parse/LePresidente/gitea-logs.yaml: no such file or directory 
WARNING Ignoring file /etc/crowdsec/parsers/s01-parse/sshd-logs.yaml: lstat /var/lib/crowdsec/state/hub/parsers/s01-parse/crowdsecurity/sshd-logs.yaml: no such file or directory 
WARNING Ignoring file /etc/crowdsec/parsers/s02-enrich/dateparse-enrich.yaml: lstat /var/lib/crowdsec/state/hub/parsers/s02-enrich/crowdsecurity/dateparse-enrich.yaml: no such file or directory 
WARNING Ignoring file /etc/crowdsec/parsers/s02-enrich/geoip-enrich.yaml: lstat /var/lib/crowdsec/state/hub/parsers/s02-enrich/crowdsecurity/geoip-enrich.yaml: no such file or directory 
WARNING Ignoring file /etc/crowdsec/parsers/s02-enrich/http-logs.yaml: lstat /var/lib/crowdsec/state/hub/parsers/s02-enrich/crowdsecurity/http-logs.yaml: no such file or directory 
WARNING Ignoring file /etc/crowdsec/parsers/s02-enrich/public-dns-allowlist.yaml: lstat /var/lib/crowdsec/state/hub/parsers/s02-enrich/crowdsecurity/public-dns-allowlist.yaml: no such file or directory 
WARNING Ignoring file /etc/crowdsec/postoverflows/s00-enrich/rdns.yaml: lstat /var/lib/crowdsec/state/hub/postoverflows/s00-enrich/crowdsecurity/rdns.yaml: no such file or directory 
WARNING Ignoring file /etc/crowdsec/postoverflows/s01-whitelist/cdn-whitelist.yaml: lstat /var/lib/crowdsec/state/hub/postoverflows/s01-whitelist/crowdsecurity/cdn-whitelist.yaml: no such file or directory 
WARNING Ignoring file /etc/crowdsec/postoverflows/s01-whitelist/seo-bots-whitelist.yaml: lstat /var/lib/crowdsec/state/hub/postoverflows/s01-whitelist/crowdsecurity/seo-bots-whitelist.yaml: no such file or directory 
WARNING Ignoring file /etc/crowdsec/scenarios/CVE-2017-9841.yaml: lstat /var/lib/crowdsec/state/hub/scenarios/crowdsecurity/CVE-2017-9841.yaml: no such file or directory 
WARNING Ignoring file /etc/crowdsec/scenarios/CVE-2019-18935.yaml: lstat /var/lib/crowdsec/state/hub/scenarios/crowdsecurity/CVE-2019-18935.yaml: no such file or directory 
WARNING Ignoring file /etc/crowdsec/scenarios/CVE-2022-26134.yaml: lstat /var/lib/crowdsec/state/hub/scenarios/crowdsecurity/CVE-2022-26134.yaml: no such file or directory 
WARNING Ignoring file /etc/crowdsec/scenarios/CVE-2022-35914.yaml: lstat /var/lib/crowdsec/state/hub/scenarios/crowdsecurity/CVE-2022-35914.yaml: no such file or directory 
WARNING Ignoring file /etc/crowdsec/scenarios/CVE-2022-37042.yaml: lstat /var/lib/crowdsec/state/hub/scenarios/crowdsecurity/CVE-2022-37042.yaml: no such file or directory 
WARNING Ignoring file /etc/crowdsec/scenarios/CVE-2022-40684.yaml: lstat /var/lib/crowdsec/state/hub/scenarios/crowdsecurity/CVE-2022-40684.yaml: no such file or directory 
WARNING Ignoring file /etc/crowdsec/scenarios/CVE-2022-41082.yaml: lstat /var/lib/crowdsec/state/hub/scenarios/crowdsecurity/CVE-2022-41082.yaml: no such file or directory 
WARNING Ignoring file /etc/crowdsec/scenarios/CVE-2022-41697.yaml: lstat /var/lib/crowdsec/state/hub/scenarios/crowdsecurity/CVE-2022-41697.yaml: no such file or directory 
WARNING Ignoring file /etc/crowdsec/scenarios/CVE-2022-42889.yaml: lstat /var/lib/crowdsec/state/hub/scenarios/crowdsecurity/CVE-2022-42889.yaml: no such file or directory 
WARNING Ignoring file /etc/crowdsec/scenarios/CVE-2022-44877.yaml: lstat /var/lib/crowdsec/state/hub/scenarios/crowdsecurity/CVE-2022-44877.yaml: no such file or directory 
WARNING Ignoring file /etc/crowdsec/scenarios/CVE-2022-46169.yaml: lstat /var/lib/crowdsec/state/hub/scenarios/crowdsecurity/CVE-2022-46169.yaml: no such file or directory 
WARNING Ignoring file /etc/crowdsec/scenarios/CVE-2023-22515.yaml: lstat /var/lib/crowdsec/state/hub/scenarios/crowdsecurity/CVE-2023-22515.yaml: no such file or directory 
WARNING Ignoring file /etc/crowdsec/scenarios/CVE-2023-22518.yaml: lstat /var/lib/crowdsec/state/hub/scenarios/crowdsecurity/CVE-2023-22518.yaml: no such file or directory 
WARNING Ignoring file /etc/crowdsec/scenarios/CVE-2023-49103.yaml: lstat /var/lib/crowdsec/state/hub/scenarios/crowdsecurity/CVE-2023-49103.yaml: no such file or directory 
WARNING Ignoring file /etc/crowdsec/scenarios/CVE-2024-0012.yaml: lstat /var/lib/crowdsec/state/hub/scenarios/crowdsecurity/CVE-2024-0012.yaml: no such file or directory 
WARNING Ignoring file /etc/crowdsec/scenarios/CVE-2024-38475.yaml: lstat /var/lib/crowdsec/state/hub/scenarios/crowdsecurity/CVE-2024-38475.yaml: no such file or directory 
WARNING Ignoring file /etc/crowdsec/scenarios/CVE-2024-9474.yaml: lstat /var/lib/crowdsec/state/hub/scenarios/crowdsecurity/CVE-2024-9474.yaml: no such file or directory 
WARNING Ignoring file /etc/crowdsec/scenarios/apache_log4j2_cve-2021-44228.yaml: lstat /var/lib/crowdsec/state/hub/scenarios/crowdsecurity/apache_log4j2_cve-2021-44228.yaml: no such file or directory 
WARNING Ignoring file /etc/crowdsec/scenarios/authelia-bf.yaml: lstat /var/lib/crowdsec/state/hub/scenarios/LePresidente/authelia-bf.yaml: no such file or directory 
WARNING Ignoring file /etc/crowdsec/scenarios/f5-big-ip-cve-2020-5902.yaml: lstat /var/lib/crowdsec/state/hub/scenarios/crowdsecurity/f5-big-ip-cve-2020-5902.yaml: no such file or directory 
WARNING Ignoring file /etc/crowdsec/scenarios/fortinet-cve-2018-13379.yaml: lstat /var/lib/crowdsec/state/hub/scenarios/crowdsecurity/fortinet-cve-2018-13379.yaml: no such file or directory 
WARNING Ignoring file /etc/crowdsec/scenarios/gitea-bf.yaml: lstat /var/lib/crowdsec/state/hub/scenarios/LePresidente/gitea-bf.yaml: no such file or directory 
WARNING Ignoring file /etc/crowdsec/scenarios/grafana-cve-2021-43798.yaml: lstat /var/lib/crowdsec/state/hub/scenarios/crowdsecurity/grafana-cve-2021-43798.yaml: no such file or directory 
WARNING Ignoring file /etc/crowdsec/scenarios/http-admin-interface-probing.yaml: lstat /var/lib/crowdsec/state/hub/scenarios/crowdsecurity/http-admin-interface-probing.yaml: no such file or directory 
WARNING Ignoring file /etc/crowdsec/scenarios/http-backdoors-attempts.yaml: lstat /var/lib/crowdsec/state/hub/scenarios/crowdsecurity/http-backdoors-attempts.yaml: no such file or directory 
WARNING Ignoring file /etc/crowdsec/scenarios/http-bad-user-agent.yaml: lstat /var/lib/crowdsec/state/hub/scenarios/crowdsecurity/http-bad-user-agent.yaml: no such file or directory 
WARNING Ignoring file /etc/crowdsec/scenarios/http-crawl-non_statics.yaml: lstat /var/lib/crowdsec/state/hub/scenarios/crowdsecurity/http-crawl-non_statics.yaml: no such file or directory 
WARNING Ignoring file /etc/crowdsec/scenarios/http-cve-2021-41773.yaml: lstat /var/lib/crowdsec/state/hub/scenarios/crowdsecurity/http-cve-2021-41773.yaml: no such file or directory 
WARNING Ignoring file /etc/crowdsec/scenarios/http-cve-2021-42013.yaml: lstat /var/lib/crowdsec/state/hub/scenarios/crowdsecurity/http-cve-2021-42013.yaml: no such file or directory 
WARNING Ignoring file /etc/crowdsec/scenarios/http-cve-probing.yaml: lstat /var/lib/crowdsec/state/hub/scenarios/crowdsecurity/http-cve-probing.yaml: no such file or directory 
WARNING Ignoring file /etc/crowdsec/scenarios/http-generic-bf.yaml: lstat /var/lib/crowdsec/state/hub/scenarios/crowdsecurity/http-generic-bf.yaml: no such file or directory 
WARNING Ignoring file /etc/crowdsec/scenarios/http-generic-test.yaml: lstat /var/lib/crowdsec/state/hub/scenarios/crowdsecurity/http-generic-test.yaml: no such file or directory 
WARNING Ignoring file /etc/crowdsec/scenarios/http-open-proxy.yaml: lstat /var/lib/crowdsec/state/hub/scenarios/crowdsecurity/http-open-proxy.yaml: no such file or directory 
WARNING Ignoring file /etc/crowdsec/scenarios/http-path-traversal-probing.yaml: lstat /var/lib/crowdsec/state/hub/scenarios/crowdsecurity/http-path-traversal-probing.yaml: no such file or directory 
WARNING Ignoring file /etc/crowdsec/scenarios/http-probing.yaml: lstat /var/lib/crowdsec/state/hub/scenarios/crowdsecurity/http-probing.yaml: no such file or directory 
WARNING Ignoring file /etc/crowdsec/scenarios/http-sap-interface-probing.yaml: lstat /var/lib/crowdsec/state/hub/scenarios/crowdsecurity/http-sap-interface-probing.yaml: no such file or directory 
WARNING Ignoring file /etc/crowdsec/scenarios/http-sensitive-files.yaml: lstat /var/lib/crowdsec/state/hub/scenarios/crowdsecurity/http-sensitive-files.yaml: no such file or directory 
WARNING Ignoring file /etc/crowdsec/scenarios/http-sqli-probing.yaml: lstat /var/lib/crowdsec/state/hub/scenarios/crowdsecurity/http-sqli-probing.yaml: no such file or directory 
WARNING Ignoring file /etc/crowdsec/scenarios/http-w00tw00t.yaml: lstat /var/lib/crowdsec/state/hub/scenarios/ltsich/http-w00tw00t.yaml: no such file or directory 
WARNING Ignoring file /etc/crowdsec/scenarios/http-wordpress-scan.yaml: lstat /var/lib/crowdsec/state/hub/scenarios/crowdsecurity/http-wordpress-scan.yaml: no such file or directory 
WARNING Ignoring file /etc/crowdsec/scenarios/http-xss-probing.yaml: lstat /var/lib/crowdsec/state/hub/scenarios/crowdsecurity/http-xss-probing.yaml: no such file or directory 
WARNING Ignoring file /etc/crowdsec/scenarios/jira_cve-2021-26086.yaml: lstat /var/lib/crowdsec/state/hub/scenarios/crowdsecurity/jira_cve-2021-26086.yaml: no such file or directory 
WARNING Ignoring file /etc/crowdsec/scenarios/netgear_rce.yaml: lstat /var/lib/crowdsec/state/hub/scenarios/crowdsecurity/netgear_rce.yaml: no such file or directory 
WARNING Ignoring file /etc/crowdsec/scenarios/pulse-secure-sslvpn-cve-2019-11510.yaml: lstat /var/lib/crowdsec/state/hub/scenarios/crowdsecurity/pulse-secure-sslvpn-cve-2019-11510.yaml: no such file or directory 
WARNING Ignoring file /etc/crowdsec/scenarios/spring4shell_cve-2022-22965.yaml: lstat /var/lib/crowdsec/state/hub/scenarios/crowdsecurity/spring4shell_cve-2022-22965.yaml: no such file or directory 
WARNING Ignoring file /etc/crowdsec/scenarios/ssh-bf.yaml: lstat /var/lib/crowdsec/state/hub/scenarios/crowdsecurity/ssh-bf.yaml: no such file or directory 
WARNING Ignoring file /etc/crowdsec/scenarios/ssh-cve-2024-6387.yaml: lstat /var/lib/crowdsec/state/hub/scenarios/crowdsecurity/ssh-cve-2024-6387.yaml: no such file or directory 
WARNING Ignoring file /etc/crowdsec/scenarios/ssh-generic-test.yaml: lstat /var/lib/crowdsec/state/hub/scenarios/crowdsecurity/ssh-generic-test.yaml: no such file or directory 
WARNING Ignoring file /etc/crowdsec/scenarios/ssh-refused-conn.yaml: lstat /var/lib/crowdsec/state/hub/scenarios/crowdsecurity/ssh-refused-conn.yaml: no such file or directory 
WARNING Ignoring file /etc/crowdsec/scenarios/ssh-slow-bf.yaml: lstat /var/lib/crowdsec/state/hub/scenarios/crowdsecurity/ssh-slow-bf.yaml: no such file or directory 
WARNING Ignoring file /etc/crowdsec/scenarios/thinkphp-cve-2018-20062.yaml: lstat /var/lib/crowdsec/state/hub/scenarios/crowdsecurity/thinkphp-cve-2018-20062.yaml: no such file or directory 
WARNING Ignoring file /etc/crowdsec/scenarios/vmware-cve-2022-22954.yaml: lstat /var/lib/crowdsec/state/hub/scenarios/crowdsecurity/vmware-cve-2022-22954.yaml: no such file or directory 
WARNING Ignoring file /etc/crowdsec/scenarios/vmware-vcenter-vmsa-2021-0027.yaml: lstat /var/lib/crowdsec/state/hub/scenarios/crowdsecurity/vmware-vcenter-vmsa-2021-0027.yaml: no such file or directory 
WARNING Ignoring file /etc/crowdsec/contexts/bf_base.yaml: lstat /var/lib/crowdsec/state/hub/contexts/crowdsecurity/bf_base.yaml: no such file or directory 
WARNING Ignoring file /etc/crowdsec/contexts/http_base.yaml: lstat /var/lib/crowdsec/state/hub/contexts/crowdsecurity/http_base.yaml: no such file or directory 
WARNING Ignoring file /etc/crowdsec/collections/authelia.yml: lstat /var/lib/crowdsec/state/hub/collections/LePresidente/authelia.yml: no such file or directory 
WARNING Ignoring file /etc/crowdsec/collections/base-http-scenarios.yaml: lstat /var/lib/crowdsec/state/hub/collections/crowdsecurity/base-http-scenarios.yaml: no such file or directory 
WARNING Ignoring file /etc/crowdsec/collections/caddy.yaml: lstat /var/lib/crowdsec/state/hub/collections/crowdsecurity/caddy.yaml: no such file or directory 
WARNING Ignoring file /etc/crowdsec/collections/gitea.yml: lstat /var/lib/crowdsec/state/hub/collections/LePresidente/gitea.yml: no such file or directory 
WARNING Ignoring file /etc/crowdsec/collections/http-cve.yaml: lstat /var/lib/crowdsec/state/hub/collections/crowdsecurity/http-cve.yaml: no such file or directory 
WARNING Ignoring file /etc/crowdsec/collections/linux.yaml: lstat /var/lib/crowdsec/state/hub/collections/crowdsecurity/linux.yaml: no such file or directory 
WARNING Ignoring file /etc/crowdsec/collections/sshd.yaml: lstat /var/lib/crowdsec/state/hub/collections/crowdsecurity/sshd.yaml: no such file or directory 
WARNING Ignoring file /etc/crowdsec/collections/whitelist-good-actors.yaml: lstat /var/lib/crowdsec/state/hub/collections/crowdsecurity/whitelist-good-actors.yaml: no such file or directory 
──────────────────────────────────────
 PARSERS                              
──────────────────────────────────────
 Name  📦 Status  Version  Local Path 
──────────────────────────────────────
──────────────────────────────────────

@SebastianStork

Copy link
Copy Markdown
Contributor

From what I have seen, the idiomatic way to make /var/lib/crowdsec and /etc/crowdsec accessible to the service, is to use the systemd service options StateDirectory and ConfigurationDirectory. This would replace ReadWritePaths and the tmpfile rules for rootDir and confDir as systemd will create those dirs automatically. I have set it like this:

systemd.services.crowdsec.serviceConfig = {
  StateDirectory = "crowdsec";
  StateDirectoryMode = "0750";
  ConfigurationDirectory = "crowdsec";
  ConfigurationDirectoryMode = "0750";
};

@SebastianStork

Copy link
Copy Markdown
Contributor

People who use impermanence might appreciate DynamicUser being disabled (see nix-community/impermanence#254). The things DynamicUser does behind the scenes, we already do explicitly (at least I think so? see https://unix.stackexchange.com/questions/635027/systemd-dynamicuser-vs-user)

@TornaxO7

Copy link
Copy Markdown
Contributor Author

People who use impermanence might appreciate DynamicUser being disabled (see nix-community/impermanence#254).

Hm... should I add an option where the user can enable/disable it or should I just remove the DynamicUser option?
There was a discussion about the DynamicUser which you can read here #426875 (comment).

@TornaxO7

Copy link
Copy Markdown
Contributor Author

From what I have seen, the idiomatic way to make /var/lib/crowdsec and /etc/crowdsec accessible to the service, is to use the systemd service options StateDirectory and ConfigurationDirectory. This would replace ReadWritePaths and the tmpfile rules for rootDir and confDir as systemd will create those dirs automatically. I have set it like this:

After skimming through systemd.exec it looks like you're right. Nice one. Thanks!

@SebastianStork

Copy link
Copy Markdown
Contributor

People who use impermanence might appreciate DynamicUser being disabled (see nix-community/impermanence#254).

Hm... should I add an option where the user can enable/disable it or should I just remove the DynamicUser option? There was a discussion about the DynamicUser which you can read here #426875 (comment).

Hmm, I admit that I wasn't aware of this context. I have just been disabling anywhere it bothered me. I'd like some other people to way in on this. The impermanence issue is a bug and will hopefully be fixed sometime in the future, so that shouldn't be the only reason to forgo DynamicUser

@poperigby

Copy link
Copy Markdown
Contributor

Anything I can do to help here? These options seem much more reasonable than the current ones.

I'd also like to mention I'm getting this error when trying to run it:

Error machine login for Haddock : ent: machine not found
127.0.0.1 - [Sun, 09 Nov 2025 15:55:06 PST] \"POST /v1/watchers/login HTTP/1.1 401 345.943µs \"crowdsec/v1.7.2-linux\" \"
attempt 1 out of 2
Error machine login for Haddock : ent: machine not found 
127.0.0.1 - [Sun, 09 Nov 2025 15:55:06 PST] \"POST /v1/watchers/login HTTP/1.1 401 123.611µs \"crowdsec/v1.7.2-linux\" \"
attempt 2 out of 2
Error machine login for Haddock : ent: machine not found
127.0.0.1 - [Sun, 09 Nov 2025 15:55:06 PST] \"POST /v1/watchers/login HTTP/1.1 401 100.691µs \"crowdsec/v1.7.2-linux\" \"
max attempts reached for status code 401
crowdsec init: while initializing LAPIClient: authenticate watcher (Haddock): API error: ent: machine not found

This is my current configuration: https://gist.github.com/poperigby/63ef3e5b6205b6a5e4de320bcb63838a

@TornaxO7

TornaxO7 commented Nov 10, 2025 •

Copy link
Copy Markdown
Contributor Author

Anything I can do to help here? These options seem much more reasonable than the current ones.

Aye, testing! What you already did:

I'd also like to mention I'm getting this error when trying to run it:

Thx!

I'll see when I'll get back to this

@AmethystNightshade

Copy link
Copy Markdown

just tested this and ran into the same error as @poperigby. i looked in the journal and it seems like it needed the api.server.online_client.credentials_path set if anything needs to pull from crowdsec servers (anything on the hub, and possibly acquisitions) in addition the console setup fails and is a bit non intuitive. you need to go to the console and grab just the token out of the command it gives you and paste just that in the console.tokenFile. it then fails as it tries to write the console.yaml into /nix/store, which of course fails due to RO filesystem

here is my configuration repo with link pointed to my system flake and the line where the crowdsec specific bits start: https://gitlab.com/Amethyst_Nightshade/nixos-flakes/-/blob/main/nixosConfigurations/tailnerd-agh.nix#L304

@TornaxO7

Copy link
Copy Markdown
Contributor Author

Alright, I'm back!

just tested this and ran into the same error as @poperigby. i looked in the journal and it seems like it needed the api.server.online_client.credentials_path set if anything needs to pull from crowdsec servers (anything on the hub, and possibly acquisitions) in addition the console setup fails and is a bit non intuitive. you need to go to the console and grab just the token out of the command it gives you and paste just that in the console.tokenFile. it then fails as it tries to write the console.yaml into /nix/store, which of course fails due to RO filesystem

Hm... this doesn't sound nice.

here is my configuration repo with link pointed to my system flake and the line where the crowdsec specific bits start: https://gitlab.com/Amethyst_Nightshade/nixos-flakes/-/blob/main/nixosConfigurations/tailnerd-agh.nix#L304

It looks like as if you've changed your repository.
Could you please update the link?

@liamthexpl0rer

Copy link
Copy Markdown
Contributor

@SuperSandro2000 Can you review and merge this please? ;)

@liamthexpl0rer

Copy link
Copy Markdown
Contributor

@TornaxO7 Can we backport this to 26.05 too?
I will add an nixpkgs-review once it's done. ^^

@liamthexpl0rer

Copy link
Copy Markdown
Contributor

nixpkgs-review result

Generated using nixpkgs-review.

Command: nixpkgs-review pr 446307
Commit: bc75068c929ebbd5465716c0b53ce91adca9ddfb


x86_64-linux

⏩ 2 packages blacklisted:
  • nixos-install-tools
  • tests.nixos-functions.nixos-test
✅ 2 packages built:
  • crowdsec
  • nixpkgs-manual

@TornaxO7

TornaxO7 commented Jun 2, 2026 •

Copy link
Copy Markdown
Contributor Author

@TornaxO7 Can we backport this to 26.05 too? I will add an nixpkgs-review once it's done. ^^

Eh, I'm unsure what you mean by that 😅 what I can do, is to rebase it to master again.
I just arrived at home, so let me quickly do that. <.<

nvm, I think you mean that if we could get the updated module to 26.05... *facepalm* sure, why not I think (but I don't know how to do that 👀 ) But on the other hand... it would introduce a breaking change...

@liamthexpl0rer

liamthexpl0rer commented Jun 2, 2026 •

Copy link
Copy Markdown
Contributor

@TornaxO7 Can we backport this to 26.05 too? I will add an nixpkgs-review once it's done. ^^

Eh, I'm unsure what you mean by that 😅 what I can do, is to rebase it to master again. I just arrived at home, so let me quickly do that. <.<

nvm, I think you mean that if we could get the updated module to 26.05... facepalm sure, why not I think (but I don't know how to do that 👀 )

You can do that by adding the backport release-26.05 label to this pr. See https://github.com/NixOS/nixpkgs/blob/master/CONTRIBUTING.md#how-to-backport-pull-requests

Co-authored-by: Nicolas Mémeint <[email protected]>
Co-authored-by: Jarno Pelkonen <[email protected]>
Co-authored-by: Yash Garg <[email protected]>
Co-authored-by: Gaël James <[email protected]>
Co-authored-by: Azat Bahawi <[email protected]>
@eccgecko

eccgecko commented Jun 2, 2026

Copy link
Copy Markdown

Personally, I think we have missed the boat for a 26.05 merge.

As @TornaxO7 says, the rewritten module introduces breaking changes and will require user intervention.

I feel like backports are more suitable for important security updates for CVEs and smaller incremental changes.

If we wanted a 26.05 merge, we should have been pushing harder for it the last couple of weeks during its merging window.

I personally feel we should now have to wait for 26.11. Anyone who is keen for the changes now can just pull from this PR, as many of us are already doing (or unstable if it goes master -> unstable).

But that is just my honest and humble opinion, and more than happy for others to overrule me.

@TornaxO7

TornaxO7 commented Jun 2, 2026

Copy link
Copy Markdown
Contributor Author

Alright, I rebased the changes to the latest master. Also bumped the crowdsec package from 1.7.7 to 1.7.8.

@liamthexpl0rer

Copy link
Copy Markdown
Contributor

Personally, I think we have missed the boat for a 26.05 merge.

As @TornaxO7 says, the rewritten module introduces breaking changes and will require user intervention.

I feel like backports are more suitable for important security updates for CVEs and smaller incremental changes.

If we wanted a 26.05 merge, we should have been pushing harder for it the last couple of weeks during its merging window.

I personally feel we should now have to wait for 26.11. Anyone who is keen for the changes now can just pull from this PR, as many of us are already doing (or unstable if it goes master -> unstable).

But that is just my honest and humble opinion, and more than happy for others to overrule me.

What are the breaking changes? Normally a backport is also possible for new and updated modules.

@eccgecko

eccgecko commented Jun 2, 2026 •

Copy link
Copy Markdown

What are the breaking changes? Normally a backport is also possible for new and updated modules.

Well I have always used the module from this PR on my nixos system from the start, so I am not 100% on that (I am mostly going off what @TornaxO7 said). My assumption was that, due to the complete rewrite, a user who was previously using the nixpkgs module might need to reconfigure their setup to get crowdsec working again / may run into permission issues. I don't know if this module has a migration path from the older version.

If it doesn't introduce breaking changes and doesn't require manual intervention, then sure, I might be able to see a justification for trying for a 26.05 backports merge.

On the other hand, that's what merge windows are for, so a complete rewrite seems to me to not be appropriate for a backports update. But like I said, just my opinion.

@TornaxO7

TornaxO7 commented Jun 2, 2026 •

Copy link
Copy Markdown
Contributor Author

What are the breaking changes? Normally a backport is also possible for new and updated modules.

@liamthexpl0rer there's no localConfig anymore. Some option moved from localConfig to settings while some other options within settings have been moved to settings.config, some have been removed.

@liamthexpl0rer

liamthexpl0rer commented Jun 3, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for the clarification.

I'm currently on nixos-26.05 channel. If this is merged, how I can override my config to get this package from unstable?

@TornaxO7

TornaxO7 commented Jun 3, 2026

Copy link
Copy Markdown
Contributor Author

I'm currently on nixos-26.05 channel. If this is merged, how I can override my config to get this package from unstable?

That's... a good question . I don't know exactly how to do that but I guess it would be something like this (assuming you're using flakes):

  1. Add an unstable attribute in inputs.
  2. Now you can follow this section: Replace Modules
    But instead of adding an unstable channel I think you an simply add
imports = [
    (unstable + "nixos/modules/services/security/crowdsec.nix")
    (unstable + "nixos/modules/services/security/crowdsec-firewall-bouncer.nix")
];

@strangeglyph

strangeglyph commented Jun 3, 2026 •

Copy link
Copy Markdown
Contributor

You'll also want to disable the current modules from nixos stable

disabledModules = [ 
  "services/security/crowdsec.nix"
  "services/security/crowdsec-firewall-bouncer.nix"
 ];

imports = [ 
  "${inputs.nixpkgs-unstable}/nixos/modules/services/security/crowdsec.nix" 
  "${inputs.nixpkgs-unstable}/nixos/modules/services/security/crowdsec-firewall-bouncer.nix" 
];

@liamthexpl0rer

Copy link
Copy Markdown
Contributor

You'll also want to disable the current modules from nixos stable

disabledModules = [ 
  "services/security/crowdsec.nix"
  "services/security/crowdsec-firewall-bouncer.nix"
 ];

imports = [ 
  "${inputs.nixpkgs-unstable}/nixos/modules/services/security/crowdsec.nix" 
  "${inputs.nixpkgs-unstable}/nixos/modules/services/security/crowdsec-firewall-bouncer.nix" 
];

Thanks! I will test it out after merge (and hydra build). ;)

@Peronia

Peronia commented Jun 3, 2026 •

Copy link
Copy Markdown
Contributor

I'm using flakes und unstable and tried it this way:

inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    crowdsec-module = {
      url = "github:TornaxO7/nixpkgs/crowdsec";
      flake = false;
    };

Then I disabled the nixpkgs module for one testhost:

modules = [
            ./hosts/host.nix
            (
              { config, lib, ... }:
              {
                disabledModules = [
                  "services/security/crowdsec.nix"
                ];
              }
            )
            "${crowdsec-module}/nixos/modules/services/security/crowdsec.nix"
          ];

The build was ok, I tried cscli metricsand got this: WARNING fetching metrics: Get "http://127.0.0.1:6060/metrics": dial tcp 127.0.0.1:6060: connect: connection refused
The I looked at crowdsec-setup:

systemctl status crowdsec-setup
× crowdsec-setup.service - CrowdSec setup service
     Loaded: loaded (/etc/systemd/system/crowdsec-setup.service; enabled; preset: ignored)
     Active: failed (Result: exit-code) since Wed 2026-06-03 15:30:59 CEST; 6min ago
 Invocation: cca8edeb0d3943c5a7776ca67d38638b
    Process: 337 ExecStartPre=/nix/store/9ypz3flqsrl5xl495mm8h645gadjsxi1-coreutils-9.11/bin/chown crowdsec:crowdsec -R /etc/crowdsec (code=exited, status=0/SUCCESS)
    Process: 340 ExecStartPre=/nix/store/9ypz3flqsrl5xl495mm8h645gadjsxi1-coreutils-9.11/bin/chmod 750 -R /etc/crowdsec (code=exited, status=0/SUCCESS)
    Process: 343 ExecStart=/nix/store/y1lrzzr5p70n6qp5ba0ib96snpx16qcj-crowdsec-setup/bin/crowdsec-setup (code=exited, status=1/FAILURE)
   Main PID: 343 (code=exited, status=1/FAILURE)
         IO: 1M read, 0B written
   Mem peak: 2.7M
        CPU: 131ms

Jun 03 15:30:59 host systemd[1]: Starting CrowdSec setup service...
Jun 03 15:30:59 host (chown)[337]: crowdsec-setup.service: Found pre-existing public StateDirectory= directory /var/lib/crowdsec, migrating to /var/lib/private/crowdsec.
Jun 03 15:30:59 host (chown)[337]: crowdsec-setup.service: Apparently, service previously had DynamicUser= turned off, and has now turned it on.
Jun 03 15:30:59 host crowdsec-setup[343]: Creating directories...
Jun 03 15:30:59 host crowdsec-setup[343]: Installing notification plugins...
Jun 03 15:30:59 host crowdsec-setup[349]: install: cannot stat '/nix/store/2addxwpzhnmfmm02sbv6sir5w2f336y6-crowdsec-1.7.7/libexec/crowdsec/plugins/notification-dummy': Datei oder Verzeichnis nicht gefunden
Jun 03 15:30:59 host systemd[1]: crowdsec-setup.service: Main process exited, code=exited, status=1/FAILURE
Jun 03 15:30:59 host systemd[1]: crowdsec-setup.service: Failed with result 'exit-code'.
Jun 03 15:30:59 host systemd[1]: Failed to start CrowdSec setup service.
Jun 03 15:30:59 host systemd[1]: crowdsec-setup.service: Consumed 131ms CPU time over 216ms wall clock time, 2.7M memory peak, 1M read from disk.

Not sure if it should work with this input...
I used the same config as before, only with the new syntax. My config:

crowdsec = {
        enable = true;
        autoUpdateService = true;
        hub.collections = [
          "crowdsecurity/linux"
          "crowdsecurity/nginx"
        ];
        settings = {
          config.api.client.credentials_path = "${config.age.secrets.host-crowdsec-lapi-credentials.path}";
          acquisitions = [
            {
              source = "file";
              filenames = [
                "/var/log/nginx/*.log"
              ];
              labels = {
                type = "nginx";
              };
            }
          ];
          parsers.s02Enrich = [
            {
              name = "local_network_whitelist";
              description = "Ignore local LAN IPs";
              whitelist = {
                reason = "Local network IP";
                cidr = [
                  "192.168.190.0/24"
                ];
              };
            }
          ];
        };
      };

@TornaxO7

TornaxO7 commented Jun 3, 2026

Copy link
Copy Markdown
Contributor Author

@Peronia the crowdsec package got some changes as well, you'd need to import that one as well or assign it to services.crowdsec.package.

@Peronia

Peronia commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Okay, I updated my config.
flake.nix:

inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    crowdsec-module = {
      url = "github:TornaxO7/nixpkgs/crowdsec";
      flake = false;
    };
  };
host = {
          modules = [
            ./hosts/host.nix
            (
              { ... }:
              {
                disabledModules = [
                  "services/security/crowdsec.nix"
                ];
              }
            )
            "${crowdsec-module}/nixos/modules/services/security/crowdsec.nix"
            (
              { ... }:
              {
                _module.args.crowdsec-module = crowdsec-module;
              }
            )
          ];

host.nix:

let
  crowdsecPackage = import "${crowdsec-module}/pkgs/by-name/cr/crowdsec/package.nix" {
    inherit (pkgs)
      lib
      buildGoModule
      fetchFromGitHub
      installShellFiles
      makeWrapper
      ;
  };
in
...
crowdsec = {
        enable = true;
        package = crowdsecPackage;
... (like post before)

The build works, I saw that version 1.7.8 is build, but crowdsec -version shows 1.7.7. Also cscli metrics throws the same error.
crowdsec-setup is now happy, but I see Jun 03 20:35:22 host crowdsec-setup[358]: level=warning msg="Ignoring file /etc/crowdsec/parsers/s02-enrich/igjh5813s7md7nkpfg5yx0mm4wq8kiyn-parsers-s02-enrich.yaml: lstat /nix/store/igjh5813s7md7nkpfg5yx0mm4wq8kiyn-parsers-s02-enrich.yaml: no such file or directory".
It's very complicated...

@liamthexpl0rer liamthexpl0rer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good to me. I have also deployed it now on one of my servers.

@TornaxO7 Big thanks for your work! I hope this get merged soon. ;)

@TornaxO7

TornaxO7 commented Jun 3, 2026

Copy link
Copy Markdown
Contributor Author

@Peronia

could you please replace

let
  crowdsecPackage = import "${crowdsec-module}/pkgs/by-name/cr/crowdsec/package.nix" {
    inherit (pkgs)
      lib
      buildGoModule
      fetchFromGitHub
      installShellFiles
      makeWrapper
      ;
  };
in

with

let
  crowdsecPackage = pkgs.callPackage "${crowdsec-module}/pkgs/by-name/cr/crowdsec/package.nix" {};
in

but I don't think that this going to change anything... (except for better readability and maintainability :D)

but I see Jun 03 20:35:22 host crowdsec-setup[358]: level=warning msg="Ignoring file /etc/crowdsec/parsers/s02-enrich/igjh5813s7md7nkpfg5yx0mm4wq8kiyn-parsers-s02-enrich.yaml: lstat /nix/store/igjh5813s7md7nkpfg5yx0mm4wq8kiyn-parsers-s02-enrich.yaml: no such file or directory".

hm... could you please try systemd-tmpfiles --create and look if the error persists?
If the issue is still there, could you please execute systemd-tmpfiles --create --dry-run | grep crowdsec and check if this enrich file is listed there?

Alternatively, here's my matrix tag: @tornax:matrix.org and feel free to contact me. I think it's better to debug this somewhere else than providing support in this PR.

@liamthexpl0rer

Copy link
Copy Markdown
Contributor

@Peronia Yesterday I have setup crowdsec on my machines. If you need an example, feel free to look into my repo. ^^

https://codeberg.org/liamthexpl0rer/nixos-serverconf/src/branch/dev

@SuperSandro2000

Copy link
Copy Markdown
Member

Yeah, we should probably not backport this as is. Maybe the most pressing parts to get things somewhat working.

Comment on lines +236 to +237
# Ensure the directory exists
mkdir -p "$(dirname ${apiKeyFile})" || true

@SuperSandro2000 SuperSandro2000 Jun 5, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe we do this in a follow up but this should be done with tmpfiles and there we can use the nix dirname function to avoid shelling.

Comment on lines +257 to +259
if ! cscli bouncers add --output raw -- ${lib.escapeShellArg cfg.registerBouncer.bouncerName} > ${apiKeyFile} 2>&1; then
echo "Failed to register the bouncer"
cat ${apiKeyFile} || true # Show error message

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why do we redirect stderr to the file to than cat it? Why not just log it? This way we avoid by accident logging the api key.

fi
fi

chmod 0440 ${apiKeyFile} || true

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This must be done beforehand with umask as we otherwise have a brief moment where the permissions are wrong.

echo "Failed to register the bouncer"
cat ${apiKeyFile} || true # Show error message
rm -f ${apiKeyFile}
exit 1

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
exit 1
exit 1

Otherwise indentation is wrong I think

Comment on lines +13 to +14
# Reason:
# https://github.com/NixOS/nixpkgs/pull/446307#issuecomment-3955091336

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We should copy the reason in code. Than we can also easily update it over time.

Comment on lines +16 to +20
# crowdsec needs the files from caddy
systemd.services.crowdsec.after = [ "caddy.service" ];

# for interactive with non-root users
security.sudo-rs.enable = true;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This seems rather random. Can't we avoid this with an easy workaround?

Comment thread nixos/tests/crowdsec/full.nix Resolved

# serve local hub
virtualHosts = {
"http://${hub-addr}".extraConfig = ''

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why not use a simple tool or the standard nginx?

Comment on lines +59 to +65
install -D $out/bin/notification-dummy -t $out/libexec/crowdsec/plugins/
install -D $out/bin/notification-email -t $out/libexec/crowdsec/plugins/
install -D $out/bin/notification-file -t $out/libexec/crowdsec/plugins/
install -D $out/bin/notification-http -t $out/libexec/crowdsec/plugins/
install -D $out/bin/notification-sentinel -t $out/libexec/crowdsec/plugins/
install -D $out/bin/notification-slack -t $out/libexec/crowdsec/plugins/
install -D $out/bin/notification-splunk -t $out/libexec/crowdsec/plugins/

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why copy them instead of moving them?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We should write a script for that. Can we avoid commiting this file at all?

SupplementaryGroups = cfg.extraGroups;

ExecStartPre = "${crowdsec} -t -error";
ExecStart = "${crowdsec} -info";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

There should be an option to change the log level. It is currently hardcoded to info.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I applied that in the other PR.

@TornaxO7 TornaxO7 mentioned this pull request Jun 25, 2026
3 of 13 tasks
@TornaxO7

Copy link
Copy Markdown
Contributor Author

Alright, this PR continues in #535319.

The newer PR solves to additional things compared to this one:

  • It fully uses systemd.tmpfiles for creating and removing the directories and files. So user should be able to set a different config_dir path or data_dir without breaking things.
  • The cscli should have working auto completion now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2.status: merge conflict This PR has merge conflicts with the target branch 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: changelog This PR adds or changes release notes 8.has: documentation This PR adds or changes documentation 8.has: module (update) This PR changes an existing module in `nixos/` 8.has: package (update) This PR updates a package to a newer version 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux.

Projects

None yet