about summary refs log tree commit diff
path: root/modules/fail2ban.nix
blob: a0cc2b4dbcf8f0d0702f39ea0f3107a770651f14 (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
33
34
35
36
37
{
  config,
  lib,
  this,
  ...
}:
with lib;
let
  cfg = config.nixfiles.modules.fail2ban;
in
{
  options.nixfiles.modules.fail2ban.enable = mkEnableOption "fail2ban";

  config = mkIf cfg.enable {
    ark.directories = [ "/var/lib/fail2ban" ];

    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.settings.blocktype = "DROP";
    };
  };
}

Consider giving Nix/NixOS a try! <3