about summary refs log tree commit diff
path: root/modules/nixos/fail2ban.nix
blob: 5ac3c9cf5c32245bc0d17642de86afdc14dd68d2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
{
  config,
  lib,
  this,
  ...
}:
with lib; let
  cfg = config.nixfiles.modules.fail2ban;
in {
  options.nixfiles.modules.fail2ban.enable =
    mkEnableOption "fail2ban";

  config = mkIf cfg.enable {
    services.fail2ban = {
      enable = true;

      bantime-increment = {
        enable = true;
        maxtime = "24h";
        rndtime = "8m";
      };

      ignoreIP =
        optionals (hasAttr "wireguard" this)
        (with config.nixfiles.modules.wireguard; [ipv4.subnet ipv6.subnet]);

      jails.DEFAULT = ''
        blocktype = DROP
      '';
    };
  };
}

Consider giving Nix/NixOS a try! <3