DynamicUser is giving me a hard time and I don’t see how you can solve those issues in a nice way so I’m thinking about to not use DynamicUser for the crowdsec module. Is that fine?
With DynamicUser, every user who wanted to use cscli to “interact” with crowdsec, needed to provide their user password and are checked, if they even have permission to execute systemd-run). Without DynamicUser only a Error: while setting up trace directory: mkdir /var/lib/crowdsec: file exists is currently “checking” for the correct users to execute cscli which is obviously not… good. How do I allow only users which are in the crowdsec group to be able to execute cscli (but even then with a password or only with sudo)? Somehow I need to set the group of cscli and then the permissions. How do you do that for a nixos-module?
I don’t think security.wrappers is the answer here, cscli shouldn’t have a setuid bit.
The way e.g. nextcloud solves this is using sudo. You could try to get the UID of the user executing crowdsec at runtime and make the script call sudo with that UID.
Your systemd-exec approach seemed better, though, I think you just hadn’t figured out how to fix the completion files.
That seems easy enough to fix, makeWrapper supports adding things to $PATH: Nixpkgs Reference Manual
Not to say you have to use DynamicUser, but when I wrote this module it was pretty easy to set DynamicUser and make a wrapper like the nextcloud one to still have cscli work. It’s a shame the crowdsec module was merged without looking much into my fork.
I’m a little busy currently, but I may have time over easter to sit down for some pair programming if that would help?
My guess is that you end up doing something in the module that ends up overwriting that. Maybe it’s double-wrapped, or you substitute in a version from somewhere else.
Haven’t looked at the PR in detail, so at best this is a guess, I’ll try to set aside some time to do that.