2018-03-14 04:25:55 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
let
|
|
|
|
types = lib.types;
|
|
|
|
cfg = config.services.shorewall6;
|
|
|
|
in {
|
|
|
|
options = {
|
|
|
|
services.shorewall6 = {
|
|
|
|
enable = lib.mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2022-08-30 01:30:04 +01:00
|
|
|
description = lib.mdDoc ''
|
2018-03-14 04:25:55 +00:00
|
|
|
Whether to enable Shorewall IPv6 Firewall.
|
2022-08-30 01:30:04 +01:00
|
|
|
|
|
|
|
::: {.warning}
|
|
|
|
Enabling this service WILL disable the existing NixOS
|
|
|
|
firewall! Default firewall rules provided by packages are not
|
|
|
|
considered at the moment.
|
|
|
|
:::
|
2018-03-14 04:25:55 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
package = lib.mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.shorewall;
|
2021-10-03 17:06:03 +01:00
|
|
|
defaultText = lib.literalExpression "pkgs.shorewall";
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc "The shorewall package to use.";
|
2018-03-14 04:25:55 +00:00
|
|
|
};
|
|
|
|
configs = lib.mkOption {
|
2020-03-04 22:44:35 +00:00
|
|
|
type = types.attrsOf types.lines;
|
2018-03-14 04:25:55 +00:00
|
|
|
default = {};
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc ''
|
2018-03-14 04:25:55 +00:00
|
|
|
This option defines the Shorewall configs.
|
|
|
|
The attribute name defines the name of the config,
|
|
|
|
and the attribute value defines the content of the config.
|
|
|
|
'';
|
2020-03-04 22:44:35 +00:00
|
|
|
apply = lib.mapAttrs (name: text: pkgs.writeText "${name}" text);
|
2018-03-14 04:25:55 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = lib.mkIf cfg.enable {
|
|
|
|
systemd.services.firewall.enable = false;
|
|
|
|
systemd.services.shorewall6 = {
|
|
|
|
description = "Shorewall IPv6 Firewall";
|
|
|
|
after = [ "ipset.target" ];
|
|
|
|
before = [ "network-pre.target" ];
|
|
|
|
wants = [ "network-pre.target" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
reloadIfChanged = true;
|
|
|
|
restartTriggers = lib.attrValues cfg.configs;
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "oneshot";
|
|
|
|
RemainAfterExit = "yes";
|
|
|
|
ExecStart = "${cfg.package}/bin/shorewall6 start";
|
|
|
|
ExecReload = "${cfg.package}/bin/shorewall6 reload";
|
|
|
|
ExecStop = "${cfg.package}/bin/shorewall6 stop";
|
|
|
|
};
|
|
|
|
preStart = ''
|
|
|
|
install -D -d -m 750 /var/lib/shorewall6
|
|
|
|
install -D -d -m 755 /var/lock/subsys
|
|
|
|
touch /var/log/shorewall6.log
|
|
|
|
chown 750 /var/log/shorewall6.log
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
environment = {
|
2020-03-04 22:44:35 +00:00
|
|
|
etc = lib.mapAttrs' (name: conf: lib.nameValuePair "shorewall6/${name}" {source=conf;}) cfg.configs;
|
2018-03-14 04:25:55 +00:00
|
|
|
systemPackages = [ cfg.package ];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|