Skip to content

crowdsec-firewall-bouncer: init at 0.0.33#412880

Merged
Defelo merged 1 commit intoNixOS:masterfrom
TornaxO7:crowdsec-firewall-bouncer
Jun 14, 2025
Merged

crowdsec-firewall-bouncer: init at 0.0.33#412880
Defelo merged 1 commit intoNixOS:masterfrom
TornaxO7:crowdsec-firewall-bouncer

Conversation

@TornaxO7
Copy link
Contributor

@TornaxO7 TornaxO7 commented Jun 1, 2025

Closes #279874

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/)
  • Nixpkgs 25.11 Release Notes (or backporting 24.11 and 25.05 Nixpkgs Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
  • NixOS 25.11 Release Notes (or backporting 24.11 and 25.05 NixOS Release notes)
    • (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.

@TornaxO7 TornaxO7 force-pushed the crowdsec-firewall-bouncer branch from 44cae38 to 7629126 Compare June 1, 2025 09:11
@github-actions github-actions bot added 10.rebuild-darwin: 1 This PR causes 1 package to rebuild on Darwin. 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-linux: 1 This PR causes 1 package to rebuild on Linux. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. labels Jun 1, 2025
@TornaxO7 TornaxO7 marked this pull request as draft June 1, 2025 09:15
@TornaxO7
Copy link
Contributor Author

TornaxO7 commented Jun 1, 2025

@06kellyjac may I ask for some suggestions here?

I saw here (#279874 (comment)) that you'd like to split the package into two outputs. Should I give it a try (I've never done that before)?

@06kellyjac
Copy link
Member

You could look at the crane package for reference maybe.
It has 3 outputs total: out (the main/default one), crane, and gcrane.
The binaries are moved into their respective outputs and symlinks are added to out.
There are also completion files being generated but that may not be necessary.
Overall it just means by default if someone does nix-shell -p crane or installs it they'll get both, if someone only needs crane they can specify crane.crane

For other examples searching for outputs = should find a few things. :)

@06kellyjac
Copy link
Member

Or alternatively we can have it all in one output for now. Just having it packaged would be good

@TornaxO7
Copy link
Contributor Author

TornaxO7 commented Jun 1, 2025

Or alternatively we can have it all in one output for now. Just having it packaged would be good

I think that would simplify it xD

@TornaxO7 TornaxO7 marked this pull request as ready for review June 1, 2025 11:22
@TornaxO7
Copy link
Contributor Author

TornaxO7 commented Jun 1, 2025

Regarding testing: I don't really know how to test it. 👀
Running

nix build .#crowdsec-firewall-bouncer
./result/bin/crowdsec-firewall-bouncer

gives me this:

FATA[0000] configuration file is required

Running

./result/bin/crowdsec-firewall-bouncer --help

prints the help page.

@TornaxO7
Copy link
Contributor Author

TornaxO7 commented Jun 1, 2025

Ok, I could run it and it printed some valid error messages.

@TornaxO7
Copy link
Contributor Author

TornaxO7 commented Jun 2, 2025

Or alternatively we can have it all in one output for now. Just having it packaged would be good

@06kellyjac (just in case) I'd say, it's ready for review then. Having it as a package to continue working on the service would be very nice. :) (I'd reaaaaaaaaaaaaally love to have crowdsec as a module).

@acuteaangle
Copy link
Contributor

nixpkgs-review result

Generated using nixpkgs-review.

Command: nixpkgs-review pr 412880


x86_64-linux

❌ 1 package failed to build:
  • crowdsec-firewall-bouncer
    error: hash mismatch in fixed-output derivation '/nix/store/xix9x1filik5k8wa7d91s9npf1npgx2y-source.drv':
             specified: sha256-59MWll8v00CF4WA53gjHZSTFc8hpYaHENg9O7LgTCrA=
                got:    sha256-4fxxAW2sXGNxjsc75fd499ciuN8tjGqlpRIaHYUXwQ0=
    error: 1 dependencies of derivation '/nix/store/6mlx6g8sbk1fpax1yj51005niv5zm4gs-crowdsec-firewall-bouncer-0.0.33-go-modules.drv' failed to build
    error: 2 dependencies of derivation '/nix/store/kanxa877yhg6p5ic3phyxlwibk4gz5sc-crowdsec-firewall-bouncer-0.0.33.drv' failed to build
    error: 1 dependencies of derivation '/nix/store/5ks9bcf2z8vdfmvj3awyhp6pj72m64sr-review-shell.drv' failed to build
    
✅ 7 packages built:
  • eduke32
  • nixpkgs-manual
  • super-productivity
  • veilid
  • veilid.dev
  • veilid.lib
  • zizmor

@acuteaangle
Copy link
Contributor

src.hash seems to be outdated

@TornaxO7
Copy link
Contributor Author

TornaxO7 commented Jun 5, 2025

That's... interesting... I successfully build with nix bulid .#crowdsec-firewall-bouncer... I'll fix it

@acuteaangle
Copy link
Contributor

acuteaangle commented Jun 5, 2025

That's... interesting... I successfully build with nix bulid .#crowdsec-firewall-bouncer... I'll fix it

Nix will continue using an old version; if the hash exists in the store, it'll skip fetching the source and will use what it has.

We should add versionCheckHook to fix this, but currently cs-firewall-bouncer --version gives an empty version output for me:

version:
BuildDate:
GoVersion: 1.24.3
Platform: linux

acuteaangle

This comment was marked as resolved.

@acuteaangle
Copy link
Contributor

acuteaangle commented Jun 5, 2025

A bit later I'll try to figure out why --version gives an empty version. It's really useful to have versionCheckHook working: it
prevents Nix from using stale hashes from old versions, it helps ensure nix-update-script is functioning properly, and it act as a very basic test that the binary can run at all. It does, however, need version to be a substring of the output.

EDIT:
I won’t be able to get to this tonight.

@TornaxO7 TornaxO7 force-pushed the crowdsec-firewall-bouncer branch from 906289c to f0ca41b Compare June 6, 2025 03:52
@TornaxO7 TornaxO7 force-pushed the crowdsec-firewall-bouncer branch 2 times, most recently from c5944de to f9a35db Compare June 6, 2025 17:25
Copy link
Contributor

@acuteaangle acuteaangle left a comment

Choose a reason for hiding this comment

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

This gets versionCheckHook working :)
Since we're setting the version based on src.tag, it won't help against a stale hash, but I still think it's a good idea to include it.

@acuteaangle
Copy link
Contributor

I managed to get extracting version information from git working, but it feels like a decent amount of complexity just to get the full benefit of versionCheckHook. I’ll throw the patch here anyways, in case future reviewers have any thoughts about it.

crowdsec-firewall-bouncer-extract-metadata-from-git.patch
From: Summer Tea <acuteaangle@disroot.org>
Date: Tue, 10 Jun 2025 03:36:14 -0400
Subject: [RFC PATCH] crowdsec-firewall-bouncer: extract metadata from git
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Extract versioning information from `git` to allow `versionCheckHook`
to validate that {version} and {src.hash} are maintained in sync.

`.git` is deleted in postFetch after the desired information is written
out, to avoid reproducibility issues described in [#8567].

Additionally, `-version` gives unsurprising output—in contrast to fields
previously being blank or unique to Nix.

The upstream Makefile sets the version metadata to the following values:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
version.Version=$(git describe --tags)
version.BuildDate=$(date +%F"_"%T)
version.Tag=$(git rev-parse HEAD)'
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
While these are questionably named and perhaps do not produce 'optimal'
output, for now replicate what the upstream Makefile does, with the
exception of substituting the commit date for the build date.

`git describe --tags` seems to produce different output in fetchgit,
despite operating on the same commit.
tag `v0.0.33` (cb8b3e3) gives `v0.0.33` when run interactively against
the upstream repo, but within fetchgit it instead returns
`v0.0.33-rc1-1-gcb8b3e3`, which is technically correct, but different.

This whole version system seems fairly janky. `-version` prints
`v0.0.33-rc1-1-gcb8b3e3-cb8b3e3c654499f745ff487eb1c327d7234a533f`,
catenating the output of `git describe --tags` (which may already
include the commit hash) with the commit hash.

Either `git log --tags --long --abbrev=40` or `git log --tags --abbrev=0`
seems like it would make more sense here, but out of scope
for Nixpkgs.

[#8567]: https://github.com/NixOS/nixpkgs/issues/8567
---

I managed to get extracting version information from `git` working,
but it feels like a decent amount of complexity just to get the full
benefit of `versionCheckHook`. I’ll throw the patch here anyways,
in case future reviewers have any thoughts about it.

 .../cr/crowdsec-firewall-bouncer/package.nix  | 40 +++++++++++++++++--
 1 file changed, 36 insertions(+), 4 deletions(-)


diff --git a/pkgs/by-name/cr/crowdsec-firewall-bouncer/package.nix b/pkgs/by-name/cr/crowdsec-firewall-bouncer/package.nix
index f7b3116e41fd..2b640d3f7c2c 100644
--- a/pkgs/by-name/cr/crowdsec-firewall-bouncer/package.nix
+++ b/pkgs/by-name/cr/crowdsec-firewall-bouncer/package.nix
@@ -13,14 +13,46 @@ buildGoModule rec {
     owner = "crowdsecurity";
     repo = "cs-firewall-bouncer";
     tag = "v${version}";
-    hash = "sha256-4fxxAW2sXGNxjsc75fd499ciuN8tjGqlpRIaHYUXwQ0=";
+    hash = "sha256-lfIRKFGVB++sAVDnGujh0VwCyZmfdxXtl3rK8V7xVr0=";
+    leaveDotGit = true;
+    deepClone = true; # needed for `git describe`
+    # By extracting metadata from the git repository in postFetch, we can
+    # delete the rest of `.git` afterwards and avoid the reproducibility
+    # issues described in <https://github.com/NixOS/nixpkgs/issues/8567>.
+    postFetch = ''
+      pushd "$out"
+      # Store the current commit hash and the output of `git describe`
+      # to give to the program during the build.
+      #
+      # Do this rather than directly supplying `{version}` or `{src.tag}`,
+      # as it allows `versionCheckHook` to function as a better sanity check.
+      git describe --tags > COMMIT_DESCRIBE
+      git rev-parse HEAD > COMMIT
+      # Format using `date` rather than git’s builtin `--date` option, as
+      # it’s an easy way to be _certain_ times will be in UTC (without relying
+      # TZ=UTC0), and we can directly use the expected format string from the
+      # Makefile, since it would call `date`.
+      #
+      # While it would be possible to leave the date unset (the program
+      # would print an empty string in its place) or set it to a fixed epoch,
+      # providing the commit date lets it give a useful and unsurprising value.
+      date -u -d "@$(git log -1 --pretty=%ct)" '+%F_%T' > SOURCE_DATE
+      # We want to remove *every* `.git` directory, in case of submodules.
+      find -name .git -print0 | xargs -0 rm -rf
+      popd
+    '';
   };
 
   vendorHash = "sha256-Bhp6Z2UlCJ32vdc3uINCGleZFP2WeUn/XK+Q29szUzQ=";
 
-  ldflags = [
-    "-X github.com/crowdsecurity/go-cs-lib/version.Version=${src.tag}"
-  ];
+  preBuild = ''
+    # Poorly named, but what the programs expects
+    pushd "$src"
+    ldflags+=" -X github.com/crowdsecurity/go-cs-lib/version.Version=$(< COMMIT_DESCRIBE)"
+    ldflags+=" -X github.com/crowdsecurity/go-cs-lib/version.BuildDate=$(< SOURCE_DATE)"
+    ldflags+=" -X github.com/crowdsecurity/go-cs-lib/version.Tag=$(< COMMIT)"
+    popd
+  '';
 
   nativeInstallCheckInputs = [ versionCheckHook ];
 

@acuteaangle
Copy link
Contributor

Next chance I get some more free time, I’m hoping to try out this package with the WIP module at #387625.
It’d be nice to know if this actually functions :)

Copy link
Member

@Defelo Defelo left a comment

Choose a reason for hiding this comment

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

also please don't forget to squash your commits 😉

@TornaxO7
Copy link
Contributor Author

also please don't forget to squash your commits 😉

Aye! (And: Long time no see :D)

@TornaxO7 TornaxO7 force-pushed the crowdsec-firewall-bouncer branch from 5706932 to 8927354 Compare June 13, 2025 09:10
@06kellyjac
Copy link
Member

nixpkgs-review result

Generated using nixpkgs-review.

Command: nixpkgs-review pr 412880


x86_64-linux

✅ 1 package built:
  • crowdsec-firewall-bouncer

Copy link
Member

@06kellyjac 06kellyjac left a comment

Choose a reason for hiding this comment

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

Happy to maintain with you but otherwise LGTM

@Defelo
Copy link
Member

Defelo commented Jun 13, 2025

nixpkgs-review result

Generated using nixpkgs-review-gha

Command: nixpkgs-review pr 412880

Logs: https://github.com/Defelo/nixpkgs-review-gha/actions/runs/15636318062

Download packages from cache:
  • x86_64-linux
    nix-store -r --add-root nixpkgs-pr-412880-x86_64-linux \
      --option binary-caches 'https://cache.nixos.org/ https://attic.defelo.de/nixpkgs' \
      --option trusted-public-keys '
      cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=
      nixpkgs:xeaAWa3crK09hMmFiygBeRmLq3hUjUShgaAwYVUEtw0=
      ' \
      /nix/store/c80hgminwhdpnv1530h7ksndfgvpj5xs-crowdsec-firewall-bouncer-0.0.33
  • aarch64-linux
    nix-store -r --add-root nixpkgs-pr-412880-aarch64-linux \
      --option binary-caches 'https://cache.nixos.org/ https://attic.defelo.de/nixpkgs' \
      --option trusted-public-keys '
      cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=
      nixpkgs:xeaAWa3crK09hMmFiygBeRmLq3hUjUShgaAwYVUEtw0=
      ' \
      /nix/store/9fj8dgci75z25g3jcm6yk5mgfvfh3yxj-crowdsec-firewall-bouncer-0.0.33
  • aarch64-darwin
    nix-store -r --add-root nixpkgs-pr-412880-aarch64-darwin \
      --option binary-caches 'https://cache.nixos.org/ https://attic.defelo.de/nixpkgs' \
      --option trusted-public-keys '
      cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=
      nixpkgs:xeaAWa3crK09hMmFiygBeRmLq3hUjUShgaAwYVUEtw0=
      ' \
      /nix/store/cc7bs5qyvcymicr2s1mq9dqijgmkxkzi-crowdsec-firewall-bouncer-0.0.33

x86_64-linux (sandbox = true)

✅ 1 package built:
  • crowdsec-firewall-bouncer

aarch64-linux (sandbox = true)

✅ 1 package built:
  • crowdsec-firewall-bouncer

x86_64-darwin (sandbox = true)

✅ 1 package built:
  • crowdsec-firewall-bouncer

aarch64-darwin (sandbox = true)

✅ 1 package built:
  • crowdsec-firewall-bouncer

Copy link
Member

@Defelo Defelo left a comment

Choose a reason for hiding this comment

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

Diff LGTM, however can't test this myself.

Maybe consider rewriting your commit message to mention each co-author only once and remove the old messages ("Update ...", "format ...")

@wegank wegank added the 12.approvals: 2 This PR was reviewed and approved by two persons. label Jun 13, 2025
@TornaxO7
Copy link
Contributor Author

Diff LGTM, however can't test this myself.

Maybe consider rewriting your commit message to mention each co-author only once and remove the old messages ("Update ...", "format ...")

ok

Co-authored-by: Summer Tea <79724236+acuteaangle@users.noreply.github.com>

Co-authored-by: Felix Bargfeldt <41747605+Defelo@users.noreply.github.com>

Co-authored-by: j-k <dev@j-k.io>
@TornaxO7 TornaxO7 force-pushed the crowdsec-firewall-bouncer branch from c561bfb to 7895713 Compare June 13, 2025 17:00
@Defelo Defelo merged commit e2d93b5 into NixOS:master Jun 14, 2025
15 of 16 checks passed
@TornaxO7 TornaxO7 deleted the crowdsec-firewall-bouncer branch June 14, 2025 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-darwin: 1 This PR causes 1 package to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 10.rebuild-linux: 1 This PR causes 1 package to rebuild on Linux. 12.approvals: 2 This PR was reviewed and approved by two persons.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Package request: crowdsec-firewall-bouncer-iptables

5 participants