1 { config, pkgs, lib, ... }:
3 cfg = config.services.etebase-server;
5 iniFmt = pkgs.formats.ini {};
7 configIni = iniFmt.generate "etebase-server.ini" cfg.settings;
9 defaultUser = "etebase-server";
13 (lib.mkRemovedOptionModule
14 [ "services" "etebase-server" "customIni" ]
15 "Set the option `services.etebase-server.settings' instead.")
16 (lib.mkRemovedOptionModule
17 [ "services" "etebase-server" "database" ]
18 "Set the option `services.etebase-server.settings.database' instead.")
19 (lib.mkRenamedOptionModule
20 [ "services" "etebase-server" "secretFile" ]
21 [ "services" "etebase-server" "settings" "secret_file" ])
22 (lib.mkRenamedOptionModule
23 [ "services" "etebase-server" "host" ]
24 [ "services" "etebase-server" "settings" "allowed_hosts" "allowed_host1" ])
28 services.etebase-server = {
29 enable = lib.mkOption {
30 type = lib.types.bool;
34 Whether to enable the Etebase server.
36 Once enabled you need to create an admin user by invoking the
37 shell command `etebase-server createsuperuser` with
38 the user specified by the `user` option or a superuser.
39 Then you can login and create accounts on your-etebase-server.com/admin
43 package = lib.mkOption {
44 type = lib.types.package;
45 default = pkgs.etebase-server;
46 defaultText = lib.literalExpression "pkgs.python3.pkgs.etebase-server";
47 description = "etebase-server package to use.";
50 dataDir = lib.mkOption {
52 default = "/var/lib/etebase-server";
53 description = "Directory to store the Etebase server data.";
57 type = with lib.types; nullOr port;
59 description = "Port to listen on.";
62 openFirewall = lib.mkOption {
63 type = lib.types.bool;
66 Whether to open ports in the firewall for the server.
70 unixSocket = lib.mkOption {
71 type = with lib.types; nullOr str;
73 description = "The path to the socket to bind to.";
74 example = "/run/etebase-server/etebase-server.sock";
77 settings = lib.mkOption {
78 type = lib.types.submodule {
79 freeformType = iniFmt.type;
83 debug = lib.mkOption {
84 type = lib.types.bool;
87 Whether to set django's DEBUG flag.
90 secret_file = lib.mkOption {
91 type = with lib.types; nullOr str;
94 The path to a file containing the secret
95 used as django's SECRET_KEY.
98 static_root = lib.mkOption {
100 default = "${cfg.dataDir}/static";
101 defaultText = lib.literalExpression ''"''${config.services.etebase-server.dataDir}/static"'';
102 description = "The directory for static files.";
104 media_root = lib.mkOption {
105 type = lib.types.str;
106 default = "${cfg.dataDir}/media";
107 defaultText = lib.literalExpression ''"''${config.services.etebase-server.dataDir}/media"'';
108 description = "The media directory.";
112 allowed_host1 = lib.mkOption {
113 type = lib.types.str;
115 example = "localhost";
117 The main host that is allowed access.
122 engine = lib.mkOption {
123 type = lib.types.enum [ "django.db.backends.sqlite3" "django.db.backends.postgresql" ];
124 default = "django.db.backends.sqlite3";
125 description = "The database engine to use.";
127 name = lib.mkOption {
128 type = lib.types.str;
129 default = "${cfg.dataDir}/db.sqlite3";
130 defaultText = lib.literalExpression ''"''${config.services.etebase-server.dataDir}/db.sqlite3"'';
131 description = "The database name.";
138 Configuration for `etebase-server`. Refer to
139 <https://github.com/etesync/server/blob/master/etebase-server.ini.example>
140 and <https://github.com/etesync/server/wiki>
141 for details on supported values.
146 media_root = "/path/to/media";
149 allowed_host2 = "localhost";
154 user = lib.mkOption {
155 type = lib.types.str;
156 default = defaultUser;
157 description = "User under which Etebase server runs.";
162 config = lib.mkIf cfg.enable {
164 environment.systemPackages = with pkgs; [
165 (runCommand "etebase-server" {
166 nativeBuildInputs = [ makeWrapper ];
168 makeWrapper ${cfg.package}/bin/etebase-server \
169 $out/bin/etebase-server \
170 --chdir ${lib.escapeShellArg cfg.dataDir} \
171 --prefix ETEBASE_EASY_CONFIG_PATH : "${configIni}"
175 systemd.tmpfiles.rules = [
176 "d '${cfg.dataDir}' - ${cfg.user} ${config.users.users.${cfg.user}.group} - -"
177 ] ++ lib.optionals (cfg.unixSocket != null) [
178 "d '${builtins.dirOf cfg.unixSocket}' - ${cfg.user} ${config.users.users.${cfg.user}.group} - -"
181 systemd.services.etebase-server = {
182 description = "An Etebase (EteSync 2.0) server";
183 after = [ "network.target" "systemd-tmpfiles-setup.service" ];
184 path = [ cfg.package ];
185 wantedBy = [ "multi-user.target" ];
189 WorkingDirectory = cfg.dataDir;
192 ETEBASE_EASY_CONFIG_PATH = configIni;
193 PYTHONPATH = cfg.package.pythonPath;
196 # Auto-migrate on first run or if the package has changed
197 versionFile="${cfg.dataDir}/src-version"
198 if [[ $(cat "$versionFile" 2>/dev/null) != ${cfg.package} ]]; then
199 etebase-server migrate --no-input
200 etebase-server collectstatic --no-input --clear
201 echo ${cfg.package} > "$versionFile"
206 python = cfg.package.python;
207 networking = if cfg.unixSocket != null
208 then "--uds ${cfg.unixSocket}"
209 else "--host 0.0.0.0 --port ${toString cfg.port}";
211 ${python.pkgs.uvicorn}/bin/uvicorn ${networking} \
212 --app-dir ${cfg.package}/${cfg.package.python.sitePackages} \
213 etebase_server.asgi:application
217 users = lib.optionalAttrs (cfg.user == defaultUser) {
218 users.${defaultUser} = {
224 groups.${defaultUser} = {};
227 networking.firewall = lib.mkIf cfg.openFirewall {
228 allowedTCPPorts = [ cfg.port ];