tangled
alpha
login
or
join now
pyrox.dev
/
nixpkgs
0
fork
atom
lol
0
fork
atom
overview
issues
pulls
pipelines
tusd: init at 2.8.0
Niklas Hambüchen
11 months ago
5fad4242
429c338e
+139
4 changed files
expand all
collapse all
unified
split
nixos
tests
all-tests.nix
tusd
default.nix
tus-curl-upload.sh
pkgs
by-name
tu
tusd
package.nix
+1
nixos/tests/all-tests.nix
reviewed
···
1389
1389
tuptime = handleTest ./tuptime.nix { };
1390
1390
turbovnc-headless-server = handleTest ./turbovnc-headless-server.nix { };
1391
1391
turn-rs = handleTest ./turn-rs.nix { };
1392
1392
+
tusd = runTest ./tusd/default.nix;
1392
1393
tuxguitar = runTest ./tuxguitar.nix;
1393
1394
twingate = runTest ./twingate.nix;
1394
1395
typesense = handleTest ./typesense.nix { };
+50
nixos/tests/tusd/default.nix
reviewed
···
1
1
+
{ pkgs, lib, ... }:
2
2
+
3
3
+
let
4
4
+
port = 1080;
5
5
+
6
6
+
client =
7
7
+
{ pkgs, ... }:
8
8
+
{
9
9
+
environment.systemPackages = [ pkgs.curl ];
10
10
+
};
11
11
+
12
12
+
server =
13
13
+
{ pkgs, ... }:
14
14
+
{
15
15
+
# tusd does not have a NixOS service yet.
16
16
+
systemd.services.tusd = {
17
17
+
wantedBy = [ "multi-user.target" ];
18
18
+
19
19
+
serviceConfig = {
20
20
+
ExecStart = ''${pkgs.tusd}/bin/tusd -port "${toString port}" -upload-dir=/data'';
21
21
+
};
22
22
+
};
23
23
+
networking.firewall.allowedTCPPorts = [ port ];
24
24
+
};
25
25
+
in
26
26
+
{
27
27
+
name = "tusd";
28
28
+
meta.maintainers = with lib.maintainers; [
29
29
+
nh2
30
30
+
kalbasit
31
31
+
];
32
32
+
33
33
+
nodes = {
34
34
+
inherit server;
35
35
+
inherit client;
36
36
+
};
37
37
+
38
38
+
testScript = ''
39
39
+
server.wait_for_unit("tusd.service")
40
40
+
server.wait_for_open_port(${toString port})
41
41
+
42
42
+
# Create large file.
43
43
+
client.succeed("${pkgs.coreutils}/bin/truncate --size=100M file-100M.bin")
44
44
+
45
45
+
# Upload it.
46
46
+
client.succeed("${./tus-curl-upload.sh} file-100M.bin http://server:${toString port}/files/")
47
47
+
48
48
+
print("Upload succeeded")
49
49
+
'';
50
50
+
}
+50
nixos/tests/tusd/tus-curl-upload.sh
reviewed
···
1
1
+
#!/usr/bin/env bash
2
2
+
3
3
+
# Adapted from:
4
4
+
# - https://github.com/tus/tus.io/issues/96
5
5
+
6
6
+
if [ ! -f "${1}" ]; then
7
7
+
echo -e "\n\033[1;31m✘\033[0m First argument needs to be an existing file.\n"
8
8
+
exit 1
9
9
+
fi
10
10
+
11
11
+
if [ -z "${2}" ]; then
12
12
+
echo -e "\n\033[1;31m✘\033[0m Second argument needs to be the TUS server's URL.\n"
13
13
+
exit 1
14
14
+
fi
15
15
+
16
16
+
file=${1}
17
17
+
TUS_URL=${2}
18
18
+
filename=$(basename "${file}" | base64)
19
19
+
filesize="$(wc -c <"${file}")"
20
20
+
21
21
+
# Apparently 'Location: ..' is terminated by CRLF. grep and awk faithfully
22
22
+
# preserve the line ending, and the shell's $() substitution strips off the
23
23
+
# final LF leaving you with a string that just ends with a CR.
24
24
+
#
25
25
+
# When the CR is printed, the cursor moves to the beginning of the line and
26
26
+
# whatever gets printed next overwrites what was there.
27
27
+
# ... | tr -d '\015'
28
28
+
location=$(curl \
29
29
+
--silent --show-error \
30
30
+
-I \
31
31
+
-X POST \
32
32
+
-H "Tus-Resumable: 1.0.0" \
33
33
+
-H "Content-Length: 0" \
34
34
+
-H "Upload-Length: ${filesize}" \
35
35
+
-H "Upload-Metadata: name ${filename}" \
36
36
+
"${TUS_URL}" | grep 'Location:' | awk '{print $2}' | tr -d '\015')
37
37
+
38
38
+
if [ -n "${location}" ]; then
39
39
+
curl \
40
40
+
-X PATCH \
41
41
+
-H "Tus-Resumable: 1.0.0" \
42
42
+
-H "Upload-Offset: 0" \
43
43
+
-H "Content-Length: ${filesize}" \
44
44
+
-H "Content-Type: application/offset+octet-stream" \
45
45
+
--data-binary "@${file}" \
46
46
+
"${location}" -v
47
47
+
else
48
48
+
echo -e "\n\033[1;31m✘\033[0m File creation failed..\n"
49
49
+
exit 1
50
50
+
fi
+38
pkgs/by-name/tu/tusd/package.nix
reviewed
···
1
1
+
{
2
2
+
lib,
3
3
+
buildGoModule,
4
4
+
fetchFromGitHub,
5
5
+
nixosTests,
6
6
+
}:
7
7
+
8
8
+
buildGoModule rec {
9
9
+
pname = "tusd";
10
10
+
version = "2.8.0";
11
11
+
12
12
+
src = fetchFromGitHub {
13
13
+
owner = "tus";
14
14
+
repo = "tusd";
15
15
+
tag = "v${version}";
16
16
+
hash = "sha256-OzXBeLDjaJk4NVgsauR/NUATh7qHbuEfWNdhytZmd0A=";
17
17
+
};
18
18
+
19
19
+
vendorHash = "sha256-YununGyB72zE0tmqO3BREJeMTjCuy/1fhPHC5r8OLjg=";
20
20
+
21
21
+
# Tests need the path to the binary:
22
22
+
# https://github.com/tus/tusd/blob/0e52ad650abed02ec961353bb0c3c8bc36650d2c/internal/e2e/e2e_test.go#L37
23
23
+
preCheck = ''
24
24
+
export TUSD_BINARY=$PWD/../go/bin/tusd
25
25
+
'';
26
26
+
27
27
+
passthru.tests.tusd = nixosTests.tusd;
28
28
+
29
29
+
meta = {
30
30
+
description = "Reference server implementation in Go of tus: the open protocol for resumable file uploads";
31
31
+
license = lib.licenses.mit;
32
32
+
homepage = "https://tus.io/";
33
33
+
maintainers = with lib.maintainers; [
34
34
+
nh2
35
35
+
kalbasit
36
36
+
];
37
37
+
};
38
38
+
}