nixos-seafile-overlay/seafile-server/default.nix

169 lines
5.5 KiB
Nix

{ stdenv
, lib
, fetchFromGitHub
, autoconf
, automake
, autoreconfHook
, pkgconfig
, curl
, libevent
, glib
, libuuid
, intltool
, sqlite
, withMysql ? true
, libmysqlclient
, libarchive
, libtool
, jansson
, vala
, fuse
, openssl
, oniguruma
, libevhtp
, libsearpc
, which
, # for SeaHub
python3
, python3Packages
}:
let
version = "8.0.3";
python = python3;
pythonPackages = python3Packages;
django = pythonPackages.django;
djangoModules = with pythonPackages; [ django-statici18n django-post_office django-picklefield django-formtools djangorestframework ];
seahubPythonDependencies = with pythonPackages; [
django
django-webpack-loader
future
captcha
gunicorn
pymysql
openpyxl
qrcode
dateutil
requests
pillow
pyjwt
pycryptodome
]
++ map (p: p.override { inherit django; }) djangoModules; # build django modules with required version
# defining them here to be able to expose them in a python environment as well
pythonEnvDeps = seahubPythonDependencies ++ [ libsearpc ];
seafile-server-core = stdenv.mkDerivation rec {
name = "seafile-server-core";
inherit version;
src = fetchFromGitHub {
owner = "haiwen";
repo = "seafile-server";
rev = "v${version}-server";
sha256 = "1wmbx4smf342b5pars1zm9af2i0yaq7kjj7ry0gr337gdpa4qn3b";
};
# patch to work with latest, non-vulnerable libevhtp
patches = [
./recent_libevhtp.patch
./django-version.patch
];
# `which` is called directly from python during buildPhase, so we need the binary
nativeBuildInputs = [ autoconf automake libtool pkgconfig vala autoreconfHook which pythonPackages.wrapPython ];
buildInputs = [ sqlite glib python libuuid openssl oniguruma fuse libarchive libevent libevhtp ];
propagatedBuildInputs = pythonEnvDeps;
# copy manual to required location
postInstall = ''
mkdir $out/doc
cp ${src}/doc/*.doc $out/doc/
'';
# prevent doc directory from being moved to share in fixupPhase
forceShare = [ "man" "info" ];
postFixup = ''
buildPythonPath $propagatedBuildInputs
wrapPythonProgramsIn "$out/bin" "$out $pythonPath"
'';
checkPhase = "bash ./run_tests.sh";
meta = with lib; {
license = licenses.agpl3; # with additional OpenSSL linking exception
maintainers = with maintainers; [ schmittlauch ];
};
};
seahub = pythonPackages.buildPythonApplication rec {
name = "seahub";
inherit version;
src = fetchFromGitHub {
owner = "haiwen";
repo = "seahub";
rev = "v${version}-server";
sha256 = "0vfkiavsmpjm6wjr5rcnmnpnb3rxr3svwk8fsh5c76zg87ckdz4d";
};
phases = [ "unpackPhase" "installPhase" "fixupPhase" "distPhase" ];
buildInputs = [ python pythonPackages.wrapPython ];
propagatedBuildInputs = seahubPythonDependencies ++ [ pythonPackages.seafile-bindings ]; # for `seaserv` module
installPhase = ''
cp -r ./ $out
cd "$out"
${python.interpreter} -m compileall ./
buildPythonPath $propagatedBuildInputs
set -x
patchPythonScript manage.py
'';
meta = with lib; {
license = licenses.asl20;
maintainers = with maintainers; [ schmittlauch ];
};
};
buildInputs = [ vala fuse libsearpc libuuid sqlite openssl libarchive libevent glib python ]
++ lib.optional (!withMysql) "--without-mysql";
# `which` is called directly from python during buildPhase, so we need the binary
nativeBuildInputs = [ autoconf automake libtool pkgconfig autoreconfHook which ];
configureFlags = [ "--disable-static" ];
meta = {
description = "Internal communication framework and user/group management for Seafile server";
license = lib.licenses.agpl3; # with additional OpenSSL linking exception
};
in
stdenv.mkDerivation {
name = "seafile-server";
inherit version;
nativeBuildInputs = [ python3Packages.wrapPython ];
buildInputs = [ seahub seafile-server-core libsearpc ]
++ lib.optional withMysql libmysqlclient;
phases = [ "installPhase" "fixupPhase" "distPhase" ];
# create required directory structure
# Which files need to be copied is specified in the function `copy_scripts_and_libs`
# of ${seafile-server-core.src}/scripts/build/build-server.py
# The install script below has been hand crafted from that list of files and needs to be updated on new releases.
installPhase = ''
mkdir "$out"
cd "$out"
ln -s ${seahub} seahub
ln -s ${seafile-server-core} seafile-server
# copy general scripts
cp ${seafile-server-core.src}/scripts/{setup-seafile.sh,setup-seafile-mysql.sh,setup-seafile-mysql.py,seafile.sh,seahub.sh,reset-admin.sh,seaf-fuse.sh,check_init_admin.py,seaf-gc.sh,seaf-fsck.sh} .
# copy update scripts (and their sql)
cp -r ${seafile-server-core.src}/scripts/upgrade .
cp -r ${seafile-server-core.src}/scripts/sql .
# copy_user_manual is already done in the postInstall hook of seafile-server-core
# python admin scripts need to be made executable and patched with python path
chmod ugo+x *.py
buildPythonPath $propagatedBuildInputs
wrapPythonProgramsIn "$out/*.py" "$out $pythonPath"
echo -n "${version}" > installed_version
'';
meta = with lib; {
maintainers = with maintainers; [ schmittlauch ];
license = licenses.free; # components with different free software licenses are combined
};
inherit seafile-server-core seahub;# for using the path in the NixOS module
pythonEnv = python3.buildEnv.override {
extraLibs = pythonEnvDeps;
ignoreCollisions = true;
};
}