2016-08-21 22:12:19 +01: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;
|
|
|
|
description = ''
|
|
|
|
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 {
|
|
|
|
description = "Verbatim ferm.conf configuration.";
|
|
|
|
default = "";
|
2021-10-03 17:06:03 +01:00
|
|
|
defaultText = literalDocBook "empty firewall, allows any traffic";
|
2016-08-21 22:12:19 +01:00
|
|
|
type = types.lines;
|
|
|
|
};
|
|
|
|
package = mkOption {
|
|
|
|
description = "The ferm package.";
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.ferm;
|
2021-10-03 17:06:03 +01:00
|
|
|
defaultText = literalExpression "pkgs.ferm";
|
2016-08-21 22:12:19 +01: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" ];
|
2016-12-09 07:30:17 +00:00
|
|
|
reloadIfChanged = true;
|
2016-08-21 22:12:19 +01:00
|
|
|
serviceConfig = {
|
|
|
|
Type="oneshot";
|
|
|
|
RemainAfterExit = "yes";
|
|
|
|
ExecStart = "${cfg.package}/bin/ferm ${configFile}";
|
|
|
|
ExecReload = "${cfg.package}/bin/ferm ${configFile}";
|
|
|
|
ExecStop = "${cfg.package}/bin/ferm -F ${configFile}";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|