nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{ pkgs, ... }:
2let
3 client =
4 { config, pkgs, ... }:
5 {
6 environment.systemPackages = [
7 pkgs.seafile-shared
8 pkgs.curl
9 ];
10 };
11in
12{
13 name = "seafile";
14 meta = with pkgs.lib.maintainers; {
15 maintainers = [
16 kampfschlaefer
17 ];
18 };
19
20 nodes = {
21 server =
22 { config, pkgs, ... }:
23 {
24 services.seafile = {
25 enable = true;
26 ccnetSettings.General.SERVICE_URL = "http://server";
27 seafileSettings.fileserver.host = "unix:/run/seafile/server.sock";
28 adminEmail = "admin@example.com";
29 initialAdminPassword = "seafile_password";
30 };
31 services.nginx = {
32 enable = true;
33 virtualHosts."server" = {
34 locations."/".proxyPass = "http://unix:/run/seahub/gunicorn.sock";
35 locations."/seafhttp" = {
36 proxyPass = "http://unix:/run/seafile/server.sock";
37 extraConfig = ''
38 rewrite ^/seafhttp(.*)$ $1 break;
39 client_max_body_size 0;
40 proxy_connect_timeout 36000s;
41 proxy_read_timeout 36000s;
42 proxy_send_timeout 36000s;
43 send_timeout 36000s;
44 proxy_http_version 1.1;
45 '';
46 };
47 };
48 };
49 networking.firewall = {
50 allowedTCPPorts = [ 80 ];
51 };
52 };
53 client1 = client pkgs;
54 client2 = client pkgs;
55 };
56
57 testScript = ''
58 start_all()
59
60 with subtest("start seaf-server"):
61 server.wait_for_unit("seaf-server.service")
62 server.wait_for_file("/run/seafile/seafile.sock")
63
64 with subtest("start seahub"):
65 server.wait_for_unit("seahub.service")
66 server.wait_for_unit("nginx.service")
67 server.wait_for_file("/run/seahub/gunicorn.sock")
68
69 with subtest("client1 fetch seahub page"):
70 client1.succeed("curl -L http://server | grep 'Log In' >&2")
71
72 with subtest("client1 connect"):
73 client1.wait_for_unit("default.target")
74 client1.succeed("seaf-cli init -d . >&2")
75 client1.succeed("seaf-cli start >&2")
76 client1.succeed(
77 "seaf-cli list-remote -s http://server -u admin\@example.com -p seafile_password >&2"
78 )
79
80 libid = client1.succeed(
81 'seaf-cli create -s http://server -n test01 -u admin\@example.com -p seafile_password -t "first test library"'
82 ).strip()
83
84 client1.succeed(
85 "seaf-cli list-remote -s http://server -u admin\@example.com -p seafile_password |grep test01"
86 )
87 client1.fail(
88 "seaf-cli list-remote -s http://server -u admin\@example.com -p seafile_password |grep test02"
89 )
90
91 client1.succeed(
92 f"seaf-cli download -l {libid} -s http://server -u admin\@example.com -p seafile_password -d . >&2"
93 )
94
95 client1.wait_until_succeeds("seaf-cli status |grep synchronized >&2")
96
97 client1.succeed("ls -la >&2")
98 client1.succeed("ls -la test01 >&2")
99
100 client1.execute("echo bla > test01/first_file")
101
102 client1.wait_until_succeeds("seaf-cli status |grep synchronized >&2")
103
104 with subtest("client2 sync"):
105 client2.wait_for_unit("default.target")
106
107 client2.succeed("seaf-cli init -d . >&2")
108 client2.succeed("seaf-cli start >&2")
109
110 client2.succeed(
111 "seaf-cli list-remote -s http://server -u admin\@example.com -p seafile_password >&2"
112 )
113
114 libid = client2.succeed(
115 "seaf-cli list-remote -s http://server -u admin\@example.com -p seafile_password |grep test01 |cut -d' ' -f 2"
116 ).strip()
117
118 client2.succeed(
119 f"seaf-cli download -l {libid} -s http://server -u admin\@example.com -p seafile_password -d . >&2"
120 )
121
122 client2.wait_until_succeeds("seaf-cli status |grep synchronized >&2")
123
124 client2.succeed("ls -la test01 >&2")
125
126 client2.succeed('[ `cat test01/first_file` = "bla" ]')
127 '';
128}