about summary refs log tree commit diff
diff options
context:
space:
mode:
authortalyz <kim.lindberger@gmail.com>2021-12-06 14:21:39 +0100
committertalyz <kim.lindberger@gmail.com>2021-12-06 14:21:39 +0100
commit125bb7dac1fcf9829ff93a33ed19665a72872ecd (patch)
tree80376c8ae4ba6cac073a249abc7f52806c3fc014
parent4fb343c87e29bf1f33b49a1bcc210a57d9d42f1d (diff)
discourse: Don't patch the public path
Instead of patching the path to /public in Discourse's sources, make
the nginx configuration refer to the symlink in the discourse
package which points to the real path.

When there is a mismatch between the path nginx serves and the path
Discourse thinks it serves, we can run into issues like files not
being served - at least when sendfile requests from the ruby app are
processed by nginx. The issue I ran into most recently is that backup
downloads don't work.

Since Discourse refers to the public directory relative to the Rails
root in many places, it's much easier to just sync this path to the
nginx configuration than trying to patch all occurrences in the
sources. This should hopefully mean less potential for breakage in
future Discourse releases, too.
-rw-r--r--nixos/modules/services/web-apps/discourse.nix8
-rw-r--r--pkgs/servers/web-apps/discourse/default.nix5
-rw-r--r--pkgs/servers/web-apps/discourse/public_dir_path.patch13
3 files changed, 4 insertions, 22 deletions
diff --git a/nixos/modules/services/web-apps/discourse.nix b/nixos/modules/services/web-apps/discourse.nix
index 1c7ffd59a596e..18b61200aa1b0 100644
--- a/nixos/modules/services/web-apps/discourse.nix
+++ b/nixos/modules/services/web-apps/discourse.nix
@@ -841,7 +841,7 @@ in
         inherit (cfg) sslCertificate sslCertificateKey enableACME;
         forceSSL = lib.mkDefault tlsEnabled;
 
-        root = "/run/discourse/public";
+        root = "${cfg.package}/share/discourse/public";
 
         locations =
           let
@@ -893,7 +893,7 @@ in
               "~ ^/uploads/" = proxy {
                 extraConfig = cache_1y + ''
                   proxy_set_header X-Sendfile-Type X-Accel-Redirect;
-                  proxy_set_header X-Accel-Mapping /run/discourse/public/=/downloads/;
+                  proxy_set_header X-Accel-Mapping ${cfg.package}/share/discourse/public/=/downloads/;
 
                   # custom CSS
                   location ~ /stylesheet-cache/ {
@@ -915,7 +915,7 @@ in
               "~ ^/admin/backups/" = proxy {
                 extraConfig = ''
                   proxy_set_header X-Sendfile-Type X-Accel-Redirect;
-                  proxy_set_header X-Accel-Mapping /run/discourse/public/=/downloads/;
+                  proxy_set_header X-Accel-Mapping ${cfg.package}/share/discourse/public/=/downloads/;
                 '';
               };
               "~ ^/(svg-sprite/|letter_avatar/|letter_avatar_proxy/|user_avatar|highlight-js|stylesheets|theme-javascripts|favicon/proxied|service-worker)" = proxy {
@@ -942,7 +942,7 @@ in
               };
               "/downloads/".extraConfig = ''
                 internal;
-                alias /run/discourse/public/;
+                alias ${cfg.package}/share/discourse/public/;
               '';
             };
       };
diff --git a/pkgs/servers/web-apps/discourse/default.nix b/pkgs/servers/web-apps/discourse/default.nix
index 62e9be80bcd9a..6134b307c24da 100644
--- a/pkgs/servers/web-apps/discourse/default.nix
+++ b/pkgs/servers/web-apps/discourse/default.nix
@@ -264,11 +264,6 @@ let
 
       # Make sure the notification email setting applies
       ./notification_email.patch
-
-      # Change the path to the public directory reported by Discourse
-      # to its real path instead of the symlink in the store, since
-      # the store path won't be matched by any nginx rules
-      ./public_dir_path.patch
     ];
 
     postPatch = ''
diff --git a/pkgs/servers/web-apps/discourse/public_dir_path.patch b/pkgs/servers/web-apps/discourse/public_dir_path.patch
deleted file mode 100644
index 0c6579736e22f..0000000000000
--- a/pkgs/servers/web-apps/discourse/public_dir_path.patch
+++ /dev/null
@@ -1,13 +0,0 @@
-diff --git a/lib/file_store/local_store.rb b/lib/file_store/local_store.rb
-index 25649532c0..614e062dc1 100644
---- a/lib/file_store/local_store.rb
-+++ b/lib/file_store/local_store.rb
-@@ -88,7 +88,7 @@ module FileStore
-     end
- 
-     def public_dir
--      File.join(Rails.root, "public")
-+      "/run/discourse/public"
-     end
- 
-     def tombstone_dir