2020-11-28 20:31:55 +01:00
|
|
|
{ config, pkgs, lib, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.etebase-server;
|
|
|
|
|
2021-03-28 20:41:00 +02:00
|
|
|
iniFmt = pkgs.formats.ini {};
|
2020-11-28 20:31:55 +01:00
|
|
|
|
2021-03-28 20:41:00 +02:00
|
|
|
configIni = iniFmt.generate "etebase-server.ini" cfg.settings;
|
2020-11-28 20:31:55 +01:00
|
|
|
|
|
|
|
defaultUser = "etebase-server";
|
|
|
|
in
|
|
|
|
{
|
2021-03-28 20:41:00 +02:00
|
|
|
imports = [
|
|
|
|
(mkRemovedOptionModule
|
|
|
|
[ "services" "etebase-server" "customIni" ]
|
|
|
|
"Set the option `services.etebase-server.settings' instead.")
|
|
|
|
(mkRemovedOptionModule
|
|
|
|
[ "services" "etebase-server" "database" ]
|
|
|
|
"Set the option `services.etebase-server.settings.database' instead.")
|
|
|
|
(mkRenamedOptionModule
|
|
|
|
[ "services" "etebase-server" "secretFile" ]
|
|
|
|
[ "services" "etebase-server" "settings" "secret_file" ])
|
|
|
|
(mkRenamedOptionModule
|
|
|
|
[ "services" "etebase-server" "host" ]
|
|
|
|
[ "services" "etebase-server" "settings" "allowed_hosts" "allowed_host1" ])
|
|
|
|
];
|
|
|
|
|
2020-11-28 20:31:55 +01:00
|
|
|
options = {
|
|
|
|
services.etebase-server = {
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
example = true;
|
2024-04-13 14:54:15 +02:00
|
|
|
description = ''
|
2020-11-28 20:31:55 +01:00
|
|
|
Whether to enable the Etebase server.
|
|
|
|
|
2021-03-28 20:41:00 +02:00
|
|
|
Once enabled you need to create an admin user by invoking the
|
|
|
|
shell command `etebase-server createsuperuser` with
|
|
|
|
the user specified by the `user` option or a superuser.
|
2020-11-28 20:31:55 +01:00
|
|
|
Then you can login and create accounts on your-etebase-server.com/admin
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-01-23 23:08:51 +01:00
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
2024-03-01 22:55:27 +01:00
|
|
|
default = pkgs.python3.pkgs.etebase-server;
|
|
|
|
defaultText = literalExpression "pkgs.python3.pkgs.etebase-server";
|
2024-04-13 14:54:15 +02:00
|
|
|
description = "etebase-server package to use.";
|
2024-01-23 23:08:51 +01:00
|
|
|
};
|
|
|
|
|
2020-11-28 20:31:55 +01:00
|
|
|
dataDir = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "/var/lib/etebase-server";
|
2024-04-13 14:54:15 +02:00
|
|
|
description = "Directory to store the Etebase server data.";
|
2020-11-28 20:31:55 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
port = mkOption {
|
|
|
|
type = with types; nullOr port;
|
|
|
|
default = 8001;
|
2024-04-13 14:54:15 +02:00
|
|
|
description = "Port to listen on.";
|
2020-11-28 20:31:55 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
openFirewall = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2024-04-13 14:54:15 +02:00
|
|
|
description = ''
|
2020-11-28 20:31:55 +01:00
|
|
|
Whether to open ports in the firewall for the server.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
unixSocket = mkOption {
|
|
|
|
type = with types; nullOr str;
|
|
|
|
default = null;
|
2024-04-13 14:54:15 +02:00
|
|
|
description = "The path to the socket to bind to.";
|
2020-11-28 20:31:55 +01:00
|
|
|
example = "/run/etebase-server/etebase-server.sock";
|
|
|
|
};
|
|
|
|
|
2021-03-28 20:41:00 +02:00
|
|
|
settings = mkOption {
|
|
|
|
type = lib.types.submodule {
|
|
|
|
freeformType = iniFmt.type;
|
|
|
|
|
|
|
|
options = {
|
|
|
|
global = {
|
|
|
|
debug = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2024-04-13 14:54:15 +02:00
|
|
|
description = ''
|
2021-03-28 20:41:00 +02:00
|
|
|
Whether to set django's DEBUG flag.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
secret_file = mkOption {
|
|
|
|
type = with types; nullOr str;
|
|
|
|
default = null;
|
2024-04-13 14:54:15 +02:00
|
|
|
description = ''
|
2021-03-28 20:41:00 +02:00
|
|
|
The path to a file containing the secret
|
|
|
|
used as django's SECRET_KEY.
|
|
|
|
'';
|
|
|
|
};
|
2021-03-28 23:50:18 +02:00
|
|
|
static_root = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "${cfg.dataDir}/static";
|
2021-10-03 18:06:03 +02:00
|
|
|
defaultText = literalExpression ''"''${config.services.etebase-server.dataDir}/static"'';
|
2024-04-13 14:54:15 +02:00
|
|
|
description = "The directory for static files.";
|
2021-03-28 23:50:18 +02:00
|
|
|
};
|
2021-03-28 20:41:00 +02:00
|
|
|
media_root = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "${cfg.dataDir}/media";
|
2021-10-03 18:06:03 +02:00
|
|
|
defaultText = literalExpression ''"''${config.services.etebase-server.dataDir}/media"'';
|
2024-04-13 14:54:15 +02:00
|
|
|
description = "The media directory.";
|
2021-03-28 20:41:00 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
allowed_hosts = {
|
|
|
|
allowed_host1 = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "0.0.0.0";
|
|
|
|
example = "localhost";
|
2024-04-13 14:54:15 +02:00
|
|
|
description = ''
|
2021-03-28 20:41:00 +02:00
|
|
|
The main host that is allowed access.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
database = {
|
|
|
|
engine = mkOption {
|
|
|
|
type = types.enum [ "django.db.backends.sqlite3" "django.db.backends.postgresql" ];
|
|
|
|
default = "django.db.backends.sqlite3";
|
2024-04-13 14:54:15 +02:00
|
|
|
description = "The database engine to use.";
|
2021-03-28 20:41:00 +02:00
|
|
|
};
|
|
|
|
name = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "${cfg.dataDir}/db.sqlite3";
|
2021-10-03 18:06:03 +02:00
|
|
|
defaultText = literalExpression ''"''${config.services.etebase-server.dataDir}/db.sqlite3"'';
|
2024-04-13 14:54:15 +02:00
|
|
|
description = "The database name.";
|
2021-03-28 20:41:00 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2020-11-28 20:31:55 +01:00
|
|
|
};
|
2021-03-28 20:41:00 +02:00
|
|
|
default = {};
|
2024-04-13 14:54:15 +02:00
|
|
|
description = ''
|
2022-08-13 05:15:06 +02:00
|
|
|
Configuration for `etebase-server`. Refer to
|
2021-03-28 20:41:00 +02:00
|
|
|
<https://github.com/etesync/server/blob/master/etebase-server.ini.example>
|
|
|
|
and <https://github.com/etesync/server/wiki>
|
|
|
|
for details on supported values.
|
2020-11-28 20:31:55 +01:00
|
|
|
'';
|
2021-03-28 20:41:00 +02:00
|
|
|
example = {
|
|
|
|
global = {
|
|
|
|
debug = true;
|
|
|
|
media_root = "/path/to/media";
|
|
|
|
};
|
|
|
|
allowed_hosts = {
|
|
|
|
allowed_host2 = "localhost";
|
|
|
|
};
|
|
|
|
};
|
2020-11-28 20:31:55 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
user = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = defaultUser;
|
2024-04-13 14:54:15 +02:00
|
|
|
description = "User under which Etebase server runs.";
|
2020-11-28 20:31:55 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
|
|
|
environment.systemPackages = with pkgs; [
|
|
|
|
(runCommand "etebase-server" {
|
2022-09-24 23:28:38 +02:00
|
|
|
nativeBuildInputs = [ makeWrapper ];
|
2020-11-28 20:31:55 +01:00
|
|
|
} ''
|
2024-03-01 22:55:27 +01:00
|
|
|
makeWrapper ${cfg.package}/bin/etebase-server \
|
2020-11-28 20:31:55 +01:00
|
|
|
$out/bin/etebase-server \
|
2022-03-14 19:06:00 +01:00
|
|
|
--chdir ${escapeShellArg cfg.dataDir} \
|
2020-11-28 20:31:55 +01:00
|
|
|
--prefix ETEBASE_EASY_CONFIG_PATH : "${configIni}"
|
|
|
|
'')
|
|
|
|
];
|
|
|
|
|
|
|
|
systemd.tmpfiles.rules = [
|
|
|
|
"d '${cfg.dataDir}' - ${cfg.user} ${config.users.users.${cfg.user}.group} - -"
|
2024-03-19 09:59:57 +01:00
|
|
|
] ++ lib.optionals (cfg.unixSocket != null) [
|
2024-03-15 16:52:21 +01:00
|
|
|
"d '${builtins.dirOf cfg.unixSocket}' - ${cfg.user} ${config.users.users.${cfg.user}.group} - -"
|
2020-11-28 20:31:55 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
systemd.services.etebase-server = {
|
|
|
|
description = "An Etebase (EteSync 2.0) server";
|
|
|
|
after = [ "network.target" "systemd-tmpfiles-setup.service" ];
|
2024-03-01 22:55:27 +01:00
|
|
|
path = [ cfg.package ];
|
2020-11-28 20:31:55 +01:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
serviceConfig = {
|
|
|
|
User = cfg.user;
|
|
|
|
Restart = "always";
|
|
|
|
WorkingDirectory = cfg.dataDir;
|
|
|
|
};
|
|
|
|
environment = {
|
2021-03-28 23:50:18 +02:00
|
|
|
ETEBASE_EASY_CONFIG_PATH = configIni;
|
2024-03-01 22:55:27 +01:00
|
|
|
PYTHONPATH = cfg.package.pythonPath;
|
2020-11-28 20:31:55 +01:00
|
|
|
};
|
|
|
|
preStart = ''
|
|
|
|
# Auto-migrate on first run or if the package has changed
|
|
|
|
versionFile="${cfg.dataDir}/src-version"
|
2024-01-23 23:08:51 +01:00
|
|
|
if [[ $(cat "$versionFile" 2>/dev/null) != ${cfg.package} ]]; then
|
2022-11-08 07:54:14 +01:00
|
|
|
etebase-server migrate --no-input
|
|
|
|
etebase-server collectstatic --no-input --clear
|
2024-01-23 23:08:51 +01:00
|
|
|
echo ${cfg.package} > "$versionFile"
|
2020-11-28 20:31:55 +01:00
|
|
|
fi
|
|
|
|
'';
|
|
|
|
script =
|
|
|
|
let
|
2024-03-01 22:55:27 +01:00
|
|
|
python = cfg.package.python;
|
2020-11-28 20:31:55 +01:00
|
|
|
networking = if cfg.unixSocket != null
|
2024-03-01 22:55:27 +01:00
|
|
|
then "--uds ${cfg.unixSocket}"
|
|
|
|
else "--host 0.0.0.0 --port ${toString cfg.port}";
|
2020-11-28 20:31:55 +01:00
|
|
|
in ''
|
2024-03-01 22:55:27 +01:00
|
|
|
${python.pkgs.uvicorn}/bin/uvicorn ${networking} \
|
|
|
|
--app-dir ${cfg.package}/${cfg.package.python.sitePackages} \
|
2020-11-28 20:31:55 +01:00
|
|
|
etebase_server.asgi:application
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
users = optionalAttrs (cfg.user == defaultUser) {
|
|
|
|
users.${defaultUser} = {
|
2021-04-15 20:45:08 +02:00
|
|
|
isSystemUser = true;
|
2020-11-28 20:31:55 +01:00
|
|
|
group = defaultUser;
|
|
|
|
home = cfg.dataDir;
|
|
|
|
};
|
|
|
|
|
|
|
|
groups.${defaultUser} = {};
|
|
|
|
};
|
|
|
|
|
|
|
|
networking.firewall = mkIf cfg.openFirewall {
|
|
|
|
allowedTCPPorts = [ cfg.port ];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|