2020-04-24 23:36:52 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.ferm;
|
|
|
|
|
|
|
|
configFile = pkgs.stdenv.mkDerivation {
|
|
|
|
name = "ferm.conf";
|
|
|
|
text = cfg.config;
|
|
|
|
preferLocalBuild = true;
|
|
|
|
buildCommand = ''
|
|
|
|
echo -n "$text" > $out
|
|
|
|
${cfg.package}/bin/ferm --noexec $out
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
in {
|
|
|
|
options = {
|
|
|
|
services.ferm = {
|
|
|
|
enable = mkOption {
|
|
|
|
default = false;
|
|
|
|
type = types.bool;
|
2022-08-21 13:32:41 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Whether to enable Ferm Firewall.
|
|
|
|
*Warning*: Enabling this service WILL disable the existing NixOS
|
|
|
|
firewall! Default firewall rules provided by packages are not
|
|
|
|
considered at the moment.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
config = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Verbatim ferm.conf configuration.";
|
2020-04-24 23:36:52 +00:00
|
|
|
default = "";
|
2022-09-09 14:08:57 +00:00
|
|
|
defaultText = literalMD "empty firewall, allows any traffic";
|
2020-04-24 23:36:52 +00:00
|
|
|
type = types.lines;
|
|
|
|
};
|
2024-01-02 11:29:13 +00:00
|
|
|
package = mkPackageOption pkgs "ferm" { };
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
systemd.services.firewall.enable = false;
|
|
|
|
systemd.services.ferm = {
|
|
|
|
description = "Ferm Firewall";
|
|
|
|
after = [ "ipset.target" ];
|
|
|
|
before = [ "network-pre.target" ];
|
|
|
|
wants = [ "network-pre.target" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
reloadIfChanged = true;
|
|
|
|
serviceConfig = {
|
|
|
|
Type="oneshot";
|
|
|
|
RemainAfterExit = "yes";
|
|
|
|
ExecStart = "${cfg.package}/bin/ferm ${configFile}";
|
|
|
|
ExecReload = "${cfg.package}/bin/ferm ${configFile}";
|
|
|
|
ExecStop = "${cfg.package}/bin/ferm -F ${configFile}";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|