blob: 6d75558ae20deb20050fdbb689beb5c52a877e2f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
{ config, lib, pkgs, ... }:
let
cfg = config.services.filtron;
addressType = lib.types.submodule {
options = {
address = lib.mkOption {
type = lib.types.str;
default = "127.0.0.1";
};
port = lib.mkOption { type = lib.types.port; };
};
};
in {
options.services.filtron = {
enable = lib.mkEnableOption "filtron";
package = lib.mkOption {
type = lib.types.package;
default = pkgs.filtron;
description = ''
The package containing the filtron executable.
'';
};
api = lib.mkOption {
type = addressType;
default = { address = "localhost"; port = 4005; };
description = ''
API listen address and port.
'';
};
listen = lib.mkOption {
type = addressType;
default = { port = 4004; };
description = ''
Proxy listen address and port.
'';
};
target = lib.mkOption {
type = addressType;
default = { port = 8888; };
description = ''
Target address and port for reverse proxy.
'';
};
rules = lib.mkOption {
type = with lib.types; listOf (attrsOf anything);
description = ''
Rule list.
'';
};
readBufferSize = lib.mkOption {
type = lib.types.int;
default = 16384;
description = ''
Size of the buffer used for reading.
'';
};
};
config = lib.mkIf cfg.enable {
users.users.filtron = {
description = "Filtron daemon user";
group = "filtron";
isSystemUser = true;
};
users.groups.filtron = { };
systemd.services.filtron = {
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
description = "Start a filtron instance.";
serviceConfig = {
User = "filtron";
ExecStart = with builtins; ''
${cfg.package}/bin/filtron \
-rules ${toFile "filtron-rules.json" (toJSON cfg.rules)} \
-api "${cfg.api.address}:${toString cfg.api.port}" \
-listen "${cfg.listen.address}:${toString cfg.listen.port}" \
-target "${cfg.target.address}:${toString cfg.target.port}" \
-read-buffer-size ${toString cfg.readBufferSize}
'';
};
};
};
}
|