blob: cac9a32ec409fada494369c24cc1173694f35b5f (
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
|
{
pkgs,
lib,
config,
...
}:
let
cfg = config.services.local-content-share;
in
{
options.services.local-content-share = {
enable = lib.mkEnableOption "Local-Content-Share";
package = lib.mkPackageOption pkgs "local-content-share" { };
listenAddress = lib.mkOption {
type = lib.types.str;
default = "";
example = "127.0.0.1";
description = ''
Address on which the service will be available.
The service will listen on all interfaces if set to an empty string.
'';
};
port = lib.mkOption {
type = lib.types.port;
default = 8080;
description = "Port on which the service will be available";
};
openFirewall = lib.mkOption {
type = lib.types.bool;
default = false;
description = "Whether to automatically open the specified port in the firewall";
};
};
config = lib.mkIf cfg.enable {
systemd.services.local-content-share = {
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
Type = "simple";
DynamicUser = true;
User = "local-content-share";
StateDirectory = "local-content-share";
StateDirectoryMode = "0700";
WorkingDirectory = "/var/lib/local-content-share";
ExecStart = "${lib.getExe' cfg.package "local-content-share"} -listen=${cfg.listenAddress}:${toString cfg.port}";
Restart = "on-failure";
};
};
networking.firewall = lib.mkIf cfg.openFirewall {
allowedTCPPorts = [ cfg.port ];
};
};
meta.maintainers = with lib.maintainers; [ e-v-o-l-v-e ];
}
|