aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIsmaël Bouya <ismael.bouya@normalesup.org>2019-05-11 01:14:51 +0200
committerIsmaël Bouya <ismael.bouya@normalesup.org>2019-05-11 01:14:51 +0200
commit5af8d43b9ee0543ff212e5c51fb0e750a2b83955 (patch)
tree07d979d2a30f23aa8c4bccb40343b728885f7b76
parent742c28ad92467859fb7f54c4b8b4d09d9864a75e (diff)
downloadNix-5af8d43b9ee0543ff212e5c51fb0e750a2b83955.tar.gz
Nix-5af8d43b9ee0543ff212e5c51fb0e750a2b83955.tar.zst
Nix-5af8d43b9ee0543ff212e5c51fb0e750a2b83955.zip
Use sockets for etherpad-lite
-rw-r--r--modules/webapps/etherpad-lite.nix34
-rw-r--r--nixops/modules/websites/tools/ether.nix11
2 files changed, 40 insertions, 5 deletions
diff --git a/modules/webapps/etherpad-lite.nix b/modules/webapps/etherpad-lite.nix
index 3e951c5..7f0e2ed 100644
--- a/modules/webapps/etherpad-lite.nix
+++ b/modules/webapps/etherpad-lite.nix
@@ -26,6 +26,13 @@ in
26 The directory where Etherpad lite stores its data. 26 The directory where Etherpad lite stores its data.
27 ''; 27 '';
28 }; 28 };
29 socketsDir = lib.mkOption {
30 type = lib.types.path;
31 default = "/run/${name}";
32 description = ''
33 The directory where Etherpad lite stores its sockets.
34 '';
35 };
29 configFile = lib.mkOption { 36 configFile = lib.mkOption {
30 type = lib.types.path; 37 type = lib.types.path;
31 description = '' 38 description = ''
@@ -77,6 +84,26 @@ in
77 ''; 84 '';
78 readOnly = true; 85 readOnly = true;
79 }; 86 };
87 systemdRuntimeDirectory = lib.mkOption {
88 type = lib.types.str;
89 # Use ReadWritePaths= instead if socketsDir is outside of /run
90 default = assert lib.strings.hasPrefix "/run/" cfg.socketsDir;
91 lib.strings.removePrefix "/run/" cfg.socketsDir;
92 description = ''
93 Adjusted Etherpad lite sockets directory for systemd
94 '';
95 readOnly = true;
96 };
97 sockets = lib.mkOption {
98 type = lib.types.attrsOf lib.types.path;
99 default = {
100 node = "${cfg.socketsDir}/etherpad-lite.sock";
101 };
102 readOnly = true;
103 description = ''
104 Etherpad lite sockets
105 '';
106 };
80 }; 107 };
81 108
82 config = lib.mkIf cfg.enable { 109 config = lib.mkIf cfg.enable {
@@ -98,6 +125,12 @@ in
98 --settings ${cfg.configFile} 125 --settings ${cfg.configFile}
99 ''; 126 '';
100 127
128 postStart = ''
129 while [ ! -S ${cfg.sockets.node} ]; do
130 sleep 0.5
131 done
132 chmod a+w ${cfg.sockets.node}
133 '';
101 serviceConfig = { 134 serviceConfig = {
102 DynamicUser = true; 135 DynamicUser = true;
103 User = cfg.user; 136 User = cfg.user;
@@ -112,6 +145,7 @@ in
112 Restart = "always"; 145 Restart = "always";
113 Type = "simple"; 146 Type = "simple";
114 TimeoutSec = 60; 147 TimeoutSec = 60;
148 RuntimeDirectory = cfg.systemdRuntimeDirectory;
115 StateDirectory= cfg.systemdStateDirectory; 149 StateDirectory= cfg.systemdStateDirectory;
116 ExecStartPre = [ 150 ExecStartPre = [
117 "+${pkgs.coreutils}/bin/install -d -m 0755 -o ${cfg.user} -g ${cfg.group} ${cfg.dataDir}/ep_initialized" 151 "+${pkgs.coreutils}/bin/install -d -m 0755 -o ${cfg.user} -g ${cfg.group} ${cfg.dataDir}/ep_initialized"
diff --git a/nixops/modules/websites/tools/ether.nix b/nixops/modules/websites/tools/ether.nix
index 3efa363..9c78b0c 100644
--- a/nixops/modules/websites/tools/ether.nix
+++ b/nixops/modules/websites/tools/ether.nix
@@ -5,6 +5,7 @@ let
5 # Make sure we’re not rebuilding whole libreoffice just because of a 5 # Make sure we’re not rebuilding whole libreoffice just because of a
6 # dependency 6 # dependency
7 libreoffice = (import <nixpkgs> { overlays = []; }).libreoffice-fresh; 7 libreoffice = (import <nixpkgs> { overlays = []; }).libreoffice-fresh;
8 ecfg = config.services.etherpad-lite;
8in { 9in {
9 options.services.myWebsites.tools.etherpad-lite = { 10 options.services.myWebsites.tools.etherpad-lite = {
10 enable = lib.mkEnableOption "enable etherpad's website"; 11 enable = lib.mkEnableOption "enable etherpad's website";
@@ -30,8 +31,8 @@ in {
30 "title": "Etherpad", 31 "title": "Etherpad",
31 "favicon": "favicon.ico", 32 "favicon": "favicon.ico",
32 33
33 "ip": "127.0.0.1", 34 "ip": "",
34 "port" : ${env.listenPort}, 35 "port" : "${ecfg.sockets.node}",
35 "showSettingsInAdminPage" : false, 36 "showSettingsInAdminPage" : false,
36 "dbType" : "postgres", 37 "dbType" : "postgres",
37 "dbSettings" : { 38 "dbSettings" : {
@@ -154,14 +155,14 @@ in {
154 155
155 RewriteCond %{REQUEST_URI} ^/socket.io [NC] 156 RewriteCond %{REQUEST_URI} ^/socket.io [NC]
156 RewriteCond %{QUERY_STRING} transport=websocket [NC] 157 RewriteCond %{QUERY_STRING} transport=websocket [NC]
157 RewriteRule /(.*) ws://localhost:${env.listenPort}/$1 [P,L] 158 RewriteRule /(.*) unix://${ecfg.sockets.node}|ws://ether.immae.eu/$1 [P,NE,QSA,L]
158 159
159 <IfModule mod_proxy.c> 160 <IfModule mod_proxy.c>
160 ProxyVia On 161 ProxyVia On
161 ProxyRequests Off 162 ProxyRequests Off
162 ProxyPreserveHost On 163 ProxyPreserveHost On
163 ProxyPass / http://localhost:${env.listenPort}/ 164 ProxyPass / unix://${ecfg.sockets.node}|http://ether.immae.eu/
164 ProxyPassReverse / http://localhost:${env.listenPort}/ 165 ProxyPassReverse / unix://${ecfg.sockets.node}|http://ether.immae.eu/
165 <Proxy *> 166 <Proxy *>
166 Options FollowSymLinks MultiViews 167 Options FollowSymLinks MultiViews
167 AllowOverride None 168 AllowOverride None