Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nixos/seafile: add optional seafdav service #152069

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions nixos/modules/services/networking/seafile.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ let

seafileConf = settingsFormat.generate "seafile.conf" cfg.seafileSettings;

seafdavConf = settingsFormat.generate "seafdav.conf" {
WEBDAV = cfg.seafdavSettings;
};

seahubSettings = pkgs.writeText "seahub_settings.py" ''
FILE_SERVER_ROOT = '${cfg.ccnetSettings.General.SERVICE_URL}/seafhttp'
DATABASES = {
Expand Down Expand Up @@ -93,6 +97,37 @@ in {
'';
};

seafdavSettings = mkOption {
type = types.submodule {
freeformType = settingsFormat.type;

options = {
enabled = mkEnableOption "seafdav server to access seafile through webdav";
port = mkOption {
type = types.port;
default = 6001;
description = ''
The tcp port used by seafdav.
'';
};
share_name = mkOption {
type = types.str;
default = "/";
description = ''
The location of the seafile webdav share.
This could be set to the location of a reverse proxy for seafdav.
'';
};
};
};
default = { };
description = ''
Configuration for seafdav set under the WEBDAV section, see
<link xlink:href="https://manual.seafile.com/extension/webdav/"/>
for supported values.
'';
};

workers = mkOption {
type = types.int;
default = 4;
Expand Down Expand Up @@ -282,6 +317,38 @@ in {
fi
'';
};

seafdav = mkIf cfg.seafdavSettings.enabled {
description = "seafdav Server for WebDAV access to seafile";
wantedBy = [ "seafile.target" ];
partOf = [ "seafile.target" ];
after = [ "network.target" "seaf-server.service" ];
requires = [ "seaf-server" ];
restartTriggers = [ seafdavConf ];
environment = {
PYTHONPATH = "/etc/seafile"; # seafdav imports seahub_settings.py
SEAFDAV_CONF = seafdavConf;
CCNET_CONF_DIR = ccnetDir;
SEAFILE_CONF_DIR = dataDir;
SEAFILE_CENTRAL_CONF_DIR = "/etc/seafile";
SEAFILE_RPC_PIPE_PATH = "/run/seafile";
};
serviceConfig = securityOptions // {
User = "seafile";
Group = "seafile";
DynamicUser = true;
RuntimeDirectory = "seafile";
StateDirectory = "seafile";
LogsDirectory = "seafile";
ExecStart = ''
${pkgs.seafdav}/bin/wsgidav \
--root=/ \
--server=gunicorn \
--log-file=/var/log/seafile/seafdav.log \
--port=${toString cfg.seafdavSettings.port}
'';
};
};
};
};
}
9 changes: 9 additions & 0 deletions nixos/tests/seafile.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,16 @@ import ./make-test-python.nix ({ pkgs, ... }:
ccnetSettings.General.SERVICE_URL = "http://server";
adminEmail = "[email protected]";
initialAdminPassword = "seafile_password";
seafdavSettings = {
enabled = true;
share_name = "/seafdav";
};
};
services.nginx = {
enable = true;
virtualHosts."server" = {
locations."/".proxyPass = "http://unix:/run/seahub/gunicorn.sock";
locations."/seafdav".proxyPass = "http://127.0.0.1:6001";
locations."/seafhttp" = {
proxyPass = "http://127.0.0.1:8082";
extraConfig = ''
Expand Down Expand Up @@ -50,6 +55,7 @@ import ./make-test-python.nix ({ pkgs, ... }:

with subtest("start seahub"):
server.wait_for_unit("seahub.service")
server.wait_for_unit("seafdav.service")
server.wait_for_unit("nginx.service")
server.wait_for_file("/run/seahub/gunicorn.sock")

Expand Down Expand Up @@ -117,5 +123,8 @@ import ./make-test-python.nix ({ pkgs, ... }:
client2.succeed("ls -la test01 >&2")

client2.succeed('[ `cat test01/first_file` = "bla" ]')

with subtest("seafdav query"):
client1.succeed("curl --anyauth --user '[email protected]:seafile_password' http://server/seafdav | grep 'Authenticated user' >&2")
'';
})
30 changes: 30 additions & 0 deletions pkgs/development/python-modules/seafobj/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{ lib
, fetchFromGitHub
, buildPythonPackage
}:

buildPythonPackage rec {
pname = "seafobj";
version = "unstable-2021-07-08";

src = fetchFromGitHub {
owner = "haiwen";
repo = "seafobj";
rev = "df13a98e7e32c926083ca60bb7fb1bbc4dfcdbd0";
sha256 = "0jwgbx083mwwh18x7450igq748bbld9s7zgibwv1cxwrrny1aari";
};

patches = [
./setuptools.patch
];

doCheck = false; # disabled because it requires a ccnet environment

meta = with lib; {
homepage = "https://github.com/haiwen/seafobj";
description = "Python library for accessing seafile data model";
license = licenses.asl20;
platforms = platforms.linux;
maintainers = with maintainers; [ pacman99 ];
};
}
24 changes: 24 additions & 0 deletions pkgs/development/python-modules/seafobj/setuptools.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
diff --git a/setup.py b/setup.py
new file mode 100644
index 0000000..898cbe7
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,18 @@
+from setuptools import setup, find_packages
+
+__version__ = '7.0.0'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this should be changed since you didn't actually package version 7.0.0.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess I packaged the pre-release of the next version, but then I'd have to predict what the next version number for seafobj would be.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Filed an issue upstream for adding setuptools support: haiwen/seafobj#57

+
+
+setup(name='seafobj',
+ version=__version__,
+ license='ASL2',
+ description='python library for accessing seafile data model',
+ author='Shuai Lin',
+ author_email='[email protected]',
+ url='http://seafile.com',
+ platforms=['Any'],
+ packages=find_packages(exclude=["test.*", "test"]),
+ classifiers=['Development Status :: 4 - Beta',
+ 'License :: OSI Approved :: Apache Software License',
+ 'Operating System :: OS Independent',
+ 'Programming Language :: Python'])
40 changes: 40 additions & 0 deletions pkgs/servers/seafdav/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{ lib, fetchFromGitHub, python3 }:

python3.pkgs.buildPythonApplication rec {
pname = "seafdav";
version = "unstable-2021-05-09";

src = fetchFromGitHub {
owner = "haiwen";
repo = "seafdav";
rev = "0f178088879a8d03c22d9a6b55e7e7ddc39a0c0c"; # using a fixed revision because upstream may re-tag releases :/
sha256 = "1gpvmfamjbw90gh9njgmba58qnzxji1w1sra46spnhi9k778mds3";
};

doCheck = false; # disabled because it requires a ccnet environment


propagatedBuildInputs = with python3.pkgs; [
seaserv
seafobj
defusedxml
pysearpc
future
gunicorn
jinja2
json5
python-pam
pyyaml
six
lxml
sqlalchemy
];

meta = with lib; {
homepage = "https://github.com/haiwen/seafdav";
description = "WebDAV server for seafile";
license = licenses.mit;
platforms = platforms.linux;
maintainers = with maintainers; [ pacman99 ];
};
}
2 changes: 2 additions & 0 deletions pkgs/top-level/all-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -33709,6 +33709,8 @@ with pkgs;

seafile-shared = callPackage ../misc/seafile-shared { };

seafdav = callPackage ../servers/seafdav { };

ser2net = callPackage ../servers/ser2net {};

serviio = callPackage ../servers/serviio {};
Expand Down
2 changes: 2 additions & 0 deletions pkgs/top-level/python-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8863,6 +8863,8 @@ in {

seabreeze = callPackage ../development/python-modules/seabreeze { };

seafobj = callPackage ../development/python-modules/seafobj { };

seaserv = toPythonModule (pkgs.seafile-server.override {
python3 = self.python;
});
Expand Down