2024-09-27 23:58:34 +00:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
pkgs,
|
|
|
|
...
|
|
|
|
}:
|
2021-04-20 18:06:57 +00:00
|
|
|
let
|
|
|
|
cfg = config.services.seafile;
|
|
|
|
settingsFormat = pkgs.formats.ini { };
|
|
|
|
|
2024-09-27 23:58:34 +00:00
|
|
|
ccnetConf = settingsFormat.generate "ccnet.conf" (
|
|
|
|
lib.attrsets.recursiveUpdate {
|
|
|
|
Database = {
|
|
|
|
ENGINE = "mysql";
|
|
|
|
UNIX_SOCKET = "/var/run/mysqld/mysqld.sock";
|
|
|
|
DB = "ccnet_db";
|
|
|
|
CONNECTION_CHARSET = "utf8";
|
|
|
|
};
|
|
|
|
} cfg.ccnetSettings
|
|
|
|
);
|
|
|
|
|
|
|
|
seafileConf = settingsFormat.generate "seafile.conf" (
|
|
|
|
lib.attrsets.recursiveUpdate {
|
|
|
|
database = {
|
|
|
|
type = "mysql";
|
|
|
|
unix_socket = "/var/run/mysqld/mysqld.sock";
|
|
|
|
db_name = "seafile_db";
|
|
|
|
connection_charset = "utf8";
|
|
|
|
};
|
|
|
|
} cfg.seafileSettings
|
|
|
|
);
|
2021-04-20 18:06:57 +00:00
|
|
|
|
|
|
|
seahubSettings = pkgs.writeText "seahub_settings.py" ''
|
|
|
|
FILE_SERVER_ROOT = '${cfg.ccnetSettings.General.SERVICE_URL}/seafhttp'
|
|
|
|
DATABASES = {
|
|
|
|
'default': {
|
2024-09-27 23:58:34 +00:00
|
|
|
'ENGINE': 'django.db.backends.mysql',
|
|
|
|
'NAME' : 'seahub_db',
|
|
|
|
'HOST' : '/var/run/mysqld/mysqld.sock',
|
2021-04-20 18:06:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
MEDIA_ROOT = '${seahubDir}/media/'
|
|
|
|
THUMBNAIL_ROOT = '${seahubDir}/thumbnail/'
|
|
|
|
|
2022-06-23 17:13:58 +00:00
|
|
|
SERVICE_URL = '${cfg.ccnetSettings.General.SERVICE_URL}'
|
|
|
|
|
2024-09-27 23:58:34 +00:00
|
|
|
CSRF_TRUSTED_ORIGINS = ["${cfg.ccnetSettings.General.SERVICE_URL}"]
|
|
|
|
|
2021-04-20 18:06:57 +00:00
|
|
|
with open('${seafRoot}/.seahubSecret') as f:
|
|
|
|
SECRET_KEY = f.readline().rstrip()
|
|
|
|
|
|
|
|
${cfg.seahubExtraConf}
|
|
|
|
'';
|
|
|
|
|
2024-09-27 23:58:34 +00:00
|
|
|
seafRoot = "/var/lib/seafile";
|
2021-04-20 18:06:57 +00:00
|
|
|
ccnetDir = "${seafRoot}/ccnet";
|
|
|
|
seahubDir = "${seafRoot}/seahub";
|
2024-07-04 05:38:48 +00:00
|
|
|
defaultUser = "seafile";
|
2021-04-20 18:06:57 +00:00
|
|
|
|
2023-08-16 11:39:28 +00:00
|
|
|
in
|
|
|
|
{
|
2021-04-20 18:06:57 +00:00
|
|
|
|
|
|
|
###### Interface
|
|
|
|
|
2024-09-27 23:58:34 +00:00
|
|
|
options.services.seafile = with lib; {
|
2024-04-13 12:54:15 +00:00
|
|
|
enable = mkEnableOption "Seafile server";
|
2021-04-20 18:06:57 +00:00
|
|
|
|
|
|
|
ccnetSettings = mkOption {
|
|
|
|
type = types.submodule {
|
|
|
|
freeformType = settingsFormat.type;
|
|
|
|
|
|
|
|
options = {
|
|
|
|
General = {
|
|
|
|
SERVICE_URL = mkOption {
|
2024-09-27 23:58:34 +00:00
|
|
|
type = types.singleLineStr;
|
2021-04-20 18:06:57 +00:00
|
|
|
example = "https://www.example.com";
|
2024-04-13 12:54:15 +00:00
|
|
|
description = ''
|
2021-04-20 18:06:57 +00:00
|
|
|
Seahub public URL.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
default = { };
|
2024-04-13 12:54:15 +00:00
|
|
|
description = ''
|
2021-04-20 18:06:57 +00:00
|
|
|
Configuration for ccnet, see
|
2022-07-28 21:19:15 +00:00
|
|
|
<https://manual.seafile.com/config/ccnet-conf/>
|
2021-04-20 18:06:57 +00:00
|
|
|
for supported values.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
seafileSettings = mkOption {
|
|
|
|
type = types.submodule {
|
|
|
|
freeformType = settingsFormat.type;
|
|
|
|
|
|
|
|
options = {
|
|
|
|
fileserver = {
|
|
|
|
port = mkOption {
|
|
|
|
type = types.port;
|
|
|
|
default = 8082;
|
2024-04-13 12:54:15 +00:00
|
|
|
description = ''
|
2021-04-20 18:06:57 +00:00
|
|
|
The tcp port used by seafile fileserver.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
host = mkOption {
|
2024-09-27 23:58:34 +00:00
|
|
|
type = types.singleLineStr;
|
|
|
|
default = "ipv4:127.0.0.1";
|
|
|
|
example = "unix:/run/seafile/server.sock";
|
2024-04-13 12:54:15 +00:00
|
|
|
description = ''
|
2024-09-27 23:58:34 +00:00
|
|
|
The bind address used by seafile fileserver.
|
|
|
|
|
|
|
|
The addr can be defined as one of the following:
|
|
|
|
- ipv6:<ipv6addr> for binding to an IPv6 address.
|
|
|
|
- unix:<named pipe> for binding to a unix named socket
|
|
|
|
- ipv4:<ipv4addr> for binding to an ipv4 address
|
|
|
|
Otherwise the addr is assumed to be ipv4.
|
2021-04-20 18:06:57 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
default = { };
|
2024-04-13 12:54:15 +00:00
|
|
|
description = ''
|
2021-04-20 18:06:57 +00:00
|
|
|
Configuration for seafile-server, see
|
2022-07-28 21:19:15 +00:00
|
|
|
<https://manual.seafile.com/config/seafile-conf/>
|
2021-04-20 18:06:57 +00:00
|
|
|
for supported values.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-09-27 23:58:34 +00:00
|
|
|
seahubAddress = mkOption {
|
|
|
|
type = types.singleLineStr;
|
|
|
|
default = "unix:/run/seahub/gunicorn.sock";
|
|
|
|
example = "[::1]:8083";
|
|
|
|
description = ''
|
|
|
|
Which address to bind the seahub server to, of the form:
|
|
|
|
- HOST
|
|
|
|
- HOST:PORT
|
|
|
|
- unix:PATH.
|
|
|
|
IPv6 HOSTs must be wrapped in brackets.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2021-04-20 18:06:57 +00:00
|
|
|
workers = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 4;
|
|
|
|
example = 10;
|
2024-04-13 12:54:15 +00:00
|
|
|
description = ''
|
2021-04-20 18:06:57 +00:00
|
|
|
The number of gunicorn worker processes for handling requests.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
adminEmail = mkOption {
|
|
|
|
example = "john@example.com";
|
2024-09-27 23:58:34 +00:00
|
|
|
type = types.singleLineStr;
|
2024-04-13 12:54:15 +00:00
|
|
|
description = ''
|
2021-04-20 18:06:57 +00:00
|
|
|
Seafile Seahub Admin Account Email.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
initialAdminPassword = mkOption {
|
|
|
|
example = "someStrongPass";
|
2024-09-27 23:58:34 +00:00
|
|
|
type = types.singleLineStr;
|
2024-04-13 12:54:15 +00:00
|
|
|
description = ''
|
2021-04-20 18:06:57 +00:00
|
|
|
Seafile Seahub Admin Account initial password.
|
2024-07-04 05:38:48 +00:00
|
|
|
Should be changed via Seahub web front-end.
|
2021-04-20 18:06:57 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-09-27 23:58:34 +00:00
|
|
|
seahubPackage = mkPackageOption pkgs "seahub" { };
|
2021-04-20 18:06:57 +00:00
|
|
|
|
2024-07-04 05:38:48 +00:00
|
|
|
user = mkOption {
|
2024-09-27 23:58:34 +00:00
|
|
|
type = types.singleLineStr;
|
2024-07-04 05:38:48 +00:00
|
|
|
default = defaultUser;
|
|
|
|
description = "User account under which seafile runs.";
|
|
|
|
};
|
|
|
|
|
|
|
|
group = mkOption {
|
2024-09-27 23:58:34 +00:00
|
|
|
type = types.singleLineStr;
|
2024-07-04 05:38:48 +00:00
|
|
|
default = defaultUser;
|
|
|
|
description = "Group under which seafile runs.";
|
|
|
|
};
|
|
|
|
|
|
|
|
dataDir = mkOption {
|
2024-09-27 23:58:34 +00:00
|
|
|
type = types.path;
|
|
|
|
default = "${seafRoot}/data";
|
2024-07-04 05:38:48 +00:00
|
|
|
description = "Path in which to store user data";
|
|
|
|
};
|
|
|
|
|
2024-09-27 23:58:34 +00:00
|
|
|
gc = {
|
|
|
|
enable = mkEnableOption "automatic garbage collection on stored data blocks";
|
|
|
|
|
|
|
|
dates = mkOption {
|
|
|
|
type = types.listOf types.singleLineStr;
|
|
|
|
default = [ "Sun 03:00:00" ];
|
|
|
|
description = ''
|
|
|
|
When to run garbage collection on stored data blocks.
|
|
|
|
The time format is described in {manpage}`systemd.time(7)`.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
randomizedDelaySec = mkOption {
|
|
|
|
default = "0";
|
|
|
|
type = types.singleLineStr;
|
|
|
|
example = "45min";
|
|
|
|
description = ''
|
|
|
|
Add a randomized delay before each garbage collection.
|
|
|
|
The delay will be chosen between zero and this value.
|
|
|
|
This value must be a time span in the format specified by
|
|
|
|
{manpage}`systemd.time(7)`
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
persistent = mkOption {
|
|
|
|
default = true;
|
|
|
|
type = types.bool;
|
|
|
|
example = false;
|
|
|
|
description = ''
|
|
|
|
Takes a boolean argument. If true, the time when the service
|
|
|
|
unit was last triggered is stored on disk. When the timer is
|
|
|
|
activated, the service unit is triggered immediately if it
|
|
|
|
would have been triggered at least once during the time when
|
|
|
|
the timer was inactive. Such triggering is nonetheless
|
|
|
|
subject to the delay imposed by RandomizedDelaySec=. This is
|
|
|
|
useful to catch up on missed runs of the service when the
|
|
|
|
system was powered down.
|
|
|
|
'';
|
|
|
|
};
|
2024-07-04 05:38:48 +00:00
|
|
|
};
|
|
|
|
|
2021-04-20 18:06:57 +00:00
|
|
|
seahubExtraConf = mkOption {
|
|
|
|
default = "";
|
2024-09-27 23:58:34 +00:00
|
|
|
example = ''
|
|
|
|
CSRF_TRUSTED_ORIGINS = ["https://example.com"]
|
|
|
|
'';
|
2021-04-20 18:06:57 +00:00
|
|
|
type = types.lines;
|
2024-04-13 12:54:15 +00:00
|
|
|
description = ''
|
2021-04-20 18:06:57 +00:00
|
|
|
Extra config to append to `seahub_settings.py` file.
|
2022-08-29 19:48:56 +00:00
|
|
|
Refer to <https://manual.seafile.com/config/seahub_settings_py/>
|
2021-04-20 18:06:57 +00:00
|
|
|
for all available options.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
###### Implementation
|
|
|
|
|
2024-09-27 23:58:34 +00:00
|
|
|
config = lib.mkIf cfg.enable {
|
|
|
|
services.mysql = {
|
|
|
|
enable = true;
|
|
|
|
package = lib.mkDefault pkgs.mariadb;
|
|
|
|
ensureDatabases = [
|
|
|
|
"ccnet_db"
|
|
|
|
"seafile_db"
|
|
|
|
"seahub_db"
|
|
|
|
];
|
|
|
|
ensureUsers = [
|
|
|
|
{
|
|
|
|
name = cfg.user;
|
|
|
|
ensurePermissions = {
|
|
|
|
"ccnet_db.*" = "ALL PRIVILEGES";
|
|
|
|
"seafile_db.*" = "ALL PRIVILEGES";
|
|
|
|
"seahub_db.*" = "ALL PRIVILEGES";
|
|
|
|
};
|
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
2021-04-20 18:06:57 +00:00
|
|
|
|
|
|
|
environment.etc."seafile/ccnet.conf".source = ccnetConf;
|
|
|
|
environment.etc."seafile/seafile.conf".source = seafileConf;
|
|
|
|
environment.etc."seafile/seahub_settings.py".source = seahubSettings;
|
|
|
|
|
2024-07-04 05:38:48 +00:00
|
|
|
users.users = lib.optionalAttrs (cfg.user == defaultUser) {
|
|
|
|
"${defaultUser}" = {
|
|
|
|
group = cfg.group;
|
|
|
|
isSystemUser = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-09-27 23:58:34 +00:00
|
|
|
users.groups = lib.optionalAttrs (cfg.group == defaultUser) { "${defaultUser}" = { }; };
|
2024-07-04 05:38:48 +00:00
|
|
|
|
2021-04-20 18:06:57 +00:00
|
|
|
systemd.targets.seafile = {
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
description = "Seafile components";
|
|
|
|
};
|
|
|
|
|
2023-08-16 11:39:28 +00:00
|
|
|
systemd.services =
|
|
|
|
let
|
2024-09-27 23:58:34 +00:00
|
|
|
serviceOptions = {
|
2023-08-16 11:39:28 +00:00
|
|
|
ProtectHome = true;
|
|
|
|
PrivateUsers = true;
|
|
|
|
PrivateDevices = true;
|
2024-07-04 05:38:48 +00:00
|
|
|
PrivateTmp = true;
|
|
|
|
ProtectSystem = "strict";
|
2023-08-16 11:39:28 +00:00
|
|
|
ProtectClock = true;
|
|
|
|
ProtectHostname = true;
|
|
|
|
ProtectProc = "invisible";
|
|
|
|
ProtectKernelModules = true;
|
|
|
|
ProtectKernelTunables = true;
|
|
|
|
ProtectKernelLogs = true;
|
|
|
|
ProtectControlGroups = true;
|
|
|
|
RestrictNamespaces = true;
|
2024-07-04 05:38:48 +00:00
|
|
|
RemoveIPC = true;
|
2023-08-16 11:39:28 +00:00
|
|
|
LockPersonality = true;
|
|
|
|
RestrictRealtime = true;
|
|
|
|
RestrictSUIDSGID = true;
|
2024-07-04 05:38:48 +00:00
|
|
|
NoNewPrivileges = true;
|
2023-08-16 11:39:28 +00:00
|
|
|
MemoryDenyWriteExecute = true;
|
|
|
|
SystemCallArchitectures = "native";
|
2024-09-27 23:58:34 +00:00
|
|
|
RestrictAddressFamilies = [
|
|
|
|
"AF_UNIX"
|
|
|
|
"AF_INET"
|
|
|
|
];
|
|
|
|
|
|
|
|
User = cfg.user;
|
|
|
|
Group = cfg.group;
|
|
|
|
StateDirectory = "seafile";
|
|
|
|
RuntimeDirectory = "seafile";
|
|
|
|
LogsDirectory = "seafile";
|
|
|
|
ConfigurationDirectory = "seafile";
|
|
|
|
ReadWritePaths = lib.lists.optional (cfg.dataDir != "${seafRoot}/data") cfg.dataDir;
|
2021-04-20 18:06:57 +00:00
|
|
|
};
|
2023-08-16 11:39:28 +00:00
|
|
|
in
|
|
|
|
{
|
|
|
|
seaf-server = {
|
|
|
|
description = "Seafile server";
|
|
|
|
partOf = [ "seafile.target" ];
|
2024-09-27 23:58:34 +00:00
|
|
|
unitConfig.RequiresMountsFor = lib.lists.optional (cfg.dataDir != "${seafRoot}/data") cfg.dataDir;
|
|
|
|
requires = [ "mysql.service" ];
|
|
|
|
after = [
|
|
|
|
"network.target"
|
|
|
|
"mysql.service"
|
|
|
|
];
|
2023-08-16 11:39:28 +00:00
|
|
|
wantedBy = [ "seafile.target" ];
|
2024-09-27 23:58:34 +00:00
|
|
|
restartTriggers = [
|
|
|
|
ccnetConf
|
|
|
|
seafileConf
|
|
|
|
];
|
|
|
|
serviceConfig = serviceOptions // {
|
2023-08-16 11:39:28 +00:00
|
|
|
ExecStart = ''
|
2024-09-27 23:58:34 +00:00
|
|
|
${lib.getExe cfg.seahubPackage.seafile-server} \
|
2023-08-16 11:39:28 +00:00
|
|
|
--foreground \
|
|
|
|
-F /etc/seafile \
|
|
|
|
-c ${ccnetDir} \
|
2024-09-27 23:58:34 +00:00
|
|
|
-d ${cfg.dataDir} \
|
2023-08-16 11:39:28 +00:00
|
|
|
-l /var/log/seafile/server.log \
|
|
|
|
-P /run/seafile/server.pid \
|
|
|
|
-p /run/seafile
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
preStart = ''
|
|
|
|
if [ ! -f "${seafRoot}/server-setup" ]; then
|
2024-09-27 23:58:34 +00:00
|
|
|
mkdir -p ${cfg.dataDir}/library-template
|
|
|
|
# Load schema on first install
|
|
|
|
${pkgs.mariadb.client}/bin/mysql --database=ccnet_db < ${cfg.seahubPackage.seafile-server}/share/seafile/sql/mysql/ccnet.sql
|
|
|
|
${pkgs.mariadb.client}/bin/mysql --database=seafile_db < ${cfg.seahubPackage.seafile-server}/share/seafile/sql/mysql/seafile.sql
|
|
|
|
echo "${cfg.seahubPackage.seafile-server.version}-mysql" > "${seafRoot}"/server-setup
|
|
|
|
echo Loaded MySQL schemas for first install
|
2023-08-16 11:39:28 +00:00
|
|
|
fi
|
|
|
|
# checking for upgrades and handling them
|
|
|
|
installedMajor=$(cat "${seafRoot}/server-setup" | cut -d"-" -f1 | cut -d"." -f1)
|
|
|
|
installedMinor=$(cat "${seafRoot}/server-setup" | cut -d"-" -f1 | cut -d"." -f2)
|
2024-09-27 23:58:34 +00:00
|
|
|
pkgMajor=$(echo "${cfg.seahubPackage.seafile-server.version}" | cut -d"." -f1)
|
|
|
|
pkgMinor=$(echo "${cfg.seahubPackage.seafile-server.version}" | cut -d"." -f2)
|
2021-04-20 18:06:57 +00:00
|
|
|
|
2023-08-16 11:39:28 +00:00
|
|
|
if [[ $installedMajor == $pkgMajor && $installedMinor == $pkgMinor ]]; then
|
|
|
|
:
|
2024-09-27 23:58:34 +00:00
|
|
|
elif [[ $installedMajor == 10 && $installedMinor == 0 && $pkgMajor == 11 && $pkgMinor == 0 ]]; then
|
|
|
|
# Upgrade from 10.0 to 11.0: migrate to mysql
|
|
|
|
echo Migrating from version 10 to 11
|
|
|
|
|
|
|
|
# From https://github.com/haiwen/seahub/blob/e12f941bfef7191795d8c72a7d339c01062964b2/scripts/sqlite2mysql.sh
|
|
|
|
|
|
|
|
echo Migrating ccnet database to MySQL
|
|
|
|
${lib.getExe pkgs.sqlite} ${ccnetDir}/PeerMgr/usermgr.db ".dump" | \
|
|
|
|
${lib.getExe cfg.seahubPackage.python3} ${cfg.seahubPackage}/scripts/sqlite2mysql.py > ${ccnetDir}/ccnet.sql
|
|
|
|
${lib.getExe pkgs.sqlite} ${ccnetDir}/GroupMgr/groupmgr.db ".dump" | \
|
|
|
|
${lib.getExe cfg.seahubPackage.python3} ${cfg.seahubPackage}/scripts/sqlite2mysql.py >> ${ccnetDir}/ccnet.sql
|
|
|
|
sed 's/ctime INTEGER/ctime BIGINT/g' -i ${ccnetDir}/ccnet.sql
|
|
|
|
sed 's/email TEXT, role TEXT/email VARCHAR(255), role TEXT/g' -i ${ccnetDir}/ccnet.sql
|
|
|
|
${pkgs.mariadb.client}/bin/mysql --database=ccnet_db < ${ccnetDir}/ccnet.sql
|
|
|
|
|
|
|
|
echo Migrating seafile database to MySQL
|
|
|
|
${lib.getExe pkgs.sqlite} ${cfg.dataDir}/seafile.db ".dump" | \
|
|
|
|
${lib.getExe cfg.seahubPackage.python3} ${cfg.seahubPackage}/scripts/sqlite2mysql.py > ${cfg.dataDir}/seafile.sql
|
|
|
|
sed 's/owner_id TEXT/owner_id VARCHAR(255)/g' -i ${cfg.dataDir}/seafile.sql
|
|
|
|
sed 's/user_name TEXT/user_name VARCHAR(255)/g' -i ${cfg.dataDir}/seafile.sql
|
|
|
|
${pkgs.mariadb.client}/bin/mysql --database=seafile_db < ${cfg.dataDir}/seafile.sql
|
|
|
|
|
|
|
|
echo Migrating seahub database to MySQL
|
|
|
|
echo 'SET FOREIGN_KEY_CHECKS=0;' > ${seahubDir}/seahub.sql
|
|
|
|
${lib.getExe pkgs.sqlite} ${seahubDir}/seahub.db ".dump" | \
|
|
|
|
${lib.getExe cfg.seahubPackage.python3} ${cfg.seahubPackage}/scripts/sqlite2mysql.py >> ${seahubDir}/seahub.sql
|
|
|
|
sed 's/`permission` , `reporter` text NOT NULL/`permission` longtext NOT NULL/g' -i ${seahubDir}/seahub.sql
|
|
|
|
sed 's/varchar(256) NOT NULL UNIQUE/varchar(255) NOT NULL UNIQUE/g' -i ${seahubDir}/seahub.sql
|
|
|
|
sed 's/, UNIQUE (`user_email`, `contact_email`)//g' -i ${seahubDir}/seahub.sql
|
|
|
|
sed '/INSERT INTO `base_dirfileslastmodifiedinfo`/d' -i ${seahubDir}/seahub.sql
|
|
|
|
sed '/INSERT INTO `notifications_usernotification`/d' -i ${seahubDir}/seahub.sql
|
|
|
|
sed 's/DEFERRABLE INITIALLY DEFERRED//g' -i ${seahubDir}/seahub.sql
|
|
|
|
${pkgs.mariadb.client}/bin/mysql --database=seahub_db < ${seahubDir}/seahub.sql
|
|
|
|
|
|
|
|
echo "${cfg.seahubPackage.seafile-server.version}-mysql" > "${seafRoot}"/server-setup
|
|
|
|
echo Migration complete
|
2023-08-16 11:39:28 +00:00
|
|
|
else
|
2024-09-27 23:58:34 +00:00
|
|
|
echo "Unsupported upgrade: $installedMajor.$installedMinor to $pkgMajor.$pkgMinor" >&2
|
2023-08-16 11:39:28 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
'';
|
2024-09-27 23:58:34 +00:00
|
|
|
|
|
|
|
# Fix unix socket permissions
|
|
|
|
postStart = (
|
|
|
|
lib.strings.optionalString (lib.strings.hasPrefix "unix:" cfg.seafileSettings.fileserver.host) ''
|
|
|
|
while [[ ! -S "${lib.strings.removePrefix "unix:" cfg.seafileSettings.fileserver.host}" ]]; do
|
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
chmod 666 "${lib.strings.removePrefix "unix:" cfg.seafileSettings.fileserver.host}"
|
|
|
|
''
|
|
|
|
);
|
2021-04-20 18:06:57 +00:00
|
|
|
};
|
2023-08-16 11:39:28 +00:00
|
|
|
|
|
|
|
seahub = {
|
|
|
|
description = "Seafile Server Web Frontend";
|
|
|
|
wantedBy = [ "seafile.target" ];
|
|
|
|
partOf = [ "seafile.target" ];
|
2024-09-27 23:58:34 +00:00
|
|
|
unitConfig.RequiresMountsFor = lib.lists.optional (cfg.dataDir != "${seafRoot}/data") cfg.dataDir;
|
|
|
|
requires = [
|
|
|
|
"mysql.service"
|
|
|
|
"seaf-server.service"
|
|
|
|
];
|
|
|
|
after = [
|
|
|
|
"network.target"
|
|
|
|
"mysql.service"
|
|
|
|
"seaf-server.service"
|
|
|
|
];
|
2023-08-16 11:39:28 +00:00
|
|
|
restartTriggers = [ seahubSettings ];
|
|
|
|
environment = {
|
2024-09-27 23:58:34 +00:00
|
|
|
PYTHONPATH = "${cfg.seahubPackage.pythonPath}:${cfg.seahubPackage}/thirdpart:${cfg.seahubPackage}";
|
2023-08-16 11:39:28 +00:00
|
|
|
DJANGO_SETTINGS_MODULE = "seahub.settings";
|
|
|
|
CCNET_CONF_DIR = ccnetDir;
|
2024-09-27 23:58:34 +00:00
|
|
|
SEAFILE_CONF_DIR = cfg.dataDir;
|
2023-08-16 11:39:28 +00:00
|
|
|
SEAFILE_CENTRAL_CONF_DIR = "/etc/seafile";
|
|
|
|
SEAFILE_RPC_PIPE_PATH = "/run/seafile";
|
|
|
|
SEAHUB_LOG_DIR = "/var/log/seafile";
|
|
|
|
};
|
2024-09-27 23:58:34 +00:00
|
|
|
serviceConfig = serviceOptions // {
|
2023-08-16 11:39:28 +00:00
|
|
|
RuntimeDirectory = "seahub";
|
|
|
|
ExecStart = ''
|
2024-09-27 23:58:34 +00:00
|
|
|
${lib.getExe cfg.seahubPackage.python3.pkgs.gunicorn} seahub.wsgi:application \
|
2023-08-16 11:39:28 +00:00
|
|
|
--name seahub \
|
|
|
|
--workers ${toString cfg.workers} \
|
|
|
|
--log-level=info \
|
|
|
|
--preload \
|
|
|
|
--timeout=1200 \
|
|
|
|
--limit-request-line=8190 \
|
2024-09-27 23:58:34 +00:00
|
|
|
--bind ${cfg.seahubAddress}
|
2023-08-16 11:39:28 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
preStart = ''
|
|
|
|
mkdir -p ${seahubDir}/media
|
|
|
|
# Link all media except avatars
|
2024-09-27 23:58:34 +00:00
|
|
|
for m in `find ${cfg.seahubPackage}/media/ -maxdepth 1 -not -name "avatars"`; do
|
2023-08-16 11:39:28 +00:00
|
|
|
ln -sf $m ${seahubDir}/media/
|
|
|
|
done
|
|
|
|
if [ ! -e "${seafRoot}/.seahubSecret" ]; then
|
2024-09-27 23:58:34 +00:00
|
|
|
(
|
|
|
|
umask 377 &&
|
|
|
|
${lib.getExe cfg.seahubPackage.python3} ${cfg.seahubPackage}/tools/secret_key_generator.py > ${seafRoot}/.seahubSecret
|
|
|
|
)
|
2023-08-16 11:39:28 +00:00
|
|
|
fi
|
|
|
|
if [ ! -f "${seafRoot}/seahub-setup" ]; then
|
|
|
|
# avatars directory should be writable
|
2024-09-27 23:58:34 +00:00
|
|
|
install -D -t ${seahubDir}/media/avatars/ ${cfg.seahubPackage}/media/avatars/default.png
|
|
|
|
install -D -t ${seahubDir}/media/avatars/groups ${cfg.seahubPackage}/media/avatars/groups/default.png
|
2023-08-16 11:39:28 +00:00
|
|
|
# init database
|
2024-09-27 23:58:34 +00:00
|
|
|
${cfg.seahubPackage}/manage.py migrate
|
2023-08-16 11:39:28 +00:00
|
|
|
# create admin account
|
2024-09-27 23:58:34 +00:00
|
|
|
${lib.getExe pkgs.expect} -c 'spawn ${cfg.seahubPackage}/manage.py createsuperuser --email=${cfg.adminEmail}; expect "Password: "; send "${cfg.initialAdminPassword}\r"; expect "Password (again): "; send "${cfg.initialAdminPassword}\r"; expect "Superuser created successfully."'
|
|
|
|
echo "${cfg.seahubPackage.version}-mysql" > "${seafRoot}/seahub-setup"
|
2023-08-16 11:39:28 +00:00
|
|
|
fi
|
|
|
|
if [ $(cat "${seafRoot}/seahub-setup" | cut -d"-" -f1) != "${pkgs.seahub.version}" ]; then
|
2024-09-27 23:58:34 +00:00
|
|
|
# run django migrations
|
|
|
|
${cfg.seahubPackage}/manage.py migrate
|
|
|
|
echo "${cfg.seahubPackage.version}-mysql" > "${seafRoot}/seahub-setup"
|
2023-08-16 11:39:28 +00:00
|
|
|
fi
|
2021-04-20 18:06:57 +00:00
|
|
|
'';
|
|
|
|
};
|
2024-07-04 05:38:48 +00:00
|
|
|
|
|
|
|
seaf-gc = {
|
|
|
|
description = "Seafile storage garbage collection";
|
2024-09-27 23:58:34 +00:00
|
|
|
conflicts = [
|
|
|
|
"seaf-server.service"
|
|
|
|
"seahub.service"
|
|
|
|
];
|
|
|
|
after = [
|
|
|
|
"seaf-server.service"
|
|
|
|
"seahub.service"
|
|
|
|
];
|
|
|
|
unitConfig.RequiresMountsFor = lib.lists.optional (cfg.dataDir != "${seafRoot}/data") cfg.dataDir;
|
|
|
|
onSuccess = [
|
|
|
|
"seaf-server.service"
|
|
|
|
"seahub.service"
|
|
|
|
];
|
|
|
|
onFailure = [
|
|
|
|
"seaf-server.service"
|
|
|
|
"seahub.service"
|
|
|
|
];
|
|
|
|
startAt = lib.lists.optionals cfg.gc.enable cfg.gc.dates;
|
|
|
|
serviceConfig = serviceOptions // {
|
2024-07-04 05:38:48 +00:00
|
|
|
Type = "oneshot";
|
|
|
|
};
|
|
|
|
script = ''
|
|
|
|
if [ ! -f "${seafRoot}/server-setup" ]; then
|
|
|
|
echo "Server not setup yet, GC not needed" >&2
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
|
|
|
# checking for pending upgrades
|
|
|
|
installedMajor=$(cat "${seafRoot}/server-setup" | cut -d"-" -f1 | cut -d"." -f1)
|
|
|
|
installedMinor=$(cat "${seafRoot}/server-setup" | cut -d"-" -f1 | cut -d"." -f2)
|
2024-09-27 23:58:34 +00:00
|
|
|
pkgMajor=$(echo "${cfg.seahubPackage.seafile-server.version}" | cut -d"." -f1)
|
|
|
|
pkgMinor=$(echo "${cfg.seahubPackage.seafile-server.version}" | cut -d"." -f2)
|
2024-07-04 05:38:48 +00:00
|
|
|
|
|
|
|
if [[ $installedMajor != $pkgMajor || $installedMinor != $pkgMinor ]]; then
|
|
|
|
echo "Server not upgraded yet" >&2
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Clean up user-deleted blocks and libraries
|
2024-09-27 23:58:34 +00:00
|
|
|
${cfg.seahubPackage.seafile-server}/bin/seafserv-gc \
|
2024-07-04 05:38:48 +00:00
|
|
|
-F /etc/seafile \
|
|
|
|
-c ${ccnetDir} \
|
2024-09-27 23:58:34 +00:00
|
|
|
-d ${cfg.dataDir} \
|
2024-07-04 05:38:48 +00:00
|
|
|
--rm-fs
|
|
|
|
'';
|
|
|
|
};
|
2021-04-20 18:06:57 +00:00
|
|
|
};
|
2024-09-27 23:58:34 +00:00
|
|
|
|
|
|
|
systemd.timers.seaf-gc = lib.mkIf cfg.gc.enable {
|
|
|
|
timerConfig = {
|
|
|
|
randomizedDelaySec = cfg.gc.randomizedDelaySec;
|
|
|
|
Persistent = cfg.gc.persistent;
|
|
|
|
};
|
|
|
|
};
|
2021-04-20 18:06:57 +00:00
|
|
|
};
|
2024-07-04 05:38:48 +00:00
|
|
|
|
2024-09-27 23:58:34 +00:00
|
|
|
meta.maintainers = with lib.maintainers; [
|
|
|
|
greizgh
|
|
|
|
schmittlauch
|
|
|
|
];
|
2021-04-20 18:06:57 +00:00
|
|
|
}
|