1 { config, lib, pkgs, ... }:
6 cfg = config.services.ferm;
8 configFile = pkgs.stdenv.mkDerivation {
11 preferLocalBuild = true;
13 echo -n "$text" > $out
14 ${cfg.package}/bin/ferm --noexec $out
23 description = lib.mdDoc ''
24 Whether to enable Ferm Firewall.
25 *Warning*: Enabling this service WILL disable the existing NixOS
26 firewall! Default firewall rules provided by packages are not
27 considered at the moment.
31 description = lib.mdDoc "Verbatim ferm.conf configuration.";
33 defaultText = literalMD "empty firewall, allows any traffic";
37 description = lib.mdDoc "The ferm package.";
40 defaultText = literalExpression "pkgs.ferm";
45 config = mkIf cfg.enable {
46 systemd.services.firewall.enable = false;
47 systemd.services.ferm = {
48 description = "Ferm Firewall";
49 after = [ "ipset.target" ];
50 before = [ "network-pre.target" ];
51 wants = [ "network-pre.target" ];
52 wantedBy = [ "multi-user.target" ];
53 reloadIfChanged = true;
56 RemainAfterExit = "yes";
57 ExecStart = "${cfg.package}/bin/ferm ${configFile}";
58 ExecReload = "${cfg.package}/bin/ferm ${configFile}";
59 ExecStop = "${cfg.package}/bin/ferm -F ${configFile}";