Skip to content

Commit

Permalink
host: opt: www: Made nginx bad bot blocker into a derivation that's e…
Browse files Browse the repository at this point in the history
…xtensible with patches.

This will allow patching in custom white/blacklists.
  • Loading branch information
aftix committed Oct 14, 2024
1 parent d8b1b30 commit c1b808e
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@
(appliedOverlay)
carapace
heisenbridge
nginx_blocker
nu_plugin_audio_hook
nu_plugin_compress
nu_plugin_dbus
Expand Down
14 changes: 10 additions & 4 deletions host/opt/www/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
}: let
inherit (lib.options) mkOption;

inherit (config.dep-inject) inputs;
cfg = config.my.www;
in {
imports = [
Expand Down Expand Up @@ -65,6 +64,11 @@ in {
default = 599;
type = lib.types.ints.positive;
};

nginxBlockerPatches = mkOption {
default = [];
type = lib.types.listOf lib.types.path;
};
};

config = {
Expand Down Expand Up @@ -117,10 +121,12 @@ in {
openssh.settings.AllowUsers = [cfg.user];
};

systemd.tmpfiles.rules = [
systemd.tmpfiles.rules = let
blockerPkg = pkgs.nginx_blocker.overrideAttrs {patches = cfg.nginxBlockerPatches;};
in [
"d ${cfg.root} 0775 ${cfg.user} ${cfg.group} -"
"L+ /etc/nginx/conf.d - - - - ${inputs.nginxBlacklist}/conf.d"
"L+ /etc/nginx/bots.d - - - - ${inputs.nginxBlacklist}/bots.d"
"L+ /etc/nginx/conf.d - - - - ${blockerPkg}/conf.d"
"L+ /etc/nginx/bots.d - - - - ${blockerPkg}/bots.d"
];

security.acme = {
Expand Down
2 changes: 2 additions & 0 deletions overlay.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ inputs: final: prev: {
};
});

nginx_blocker = final.callPackage ./packages/nginx_blocker.nix {inherit (inputs) nginxBlacklist;};

nu_plugin_audio_hook = final.callPackage ./packages/nu_plugin_audio_hook.nix {};
nu_plugin_compress = final.callPackage ./packages/nu_plugin_compress.nix {};
nu_plugin_dbus = final.callPackage ./packages/nu_plugin_dbus.nix {};
Expand Down
23 changes: 23 additions & 0 deletions packages/nginx_blocker.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
lib,
stdenv,
nginxBlacklist,
}:
stdenv.mkDerivation {
pname = "nginx-ultimate-bad-bot-blocker";
version = "1";

src = nginxBlacklist;

installPhase = ''
mkdir -p "$out"
cp -R *.d "$out/."
'';

meta = with lib; {
description = "nginx ultimate bad bot blocker";
homepage = "https://github.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker";
license = licenses.mit;
platforms = with platforms; all;
};
}

0 comments on commit c1b808e

Please sign in to comment.