2e751c0772
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.
156 lines
3.8 KiB
Nix
156 lines
3.8 KiB
Nix
# This module defines global configuration for Haka.
|
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
with lib;
|
|
|
|
let
|
|
|
|
cfg = config.services.haka;
|
|
|
|
haka = cfg.package;
|
|
|
|
hakaConf = pkgs.writeText "haka.conf"
|
|
''
|
|
[general]
|
|
configuration = ${if lib.strings.hasPrefix "/" cfg.configFile
|
|
then "${cfg.configFile}"
|
|
else "${haka}/share/haka/sample/${cfg.configFile}"}
|
|
${optionalString (builtins.lessThan 0 cfg.threads) "thread = ${cfg.threads}"}
|
|
|
|
[packet]
|
|
${optionalString cfg.pcap ''module = "packet/pcap"''}
|
|
${optionalString cfg.nfqueue ''module = "packet/nqueue"''}
|
|
${optionalString cfg.dump.enable ''dump = "yes"''}
|
|
${optionalString cfg.dump.enable ''dump_input = "${cfg.dump.input}"''}
|
|
${optionalString cfg.dump.enable ''dump_output = "${cfg.dump.output}"''}
|
|
|
|
interfaces = "${lib.strings.concatStringsSep "," cfg.interfaces}"
|
|
|
|
[log]
|
|
# Select the log module
|
|
module = "log/syslog"
|
|
|
|
# Set the default logging level
|
|
#level = "info,packet=debug"
|
|
|
|
[alert]
|
|
# Select the alert module
|
|
module = "alert/syslog"
|
|
|
|
# Disable alert on standard output
|
|
#alert_on_stdout = no
|
|
|
|
# alert/file module option
|
|
#file = "/dev/null"
|
|
'';
|
|
|
|
in
|
|
|
|
{
|
|
|
|
###### interface
|
|
|
|
options = {
|
|
|
|
services.haka = {
|
|
|
|
enable = mkEnableOption "Haka";
|
|
|
|
package = mkOption {
|
|
default = pkgs.haka;
|
|
defaultText = literalExpression "pkgs.haka";
|
|
type = types.package;
|
|
description = "
|
|
Which Haka derivation to use.
|
|
";
|
|
};
|
|
|
|
configFile = mkOption {
|
|
default = "empty.lua";
|
|
example = "/srv/haka/myfilter.lua";
|
|
type = types.str;
|
|
description = lib.mdDoc ''
|
|
Specify which configuration file Haka uses.
|
|
It can be absolute path or a path relative to the sample directory of
|
|
the haka git repo.
|
|
'';
|
|
};
|
|
|
|
interfaces = mkOption {
|
|
default = [ "eth0" ];
|
|
example = [ "any" ];
|
|
type = with types; listOf str;
|
|
description = lib.mdDoc ''
|
|
Specify which interface(s) Haka listens to.
|
|
Use 'any' to listen to all interfaces.
|
|
'';
|
|
};
|
|
|
|
threads = mkOption {
|
|
default = 0;
|
|
example = 4;
|
|
type = types.int;
|
|
description = lib.mdDoc ''
|
|
The number of threads that will be used.
|
|
All system threads are used by default.
|
|
'';
|
|
};
|
|
|
|
pcap = mkOption {
|
|
default = true;
|
|
type = types.bool;
|
|
description = lib.mdDoc "Whether to enable pcap";
|
|
};
|
|
|
|
nfqueue = mkEnableOption "nfqueue";
|
|
|
|
dump.enable = mkEnableOption "dump";
|
|
dump.input = mkOption {
|
|
default = "/tmp/input.pcap";
|
|
example = "/path/to/file.pcap";
|
|
type = types.path;
|
|
description = lib.mdDoc "Path to file where incoming packets are dumped";
|
|
};
|
|
|
|
dump.output = mkOption {
|
|
default = "/tmp/output.pcap";
|
|
example = "/path/to/file.pcap";
|
|
type = types.path;
|
|
description = lib.mdDoc "Path to file where outgoing packets are dumped";
|
|
};
|
|
};
|
|
};
|
|
|
|
|
|
###### implementation
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
assertions = [
|
|
{ assertion = cfg.pcap != cfg.nfqueue;
|
|
message = "either pcap or nfqueue can be enabled, not both.";
|
|
}
|
|
{ assertion = cfg.nfqueue -> !dump.enable;
|
|
message = "dump can only be used with nfqueue.";
|
|
}
|
|
{ assertion = cfg.interfaces != [];
|
|
message = "at least one interface must be specified.";
|
|
}];
|
|
|
|
|
|
environment.systemPackages = [ haka ];
|
|
|
|
systemd.services.haka = {
|
|
description = "Haka";
|
|
wantedBy = [ "multi-user.target" ];
|
|
after = [ "network.target" ];
|
|
serviceConfig = {
|
|
ExecStart = "${haka}/bin/haka -c ${hakaConf}";
|
|
ExecStop = "${haka}/bin/hakactl stop";
|
|
User = "root";
|
|
Type = "forking";
|
|
};
|
|
};
|
|
};
|
|
}
|