]> git.immae.eu Git - perso/Immae/Config/Nix.git/commitdiff
Use sockets for etherpad-lite
authorIsmaël Bouya <ismael.bouya@normalesup.org>
Fri, 10 May 2019 23:14:51 +0000 (01:14 +0200)
committerIsmaël Bouya <ismael.bouya@normalesup.org>
Fri, 10 May 2019 23:14:51 +0000 (01:14 +0200)
modules/webapps/etherpad-lite.nix
nixops/modules/websites/tools/ether.nix

index 3e951c5118bb10022b7c2096579b958e721ed998..7f0e2ed4afbc41c303b887e367af78ccb845e689 100644 (file)
@@ -26,6 +26,13 @@ in
         The directory where Etherpad lite stores its data.
       '';
     };
+    socketsDir = lib.mkOption {
+      type = lib.types.path;
+      default = "/run/${name}";
+      description = ''
+        The directory where Etherpad lite stores its sockets.
+      '';
+    };
     configFile = lib.mkOption {
       type = lib.types.path;
       description = ''
@@ -77,6 +84,26 @@ in
       '';
       readOnly = true;
     };
+    systemdRuntimeDirectory = lib.mkOption {
+      type = lib.types.str;
+      # Use ReadWritePaths= instead if socketsDir is outside of /run
+      default = assert lib.strings.hasPrefix "/run/" cfg.socketsDir;
+        lib.strings.removePrefix "/run/" cfg.socketsDir;
+      description = ''
+      Adjusted Etherpad lite sockets directory for systemd
+      '';
+      readOnly = true;
+    };
+    sockets = lib.mkOption {
+      type = lib.types.attrsOf lib.types.path;
+      default = {
+        node  = "${cfg.socketsDir}/etherpad-lite.sock";
+      };
+      readOnly = true;
+      description = ''
+        Etherpad lite sockets
+        '';
+    };
   };
 
   config = lib.mkIf cfg.enable {
@@ -98,6 +125,12 @@ in
           --settings ${cfg.configFile}
       '';
 
+      postStart = ''
+        while [ ! -S ${cfg.sockets.node} ]; do
+          sleep 0.5
+        done
+        chmod a+w ${cfg.sockets.node}
+        '';
       serviceConfig = {
         DynamicUser = true;
         User = cfg.user;
@@ -112,6 +145,7 @@ in
         Restart = "always";
         Type = "simple";
         TimeoutSec = 60;
+        RuntimeDirectory = cfg.systemdRuntimeDirectory;
         StateDirectory= cfg.systemdStateDirectory;
         ExecStartPre = [
           "+${pkgs.coreutils}/bin/install -d -m 0755 -o ${cfg.user} -g ${cfg.group} ${cfg.dataDir}/ep_initialized"
index 3efa363a969a61610903d98953019fc93cbd747d..9c78b0cf52283a6ffb9e9d3557a90b2d640b3a1a 100644 (file)
@@ -5,6 +5,7 @@ let
   # Make sure we’re not rebuilding whole libreoffice just because of a
   # dependency
   libreoffice = (import <nixpkgs> { overlays = []; }).libreoffice-fresh;
+  ecfg = config.services.etherpad-lite;
 in {
   options.services.myWebsites.tools.etherpad-lite = {
     enable = lib.mkEnableOption "enable etherpad's website";
@@ -30,8 +31,8 @@ in {
             "title": "Etherpad",
             "favicon": "favicon.ico",
 
-            "ip": "127.0.0.1",
-            "port" : ${env.listenPort},
+            "ip": "",
+            "port" : "${ecfg.sockets.node}",
             "showSettingsInAdminPage" : false,
             "dbType" : "postgres",
             "dbSettings" : {
@@ -154,14 +155,14 @@ in {
 
         RewriteCond %{REQUEST_URI}  ^/socket.io            [NC]
         RewriteCond %{QUERY_STRING} transport=websocket    [NC]
-        RewriteRule /(.*)           ws://localhost:${env.listenPort}/$1 [P,L]
+        RewriteRule /(.*)           unix://${ecfg.sockets.node}|ws://ether.immae.eu/$1 [P,NE,QSA,L]
 
         <IfModule mod_proxy.c>
           ProxyVia On
           ProxyRequests Off
           ProxyPreserveHost On
-          ProxyPass         / http://localhost:${env.listenPort}/
-          ProxyPassReverse  / http://localhost:${env.listenPort}/
+          ProxyPass         / unix://${ecfg.sockets.node}|http://ether.immae.eu/
+          ProxyPassReverse  / unix://${ecfg.sockets.node}|http://ether.immae.eu/
           <Proxy *>
             Options FollowSymLinks MultiViews
             AllowOverride None