1 # This module defines global configuration for Haka.
3 { config, lib, pkgs, ... }:
9 cfg = config.services.haka;
13 hakaConf = pkgs.writeText "haka.conf"
16 configuration = ${if lib.strings.hasPrefix "/" cfg.configFile
17 then "${cfg.configFile}"
18 else "${haka}/share/haka/sample/${cfg.configFile}"}
19 ${optionalString (builtins.lessThan 0 cfg.threads) "thread = ${cfg.threads}"}
22 ${optionalString cfg.pcap ''module = "packet/pcap"''}
23 ${optionalString cfg.nfqueue ''module = "packet/nqueue"''}
24 ${optionalString cfg.dump.enable ''dump = "yes"''}
25 ${optionalString cfg.dump.enable ''dump_input = "${cfg.dump.input}"''}
26 ${optionalString cfg.dump.enable ''dump_output = "${cfg.dump.output}"''}
28 interfaces = "${lib.strings.concatStringsSep "," cfg.interfaces}"
31 # Select the log module
34 # Set the default logging level
35 #level = "info,packet=debug"
38 # Select the alert module
39 module = "alert/syslog"
41 # Disable alert on standard output
44 # alert/file module option
58 enable = mkEnableOption "Haka";
60 package = mkPackageOption pkgs "haka" { };
62 configFile = mkOption {
63 default = "empty.lua";
64 example = "/srv/haka/myfilter.lua";
67 Specify which configuration file Haka uses.
68 It can be absolute path or a path relative to the sample directory of
73 interfaces = mkOption {
76 type = with types; listOf str;
78 Specify which interface(s) Haka listens to.
79 Use 'any' to listen to all interfaces.
88 The number of threads that will be used.
89 All system threads are used by default.
96 description = "Whether to enable pcap";
99 nfqueue = mkEnableOption "nfqueue";
101 dump.enable = mkEnableOption "dump";
102 dump.input = mkOption {
103 default = "/tmp/input.pcap";
104 example = "/path/to/file.pcap";
106 description = "Path to file where incoming packets are dumped";
109 dump.output = mkOption {
110 default = "/tmp/output.pcap";
111 example = "/path/to/file.pcap";
113 description = "Path to file where outgoing packets are dumped";
119 ###### implementation
121 config = mkIf cfg.enable {
124 { assertion = cfg.pcap != cfg.nfqueue;
125 message = "either pcap or nfqueue can be enabled, not both.";
127 { assertion = cfg.nfqueue -> !dump.enable;
128 message = "dump can only be used with nfqueue.";
130 { assertion = cfg.interfaces != [];
131 message = "at least one interface must be specified.";
135 environment.systemPackages = [ haka ];
137 systemd.services.haka = {
138 description = "Haka";
139 wantedBy = [ "multi-user.target" ];
140 after = [ "network.target" ];
142 ExecStart = "${haka}/bin/haka -c ${hakaConf}";
143 ExecStop = "${haka}/bin/hakactl stop";