nixpkgs-suyu/nixos/modules/services/networking/shorewall.nix
pennae 2e751c0772 treewide: automatically md-convert option descriptions
the conversion procedure is simple:

 - find all things that look like options, ie calls to either `mkOption`
   or `lib.mkOption` that take an attrset. remember the attrset as the
   option
 - for all options, find a `description` attribute who's value is not a
   call to `mdDoc` or `lib.mdDoc`
 - textually convert the entire value of the attribute to MD with a few
   simple regexes (the set from mdize-module.sh)
 - if the change produced a change in the manual output, discard
 - if the change kept the manual unchanged, add some text to the
   description to make sure we've actually found an option. if the
   manual changes this time, keep the converted description

this procedure converts 80% of nixos options to markdown. around 2000
options remain to be inspected, but most of those fail the "does not
change the manual output check": currently the MD conversion process
does not faithfully convert docbook tags like <code> and <package>, so
any option using such tags will not be converted at all.
2022-07-30 15:16:34 +02:00

70 lines
2.4 KiB
Nix

{ config, lib, pkgs, ... }:
let
types = lib.types;
cfg = config.services.shorewall;
in {
options = {
services.shorewall = {
enable = lib.mkOption {
type = types.bool;
default = false;
description = ''
Whether to enable Shorewall IPv4 Firewall.
<warning>
<para>
Enabling this service WILL disable the existing NixOS
firewall! Default firewall rules provided by packages are not
considered at the moment.
</para>
</warning>
'';
};
package = lib.mkOption {
type = types.package;
default = pkgs.shorewall;
defaultText = lib.literalExpression "pkgs.shorewall";
description = lib.mdDoc "The shorewall package to use.";
};
configs = lib.mkOption {
type = types.attrsOf types.lines;
default = {};
description = lib.mdDoc ''
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.
'';
apply = lib.mapAttrs (name: text: pkgs.writeText "${name}" text);
};
};
};
config = lib.mkIf cfg.enable {
systemd.services.firewall.enable = false;
systemd.services.shorewall = {
description = "Shorewall IPv4 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/shorewall start";
ExecReload = "${cfg.package}/bin/shorewall reload";
ExecStop = "${cfg.package}/bin/shorewall stop";
};
preStart = ''
install -D -d -m 750 /var/lib/shorewall
install -D -d -m 755 /var/lock/subsys
touch /var/log/shorewall.log
chown 750 /var/log/shorewall.log
'';
};
environment = {
etc = lib.mapAttrs' (name: conf: lib.nameValuePair "shorewall/${name}" {source=conf;}) cfg.configs;
systemPackages = [ cfg.package ];
};
};
}