blob: b805b7b44d72e3f9be2ee627bd94119b4bf8fe0e (
plain) (
blame)
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
86
87
88
|
{ config, pkgs, lib, ... }:
with lib;
let
cfg = config.services.sniproxy;
configFile = pkgs.writeText "sniproxy.conf" ''
user ${cfg.user}
pidfile /run/sniproxy.pid
${cfg.config}
'';
in
{
imports = [ (mkRemovedOptionModule [ "services" "sniproxy" "logDir" ] "Now done by LogsDirectory=. Set to a custom path if you log to a different folder in your config.") ];
options = {
services.sniproxy = {
enable = mkEnableOption (lib.mdDoc "sniproxy server");
user = mkOption {
type = types.str;
default = "sniproxy";
description = lib.mdDoc "User account under which sniproxy runs.";
};
group = mkOption {
type = types.str;
default = "sniproxy";
description = lib.mdDoc "Group under which sniproxy runs.";
};
config = mkOption {
type = types.lines;
default = "";
description = lib.mdDoc "sniproxy.conf configuration excluding the daemon username and pid file.";
example = ''
error_log {
filename /var/log/sniproxy/error.log
}
access_log {
filename /var/log/sniproxy/access.log
}
listen 443 {
proto tls
}
table {
example.com 192.0.2.10
example.net 192.0.2.20
}
'';
};
};
};
config = mkIf cfg.enable {
systemd.services.sniproxy = {
description = "sniproxy server";
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
Type = "forking";
ExecStart = "${pkgs.sniproxy}/bin/sniproxy -c ${configFile}";
LogsDirectory = "sniproxy";
LogsDirectoryMode = "0640";
Restart = "always";
};
};
users.users = mkIf (cfg.user == "sniproxy") {
sniproxy = {
group = cfg.group;
uid = config.ids.uids.sniproxy;
};
};
users.groups = mkIf (cfg.group == "sniproxy") {
sniproxy = {
gid = config.ids.gids.sniproxy;
};
};
};
}
|