tangled
alpha
login
or
join now
tjh.dev
/
nixpkgs
Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
0
fork
atom
overview
issues
pulls
pipelines
nixos/plikd: Add new service module
freezeboy
5 years ago
fc2ae7d7
74bec372
+83
2 changed files
expand all
collapse all
unified
split
nixos
modules
module-list.nix
services
misc
plikd.nix
+1
nixos/modules/module-list.nix
···
509
509
./services/misc/paperless.nix
510
510
./services/misc/parsoid.nix
511
511
./services/misc/plex.nix
512
512
+
./services/misc/plikd.nix
512
513
./services/misc/tautulli.nix
513
514
./services/misc/pinnwand.nix
514
515
./services/misc/pykms.nix
+82
nixos/modules/services/misc/plikd.nix
···
1
1
+
{ config, pkgs, lib, ... }:
2
2
+
3
3
+
with lib;
4
4
+
5
5
+
let
6
6
+
cfg = config.services.plikd;
7
7
+
8
8
+
format = pkgs.formats.toml {};
9
9
+
plikdCfg = format.generate "plikd.cfg" cfg.settings;
10
10
+
in
11
11
+
{
12
12
+
options = {
13
13
+
services.plikd = {
14
14
+
enable = mkEnableOption "the plikd server";
15
15
+
16
16
+
openFirewall = mkOption {
17
17
+
type = types.bool;
18
18
+
default = false;
19
19
+
description = "Open ports in the firewall for the plikd.";
20
20
+
};
21
21
+
22
22
+
settings = mkOption {
23
23
+
type = format.type;
24
24
+
default = {};
25
25
+
description = ''
26
26
+
Configuration for plikd, see <link xlink:href="https://github.com/root-gg/plik/blob/master/server/plikd.cfg"/>
27
27
+
for supported values.
28
28
+
'';
29
29
+
};
30
30
+
};
31
31
+
};
32
32
+
33
33
+
config = mkIf cfg.enable {
34
34
+
services.plikd.settings = mapAttrs (name: mkDefault) {
35
35
+
ListenPort = 8080;
36
36
+
ListenAddress = "localhost";
37
37
+
DataBackend = "file";
38
38
+
DataBackendConfig = {
39
39
+
Directory = "/var/lib/plikd";
40
40
+
};
41
41
+
MetadataBackendConfig = {
42
42
+
Driver = "sqlite3";
43
43
+
ConnectionString = "/var/lib/plikd/plik.db";
44
44
+
};
45
45
+
};
46
46
+
47
47
+
systemd.services.plikd = {
48
48
+
description = "Plikd file sharing server";
49
49
+
after = [ "network.target" ];
50
50
+
wantedBy = [ "multi-user.target" ];
51
51
+
serviceConfig = {
52
52
+
Type = "simple";
53
53
+
ExecStart = "${pkgs.plikd}/bin/plikd --config ${plikdCfg}";
54
54
+
Restart = "on-failure";
55
55
+
StateDirectory = "plikd";
56
56
+
LogsDirectory = "plikd";
57
57
+
DynamicUser = true;
58
58
+
59
59
+
# Basic hardening
60
60
+
NoNewPrivileges = "yes";
61
61
+
PrivateTmp = "yes";
62
62
+
PrivateDevices = "yes";
63
63
+
DevicePolicy = "closed";
64
64
+
ProtectSystem = "strict";
65
65
+
ProtectHome = "read-only";
66
66
+
ProtectControlGroups = "yes";
67
67
+
ProtectKernelModules = "yes";
68
68
+
ProtectKernelTunables = "yes";
69
69
+
RestrictAddressFamilies = "AF_UNIX AF_INET AF_INET6 AF_NETLINK";
70
70
+
RestrictNamespaces = "yes";
71
71
+
RestrictRealtime = "yes";
72
72
+
RestrictSUIDSGID = "yes";
73
73
+
MemoryDenyWriteExecute = "yes";
74
74
+
LockPersonality = "yes";
75
75
+
};
76
76
+
};
77
77
+
78
78
+
networking.firewall = mkIf cfg.openFirewall {
79
79
+
allowedTCPPorts = [ cfg.settings.ListenPort ];
80
80
+
};
81
81
+
};
82
82
+
}