1 { config, pkgs, lib, ... }:
3 cfg = config.services.plikd;
5 format = pkgs.formats.toml {};
6 plikdCfg = format.generate "plikd.cfg" cfg.settings;
11 enable = lib.mkEnableOption "plikd, a temporary file upload system";
13 openFirewall = lib.mkOption {
14 type = lib.types.bool;
16 description = "Open ports in the firewall for the plikd.";
19 settings = lib.mkOption {
23 Configuration for plikd, see <https://github.com/root-gg/plik/blob/master/server/plikd.cfg>
30 config = lib.mkIf cfg.enable {
31 services.plikd.settings = lib.mapAttrs (name: lib.mkDefault) {
33 ListenAddress = "localhost";
36 Directory = "/var/lib/plikd";
38 MetadataBackendConfig = {
40 ConnectionString = "/var/lib/plikd/plik.db";
44 systemd.services.plikd = {
45 description = "Plikd file sharing server";
46 after = [ "network.target" ];
47 wantedBy = [ "multi-user.target" ];
50 ExecStart = "${pkgs.plikd}/bin/plikd --config ${plikdCfg}";
51 Restart = "on-failure";
52 StateDirectory = "plikd";
53 LogsDirectory = "plikd";
57 NoNewPrivileges = "yes";
59 PrivateDevices = "yes";
60 DevicePolicy = "closed";
61 ProtectSystem = "strict";
62 ProtectHome = "read-only";
63 ProtectControlGroups = "yes";
64 ProtectKernelModules = "yes";
65 ProtectKernelTunables = "yes";
66 RestrictAddressFamilies = "AF_UNIX AF_INET AF_INET6 AF_NETLINK";
67 RestrictNamespaces = "yes";
68 RestrictRealtime = "yes";
69 RestrictSUIDSGID = "yes";
70 MemoryDenyWriteExecute = "yes";
71 LockPersonality = "yes";
75 networking.firewall = lib.mkIf cfg.openFirewall {
76 allowedTCPPorts = [ cfg.settings.ListenPort ];