8 cfg = config.services.ferm;
10 configFile = pkgs.stdenv.mkDerivation {
13 preferLocalBuild = true;
15 echo -n "$text" > $out
16 ${cfg.package}/bin/ferm --noexec $out
23 enable = lib.mkOption {
25 type = lib.types.bool;
27 Whether to enable Ferm Firewall.
28 *Warning*: Enabling this service WILL disable the existing NixOS
29 firewall! Default firewall rules provided by packages are not
30 considered at the moment.
33 config = lib.mkOption {
34 description = "Verbatim ferm.conf configuration.";
36 defaultText = lib.literalMD "empty firewall, allows any traffic";
37 type = lib.types.lines;
39 package = lib.mkPackageOption pkgs "ferm" { };
43 config = lib.mkIf cfg.enable {
44 systemd.services.firewall.enable = false;
45 systemd.services.ferm = {
46 description = "Ferm Firewall";
47 after = [ "ipset.target" ];
48 before = [ "network-pre.target" ];
49 wants = [ "network-pre.target" ];
50 wantedBy = [ "multi-user.target" ];
51 reloadIfChanged = true;
54 RemainAfterExit = "yes";
55 ExecStart = "${cfg.package}/bin/ferm ${configFile}";
56 ExecReload = "${cfg.package}/bin/ferm ${configFile}";
57 ExecStop = "${cfg.package}/bin/ferm -F ${configFile}";