1 { config, lib, pkgs, ... }:
4 cfg = config.services.transfer-sh;
6 mkDefault mkEnableOption mkPackageOption mkIf mkOption
7 types mapAttrs isBool getExe boolToString optionalAttrs;
10 options.services.transfer-sh = {
11 enable = mkEnableOption "Easy and fast file sharing from the command-line";
13 package = mkPackageOption pkgs "transfer-sh" { };
16 type = types.submodule { freeformType = with types; attrsOf (oneOf [ bool int str ]); };
20 BASEDIR = "/var/lib/transfer.sh";
21 TLS_LISTENER_ONLY = false;
24 Additional configuration for transfer-sh, see
25 <https://github.com/dutchcoders/transfer.sh#usage-1>
28 For secrets use secretFile option instead.
33 type = types.enum [ "local" "s3" "storj" "gdrive" ];
35 description = "Storage providers to use";
38 secretFile = mkOption {
39 type = types.nullOr types.path;
41 example = "/run/secrets/transfer-sh.env";
43 Path to file containing environment variables.
44 Useful for passing down secrets.
45 Some variables that can be considered secrets are:
56 localProvider = (cfg.provider == "local");
57 stateDirectory = "/var/lib/transfer.sh";
61 services.transfer-sh.settings = {
62 LISTENER = mkDefault ":8080";
63 } // optionalAttrs localProvider {
64 BASEDIR = mkDefault stateDirectory;
67 systemd.services.transfer-sh = {
68 after = [ "network.target" ];
69 wantedBy = [ "multi-user.target" ];
70 environment = mapAttrs (_: v: if isBool v then boolToString v else toString v) cfg.settings;
72 CapabilityBoundingSet = [ "CAP_NET_BIND_SERVICE" ];
73 DevicePolicy = "closed";
75 ExecStart = "${getExe cfg.package} --provider ${cfg.provider}";
76 LockPersonality = true;
77 MemoryDenyWriteExecute = true;
78 PrivateDevices = true;
81 ProtectControlGroups = true;
82 ProtectHostname = true;
83 ProtectKernelLogs = true;
84 ProtectKernelModules = true;
85 ProtectKernelTunables = true;
86 ProtectProc = "invisible";
87 RestrictAddressFamilies = [ "AF_INET" "AF_INET6" ];
88 RestrictNamespaces = true;
89 RestrictRealtime = true;
90 SystemCallArchitectures = [ "native" ];
91 SystemCallFilter = [ "@system-service" ];
92 StateDirectory = baseNameOf stateDirectory;
93 } // optionalAttrs (cfg.secretFile != null) {
94 EnvironmentFile = cfg.secretFile;
95 } // optionalAttrs localProvider {
96 ReadWritePaths = cfg.settings.BASEDIR;
101 meta.maintainers = with lib.maintainers; [ ocfox ];