1 { config, lib, pkgs, ... }:
4 cfg = config.services.trilium-server;
5 configIni = pkgs.writeText "trilium-config.ini" ''
7 # Instance name can be used to distinguish between different instances
8 instanceName=${cfg.instanceName}
10 # Disable automatically generating desktop icon
12 noBackup=${lib.boolToString cfg.noBackup}
13 noAuthentication=${lib.boolToString cfg.noAuthentication}
16 # host setting is relevant only for web deployments - set the host on which the server will listen
18 # port setting is relevant only for web deployments, desktop builds run on random free port
19 port=${toString cfg.port}
20 # true for TLS/SSL/HTTPS (secure), false for HTTP (unsecure).
26 options.services.trilium-server = with lib; {
27 enable = mkEnableOption "trilium-server";
31 default = "/var/lib/trilium";
33 The directory storing the notes database and the configuration.
37 instanceName = mkOption {
41 Instance name used to distinguish between different instances
49 Disable periodic database backups.
53 noAuthentication = mkOption {
57 If set to true, no password is required to access the web frontend.
63 default = "127.0.0.1";
65 The host address to bind to (defaults to localhost).
73 The port number to bind to.
80 Configuration for nginx reverse proxy.
83 type = types.submodule {
89 Configure the nginx reverse proxy settings.
96 The hostname use to setup the virtualhost configuration
104 config = lib.mkIf cfg.enable (lib.mkMerge [
106 meta.maintainers = with lib.maintainers; [ fliegendewurst ];
108 users.groups.trilium = {};
109 users.users.trilium = {
110 description = "Trilium User";
116 systemd.services.trilium-server = {
117 wantedBy = [ "multi-user.target" ];
118 environment.TRILIUM_DATA_DIR = cfg.dataDir;
120 ExecStart = "${pkgs.trilium-server}/bin/trilium-server";
127 systemd.tmpfiles.rules = [
128 "d ${cfg.dataDir} 0750 trilium trilium - -"
129 "L+ ${cfg.dataDir}/config.ini - - - - ${configIni}"
134 (lib.mkIf cfg.nginx.enable {
137 virtualHosts."${cfg.nginx.hostName}" = {
139 proxyPass = "http://${cfg.host}:${toString cfg.port}/";
141 proxy_http_version 1.1;
142 proxy_set_header Upgrade $http_upgrade;
143 proxy_set_header Connection 'upgrade';
144 proxy_set_header Host $host;
145 proxy_cache_bypass $http_upgrade;
149 client_max_body_size 0;