diff --git a/modules/crowdsec/default.nix b/modules/crowdsec/default.nix index 208acdb..ec115f5 100644 --- a/modules/crowdsec/default.nix +++ b/modules/crowdsec/default.nix @@ -10,17 +10,9 @@ pkg = cfg.package; - defaultPatterns = lib.mapAttrs (name: value: lib.mkDefault "${pkg}/share/crowdsec/config/patterns/${name}") (builtins.readDir "${pkg}/share/crowdsec/config/patterns"); + defaultPatterns = [pkg.patterns]; - patternsDir = pkgs.runCommandNoCC "crowdsec-patterns" {} '' - mkdir -p $out - ${lib.concatStringsSep "\n" (lib.attrValues (lib.mapAttrs ( - k: v: '' - ln -sf ${v} $out/${k} - '' - ) - cfg.patterns))} - ''; + patternsDir = pkgs.symlinkJoin { name = "crowdsec-merged-patterns"; paths = [cfg.patterns];}; defaultSettings = with lib; { common = { @@ -118,14 +110,15 @@ in { }; patterns = mkOption { description = mdDoc '' - A set of pattern files for parsing logs, in the form "type" to file containing the corresponding GROK patterns. + A list of pattern derrivations for parsing logs, in the form "type" to file containing the corresponding GROK patterns. + Files in the derriviatons will be merged into one and must only contains files in the root of the derivation. All default patterns are automatically included. See . ''; - type = types.attrsOf types.pathInStore; - default = {}; + type = types.listOf types.package; #types.attrsOf types.pathInStore; + default = []; example = lib.literalExpression '' - { ssh = ./patterns/ssh;} + [ (pkgs.writeTextDir "ssh" (builtins.readFile ./ssh)) ] ''; }; settings = mkOption { diff --git a/packages/crowdsec/default.nix b/packages/crowdsec/default.nix index 7c5a085..b9d8dda 100644 --- a/packages/crowdsec/default.nix +++ b/packages/crowdsec/default.nix @@ -43,6 +43,8 @@ buildGoModule rec { vendorHash = "sha256-fl5LkRz69QOq4aPyAhMFxw1FWozLzofDBUGvRptuyZY="; + outputs = [ "out" "patterns" ]; + nativeBuildInputs = [installShellFiles]; subPackages = [ @@ -64,9 +66,13 @@ buildGoModule rec { postBuild = "mv $GOPATH/bin/{crowdsec-cli,cscli}"; postInstall = '' + mkdir -p $patterns + mv ./config/patterns/* $patterns + mkdir -p $out/share/crowdsec cp -r ./config $out/share/crowdsec/ + installShellCompletion --cmd cscli \ --bash <($out/bin/cscli completion bash) \ --fish <($out/bin/cscli completion fish) \