1 { config, lib, pkgs, ... }:
3 cfg = config.services.infinoted;
5 options.services.infinoted = {
6 enable = lib.mkEnableOption "infinoted";
8 package = lib.mkPackageOption pkgs "libinfinity" { };
10 keyFile = lib.mkOption {
11 type = lib.types.nullOr lib.types.path;
14 Private key to use for TLS
18 certificateFile = lib.mkOption {
19 type = lib.types.nullOr lib.types.path;
22 Server certificate to use for TLS
26 certificateChain = lib.mkOption {
27 type = lib.types.nullOr lib.types.path;
30 Chain of CA-certificates to which our `certificateFile` is relative.
35 securityPolicy = lib.mkOption {
36 type = lib.types.enum ["no-tls" "allow-tls" "require-tls"];
37 default = "require-tls";
39 How strictly to enforce clients connection with TLS.
44 type = lib.types.port;
51 rootDirectory = lib.mkOption {
52 type = lib.types.path;
53 default = "/var/lib/infinoted/documents/";
55 Root of the directory structure to serve
59 plugins = lib.mkOption {
60 type = lib.types.listOf lib.types.str;
61 default = [ "note-text" "note-chat" "logging" "autosave" ];
67 passwordFile = lib.mkOption {
68 type = lib.types.nullOr lib.types.path;
71 File to read server-wide password from
75 extraConfig = lib.mkOption {
76 type = lib.types.lines;
82 Additional configuration to append to infinoted.conf
88 default = "infinoted";
90 What to call the dedicated user under which infinoted is run
94 group = lib.mkOption {
96 default = "infinoted";
98 What to call the primary group of the dedicated user under which infinoted is run
103 config = lib.mkIf (cfg.enable) {
104 users.users = lib.optionalAttrs (cfg.user == "infinoted")
106 description = "Infinoted user";
111 users.groups = lib.optionalAttrs (cfg.group == "infinoted")
115 systemd.services.infinoted =
116 { description = "Gobby Dedicated Server";
118 wantedBy = [ "multi-user.target" ];
119 after = [ "network.target" ];
124 ExecStart = "${cfg.package.infinoted} --config-file=/var/lib/infinoted/infinoted.conf";
127 PermissionsStartOnly = true;
130 mkdir -p /var/lib/infinoted
131 install -o ${cfg.user} -g ${cfg.group} -m 0600 /dev/null /var/lib/infinoted/infinoted.conf
132 cat >>/var/lib/infinoted/infinoted.conf <<EOF
134 ${lib.optionalString (cfg.keyFile != null) "key-file=${cfg.keyFile}"}
135 ${lib.optionalString (cfg.certificateFile != null) "certificate-file=${cfg.certificateFile}"}
136 ${lib.optionalString (cfg.certificateChain != null) "certificate-chain=${cfg.certificateChain}"}
137 port=${toString cfg.port}
138 security-policy=${cfg.securityPolicy}
139 root-directory=${cfg.rootDirectory}
140 plugins=${lib.concatStringsSep ";" cfg.plugins}
141 ${lib.optionalString (cfg.passwordFile != null) "password=$(head -n 1 ${cfg.passwordFile})"}
146 install -o ${cfg.user} -g ${cfg.group} -m 0750 -d ${cfg.rootDirectory}