2024-12-10 20:27:17 +01:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
pkgs,
|
|
|
|
...
|
|
|
|
}:
|
2024-01-25 01:58:23 +08:00
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.transfer-sh;
|
|
|
|
inherit (lib)
|
2024-12-10 20:27:17 +01:00
|
|
|
mkDefault
|
|
|
|
mkEnableOption
|
|
|
|
mkPackageOption
|
|
|
|
mkIf
|
|
|
|
mkOption
|
|
|
|
types
|
|
|
|
mapAttrs
|
|
|
|
isBool
|
|
|
|
getExe
|
|
|
|
boolToString
|
|
|
|
optionalAttrs
|
|
|
|
;
|
2024-01-25 01:58:23 +08:00
|
|
|
in
|
|
|
|
{
|
|
|
|
options.services.transfer-sh = {
|
2024-04-13 14:54:15 +02:00
|
|
|
enable = mkEnableOption "Easy and fast file sharing from the command-line";
|
2024-01-25 01:58:23 +08:00
|
|
|
|
|
|
|
package = mkPackageOption pkgs "transfer-sh" { };
|
|
|
|
|
|
|
|
settings = mkOption {
|
2024-12-10 20:27:17 +01:00
|
|
|
type = types.submodule {
|
|
|
|
freeformType =
|
|
|
|
with types;
|
|
|
|
attrsOf (oneOf [
|
|
|
|
bool
|
|
|
|
int
|
|
|
|
str
|
|
|
|
]);
|
|
|
|
};
|
2024-01-25 01:58:23 +08:00
|
|
|
default = { };
|
|
|
|
example = {
|
|
|
|
LISTENER = ":8080";
|
|
|
|
BASEDIR = "/var/lib/transfer.sh";
|
|
|
|
TLS_LISTENER_ONLY = false;
|
|
|
|
};
|
2024-04-13 14:54:15 +02:00
|
|
|
description = ''
|
2024-01-25 01:58:23 +08:00
|
|
|
Additional configuration for transfer-sh, see
|
|
|
|
<https://github.com/dutchcoders/transfer.sh#usage-1>
|
|
|
|
for supported values.
|
|
|
|
|
|
|
|
For secrets use secretFile option instead.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
provider = mkOption {
|
2024-12-10 20:27:17 +01:00
|
|
|
type = types.enum [
|
|
|
|
"local"
|
|
|
|
"s3"
|
|
|
|
"storj"
|
|
|
|
"gdrive"
|
|
|
|
];
|
2024-01-25 01:58:23 +08:00
|
|
|
default = "local";
|
2024-04-13 14:54:15 +02:00
|
|
|
description = "Storage providers to use";
|
2024-01-25 01:58:23 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
secretFile = mkOption {
|
|
|
|
type = types.nullOr types.path;
|
|
|
|
default = null;
|
|
|
|
example = "/run/secrets/transfer-sh.env";
|
2024-04-13 14:54:15 +02:00
|
|
|
description = ''
|
2024-01-25 01:58:23 +08:00
|
|
|
Path to file containing environment variables.
|
|
|
|
Useful for passing down secrets.
|
|
|
|
Some variables that can be considered secrets are:
|
|
|
|
- AWS_ACCESS_KEY
|
|
|
|
- AWS_ACCESS_KEY
|
|
|
|
- TLS_PRIVATE_KEY
|
|
|
|
- HTTP_AUTH_HTPASSWD
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config =
|
|
|
|
let
|
|
|
|
localProvider = (cfg.provider == "local");
|
|
|
|
stateDirectory = "/var/lib/transfer.sh";
|
|
|
|
in
|
2024-12-10 20:27:17 +01:00
|
|
|
mkIf cfg.enable {
|
|
|
|
services.transfer-sh.settings =
|
|
|
|
{
|
2024-01-25 01:58:23 +08:00
|
|
|
LISTENER = mkDefault ":8080";
|
2024-12-10 20:27:17 +01:00
|
|
|
}
|
|
|
|
// optionalAttrs localProvider {
|
2024-01-25 01:58:23 +08:00
|
|
|
BASEDIR = mkDefault stateDirectory;
|
|
|
|
};
|
|
|
|
|
2024-12-10 20:27:17 +01:00
|
|
|
systemd.services.transfer-sh = {
|
|
|
|
after = [ "network.target" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
environment = mapAttrs (_: v: if isBool v then boolToString v else toString v) cfg.settings;
|
|
|
|
serviceConfig =
|
|
|
|
{
|
2024-01-25 01:58:23 +08:00
|
|
|
DevicePolicy = "closed";
|
|
|
|
DynamicUser = true;
|
|
|
|
ExecStart = "${getExe cfg.package} --provider ${cfg.provider}";
|
|
|
|
LockPersonality = true;
|
|
|
|
MemoryDenyWriteExecute = true;
|
|
|
|
PrivateDevices = true;
|
|
|
|
PrivateUsers = true;
|
|
|
|
ProtectClock = true;
|
|
|
|
ProtectControlGroups = true;
|
|
|
|
ProtectHostname = true;
|
|
|
|
ProtectKernelLogs = true;
|
|
|
|
ProtectKernelModules = true;
|
|
|
|
ProtectKernelTunables = true;
|
|
|
|
ProtectProc = "invisible";
|
2024-12-10 20:27:17 +01:00
|
|
|
RestrictAddressFamilies = [
|
|
|
|
"AF_INET"
|
|
|
|
"AF_INET6"
|
|
|
|
];
|
2024-01-25 01:58:23 +08:00
|
|
|
RestrictNamespaces = true;
|
|
|
|
RestrictRealtime = true;
|
|
|
|
SystemCallArchitectures = [ "native" ];
|
|
|
|
SystemCallFilter = [ "@system-service" ];
|
|
|
|
StateDirectory = baseNameOf stateDirectory;
|
2024-12-10 20:27:17 +01:00
|
|
|
}
|
|
|
|
// optionalAttrs (cfg.secretFile != null) {
|
2024-01-25 01:58:23 +08:00
|
|
|
EnvironmentFile = cfg.secretFile;
|
2024-12-10 20:27:17 +01:00
|
|
|
}
|
|
|
|
// optionalAttrs localProvider {
|
2024-01-25 01:58:23 +08:00
|
|
|
ReadWritePaths = cfg.settings.BASEDIR;
|
|
|
|
};
|
|
|
|
};
|
2024-12-10 20:27:17 +01:00
|
|
|
};
|
2024-01-25 01:58:23 +08:00
|
|
|
|
|
|
|
meta.maintainers = with lib.maintainers; [ ocfox ];
|
|
|
|
}
|