1 { config, lib, pkgs, ... }:
4 cfg = config.services.shorewall;
8 enable = lib.mkOption {
12 Whether to enable Shorewall IPv4 Firewall.
15 Enabling this service WILL disable the existing NixOS
16 firewall! Default firewall rules provided by packages are not
17 considered at the moment.
22 package = lib.mkOption {
24 default = pkgs.shorewall;
25 defaultText = "pkgs.shorewall";
26 description = "The shorewall package to use.";
28 configs = lib.mkOption {
29 type = types.attrsOf types.str;
32 This option defines the Shorewall configs.
33 The attribute name defines the name of the config,
34 and the attribute value defines the content of the config.
36 apply = lib.mapAttrs (name: text: pkgs.writeText "${name}" text);
41 config = lib.mkIf cfg.enable {
43 systemd.services.firewall.enable = false;
44 systemd.services.shorewall = {
45 description = "Shorewall IPv4 Firewall";
46 after = [ "ipset.target" ];
47 before = [ "network-pre.target" ];
48 wants = [ "network-pre.target" ];
49 wantedBy = [ "multi-user.target" ];
50 reloadIfChanged = true;
51 restartTriggers = lib.attrValues cfg.configs;
54 RemainAfterExit = "yes";
55 ExecStart = "${cfg.package}/bin/shorewall start";
56 ExecReload = "${cfg.package}/bin/shorewall reload";
57 ExecStop = "${cfg.package}/bin/shorewall stop";
60 install -D -d -m 750 /var/lib/shorewall
61 install -D -d -m 755 /var/lock/subsys
62 touch /var/log/shorewall.log
63 chown 750 /var/log/shorewall.log
67 etc = lib.mapAttrsToList
70 target = "shorewall/${name}";
73 systemPackages = [ cfg.package ];