summaryrefslogtreecommitdiff
path: root/modules/nixfiles/fail2ban.nix
blob: 56670e7abbd011c810740edad9f37b411218ff75 (plain)
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 "Whether to enable fail2ban service.";

  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
      '';
    };
  };
}