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