summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKim Lindberger <kim.lindberger@gmail.com>2021-07-15 14:50:11 +0200
committerGitHub <noreply@github.com>2021-07-15 14:50:11 +0200
commit5fd730e210a295b9cb7cf6eed5ce3d0354e6c544 (patch)
tree16f2b7c4a9ced595c4586c9d9963de50995646f4
parentMerge pull request #130255 from NixOS/backport-130253-to-release-21.05 (diff)
parentdiscourse: Add a proper plugin builder + a few initial packages (diff)
downloadnixpkgs-5fd730e210a295b9cb7cf6eed5ce3d0354e6c544.tar.gz
Merge pull request #128823 from NixOS/backport-127931-to-release-21.05
[Backport release-21.05] discourse: Fix plugin support
-rw-r--r--nixos/modules/services/web-apps/discourse.nix5
-rw-r--r--pkgs/servers/web-apps/discourse/default.nix64
-rw-r--r--pkgs/servers/web-apps/discourse/plugin_gem_api_version.patch13
-rw-r--r--pkgs/servers/web-apps/discourse/plugins/all-plugins.nix12
-rw-r--r--pkgs/servers/web-apps/discourse/plugins/discourse-canned-replies/default.nix11
-rw-r--r--pkgs/servers/web-apps/discourse/plugins/discourse-github/Gemfile3
-rw-r--r--pkgs/servers/web-apps/discourse/plugins/discourse-github/Gemfile.lock37
-rw-r--r--pkgs/servers/web-apps/discourse/plugins/discourse-github/default.nix12
-rw-r--r--pkgs/servers/web-apps/discourse/plugins/discourse-github/gemset.nix126
-rw-r--r--pkgs/servers/web-apps/discourse/plugins/discourse-math/default.nix11
-rw-r--r--pkgs/servers/web-apps/discourse/plugins/discourse-solved/default.nix11
-rw-r--r--pkgs/servers/web-apps/discourse/plugins/discourse-spoiler-alert/default.nix11
-rw-r--r--pkgs/servers/web-apps/discourse/plugins/discourse-yearly-review/default.nix11
-rw-r--r--pkgs/servers/web-apps/discourse/use_mv_instead_of_rename.patch22
14 files changed, 339 insertions, 10 deletions
diff --git a/nixos/modules/services/web-apps/discourse.nix b/nixos/modules/services/web-apps/discourse.nix
index 49958fc6190c..00a269ba871d 100644
--- a/nixos/modules/services/web-apps/discourse.nix
+++ b/nixos/modules/services/web-apps/discourse.nix
@@ -30,6 +30,9 @@ in
package = lib.mkOption {
type = lib.types.package;
default = pkgs.discourse;
+ apply = p: p.override {
+ plugins = lib.unique (p.enabledPlugins ++ cfg.plugins);
+ };
defaultText = "pkgs.discourse";
description = ''
The discourse package to use.
@@ -731,8 +734,6 @@ in
cp -r ${cfg.package}/share/discourse/config.dist/* /run/discourse/config/
cp -r ${cfg.package}/share/discourse/public.dist/* /run/discourse/public/
- cp -r ${cfg.package}/share/discourse/plugins.dist/* /run/discourse/plugins/
- ${lib.concatMapStringsSep "\n" (p: "ln -sf ${p} /run/discourse/plugins/") cfg.plugins}
ln -sf /var/lib/discourse/uploads /run/discourse/public/uploads
ln -sf /var/lib/discourse/backups /run/discourse/public/backups
diff --git a/pkgs/servers/web-apps/discourse/default.nix b/pkgs/servers/web-apps/discourse/default.nix
index 5e7c4d5368a4..5a3301040d33 100644
--- a/pkgs/servers/web-apps/discourse/default.nix
+++ b/pkgs/servers/web-apps/discourse/default.nix
@@ -1,8 +1,11 @@
{ stdenv, makeWrapper, runCommandNoCC, lib, nixosTests, writeShellScript
-, fetchFromGitHub, bundlerEnv, ruby, replace, gzip, gnutar, git, cacert
-, util-linux, gawk, imagemagick, optipng, pngquant, libjpeg, jpegoptim
-, gifsicle, libpsl, redis, postgresql, which, brotli, procps, rsync
-, nodePackages, v8
+, fetchFromGitHub, bundlerEnv, callPackage
+
+, ruby, replace, gzip, gnutar, git, cacert, util-linux, gawk
+, imagemagick, optipng, pngquant, libjpeg, jpegoptim, gifsicle, libpsl
+, redis, postgresql, which, brotli, procps, rsync, nodePackages, v8
+
+, plugins ? []
}:
let
@@ -46,6 +49,35 @@ let
UNICORN_LISTENER = "/run/discourse/sockets/unicorn.sock";
};
+ mkDiscoursePlugin =
+ { name ? null
+ , pname ? null
+ , version ? null
+ , meta ? null
+ , bundlerEnvArgs ? {}
+ , src
+ , ...
+ }@args:
+ let
+ rubyEnv = bundlerEnv (bundlerEnvArgs // {
+ inherit name pname version ruby;
+ });
+ in
+ stdenv.mkDerivation (builtins.removeAttrs args [ "bundlerEnvArgs" ] // {
+ inherit name pname version src meta;
+ pluginName = if name != null then name else "${pname}-${version}";
+ phases = [ "unpackPhase" "installPhase" ];
+ installPhase = ''
+ runHook preInstall
+ mkdir -p $out
+ cp -r * $out/
+ '' + lib.optionalString (bundlerEnvArgs != {}) ''
+ ln -sf ${rubyEnv}/lib/ruby/gems $out/gems
+ '' + ''
+ runHook postInstall
+ '';
+ });
+
rake = runCommandNoCC "discourse-rake" {
nativeBuildInputs = [ makeWrapper ];
} ''
@@ -121,6 +153,12 @@ let
nodePackages.uglify-js
];
+ patches = [
+ # Use the Ruby API version in the plugin gem path, to match the
+ # one constructed by bundlerEnv
+ ./plugin_gem_api_version.patch
+ ];
+
# We have to set up an environment that is close enough to
# production ready or the assets:precompile task refuses to
# run. This means that Redis and PostgreSQL has to be running and
@@ -148,6 +186,8 @@ let
mkdir $NIX_BUILD_TOP/tmp_home
export HOME=$NIX_BUILD_TOP/tmp_home
+ ${lib.concatMapStringsSep "\n" (p: "ln -sf ${p} plugins/${p.pluginName or ""}") plugins}
+
export RAILS_ENV=production
bundle exec rake db:migrate >/dev/null
@@ -195,6 +235,14 @@ let
# Log Unicorn messages to the journal and make request timeout
# configurable
./unicorn_logging_and_timeout.patch
+
+ # Use the Ruby API version in the plugin gem path, to match the
+ # one constructed by bundlerEnv
+ ./plugin_gem_api_version.patch
+
+ # Use mv instead of rename, since rename doesn't work across
+ # device boundaries
+ ./use_mv_instead_of_rename.patch
];
postPatch = ''
@@ -203,8 +251,6 @@ let
# warnings and means we don't have to link back to lib from the
# state directory.
find config -type f -execdir sed -Ei "s,(\.\./)+(lib|app)/,$out/share/discourse/\2/," {} \;
-
- ${replace}/bin/replace-literal -f -r -e 'File.rename(temp_destination, destination)' "FileUtils.mv(temp_destination, destination)" .
'';
buildPhase = ''
@@ -212,7 +258,6 @@ let
mv config config.dist
mv public public.dist
- mv plugins plugins.dist
runHook postBuild
'';
@@ -230,6 +275,7 @@ let
ln -sf /run/discourse/public $out/share/discourse/public
ln -sf /run/discourse/plugins $out/share/discourse/plugins
ln -sf ${assets} $out/share/discourse/public.dist/assets
+ ${lib.concatMapStringsSep "\n" (p: "ln -sf ${p} $out/share/discourse/plugins/${p.pluginName or ""}") plugins}
runHook postInstall
'';
@@ -243,7 +289,9 @@ let
};
passthru = {
- inherit rubyEnv runtimeEnv runtimeDeps rake;
+ inherit rubyEnv runtimeEnv runtimeDeps rake mkDiscoursePlugin;
+ enabledPlugins = plugins;
+ plugins = callPackage ./plugins/all-plugins.nix { inherit mkDiscoursePlugin; };
ruby = rubyEnv.wrappedRuby;
tests = nixosTests.discourse;
};
diff --git a/pkgs/servers/web-apps/discourse/plugin_gem_api_version.patch b/pkgs/servers/web-apps/discourse/plugin_gem_api_version.patch
new file mode 100644
index 000000000000..ca7aa850ec51
--- /dev/null
+++ b/pkgs/servers/web-apps/discourse/plugin_gem_api_version.patch
@@ -0,0 +1,13 @@
+diff --git a/lib/plugin_gem.rb b/lib/plugin_gem.rb
+index 855d1aca2c..8115623547 100644
+--- a/lib/plugin_gem.rb
++++ b/lib/plugin_gem.rb
+@@ -4,7 +4,7 @@ module PluginGem
+ def self.load(path, name, version, opts = nil)
+ opts ||= {}
+
+- gems_path = File.dirname(path) + "/gems/#{RUBY_VERSION}"
++ gems_path = File.dirname(path) + "/gems/#{Gem.ruby_api_version}"
+
+ spec_path = gems_path + "/specifications"
+
diff --git a/pkgs/servers/web-apps/discourse/plugins/all-plugins.nix b/pkgs/servers/web-apps/discourse/plugins/all-plugins.nix
new file mode 100644
index 000000000000..e6640cbbe975
--- /dev/null
+++ b/pkgs/servers/web-apps/discourse/plugins/all-plugins.nix
@@ -0,0 +1,12 @@
+{ mkDiscoursePlugin, newScope, fetchFromGitHub, ... }@args:
+let
+ callPackage = newScope args;
+in
+{
+ discourse-spoiler-alert = callPackage ./discourse-spoiler-alert {};
+ discourse-solved = callPackage ./discourse-solved {};
+ discourse-canned-replies = callPackage ./discourse-canned-replies {};
+ discourse-math = callPackage ./discourse-math {};
+ discourse-github = callPackage ./discourse-github {};
+ discourse-yearly-review = callPackage ./discourse-yearly-review {};
+}
diff --git a/pkgs/servers/web-apps/discourse/plugins/discourse-canned-replies/default.nix b/pkgs/servers/web-apps/discourse/plugins/discourse-canned-replies/default.nix
new file mode 100644
index 000000000000..05c153cd70b1
--- /dev/null
+++ b/pkgs/servers/web-apps/discourse/plugins/discourse-canned-replies/default.nix
@@ -0,0 +1,11 @@
+{ mkDiscoursePlugin, fetchFromGitHub }:
+
+mkDiscoursePlugin {
+ name = "discourse-canned-replies";
+ src = fetchFromGitHub {
+ owner = "discourse";
+ repo = "discourse-canned-replies";
+ rev = "7ee748f18a276aca42185e2079c1d4cadeecdaf8";
+ sha256 = "0j10kxfr6v2rdd58smg2i7iac46z74qnnjk8b91jd1svazhis1ph";
+ };
+}
diff --git a/pkgs/servers/web-apps/discourse/plugins/discourse-github/Gemfile b/pkgs/servers/web-apps/discourse/plugins/discourse-github/Gemfile
new file mode 100644
index 000000000000..f0205f4ff1df
--- /dev/null
+++ b/pkgs/servers/web-apps/discourse/plugins/discourse-github/Gemfile
@@ -0,0 +1,3 @@
+source 'https://rubygems.org'
+gem 'sawyer', '0.8.2'
+gem 'octokit', '4.21.0'
diff --git a/pkgs/servers/web-apps/discourse/plugins/discourse-github/Gemfile.lock b/pkgs/servers/web-apps/discourse/plugins/discourse-github/Gemfile.lock
new file mode 100644
index 000000000000..f28833a35c0f
--- /dev/null
+++ b/pkgs/servers/web-apps/discourse/plugins/discourse-github/Gemfile.lock
@@ -0,0 +1,37 @@
+GEM
+ remote: https://rubygems.org/
+ specs:
+ addressable (2.7.0)
+ public_suffix (>= 2.0.2, < 5.0)
+ faraday (1.4.2)
+ faraday-em_http (~> 1.0)
+ faraday-em_synchrony (~> 1.0)
+ faraday-excon (~> 1.1)
+ faraday-net_http (~> 1.0)
+ faraday-net_http_persistent (~> 1.1)
+ multipart-post (>= 1.2, < 3)
+ ruby2_keywords (>= 0.0.4)
+ faraday-em_http (1.0.0)
+ faraday-em_synchrony (1.0.0)
+ faraday-excon (1.1.0)
+ faraday-net_http (1.0.1)
+ faraday-net_http_persistent (1.1.0)
+ multipart-post (2.1.1)
+ octokit (4.21.0)
+ faraday (>= 0.9)
+ sawyer (~> 0.8.0, >= 0.5.3)
+ public_suffix (4.0.6)
+ ruby2_keywords (0.0.4)
+ sawyer (0.8.2)
+ addressable (>= 2.3.5)
+ faraday (> 0.8, < 2.0)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ octokit (= 4.21.0)
+ sawyer (= 0.8.2)
+
+BUNDLED WITH
+ 2.1.4
diff --git a/pkgs/servers/web-apps/discourse/plugins/discourse-github/default.nix b/pkgs/servers/web-apps/discourse/plugins/discourse-github/default.nix
new file mode 100644
index 000000000000..e5d8cff0a9fd
--- /dev/null
+++ b/pkgs/servers/web-apps/discourse/plugins/discourse-github/default.nix
@@ -0,0 +1,12 @@
+{ mkDiscoursePlugin, fetchFromGitHub }:
+
+mkDiscoursePlugin {
+ name = "discourse-github";
+ bundlerEnvArgs.gemdir = ./.;
+ src = fetchFromGitHub {
+ owner = "discourse";
+ repo = "discourse-github";
+ rev = "151e353a5a1971157c70c2e2b0f56387f212a81f";
+ sha256 = "00kra6zd2k1f2vwcdvxnxnammzh72f5qxcqbb94m0z6maj598wdy";
+ };
+}
diff --git a/pkgs/servers/web-apps/discourse/plugins/discourse-github/gemset.nix b/pkgs/servers/web-apps/discourse/plugins/discourse-github/gemset.nix
new file mode 100644
index 000000000000..bad1f9629578
--- /dev/null
+++ b/pkgs/servers/web-apps/discourse/plugins/discourse-github/gemset.nix
@@ -0,0 +1,126 @@
+{
+ addressable = {
+ dependencies = ["public_suffix"];
+ groups = ["default"];
+ platforms = [];
+ source = {
+ remotes = ["https://rubygems.org"];
+ sha256 = "1fvchp2rhp2rmigx7qglf69xvjqvzq7x0g49naliw29r2bz656sy";
+ type = "gem";
+ };
+ version = "2.7.0";
+ };
+ faraday = {
+ dependencies = ["faraday-em_http" "faraday-em_synchrony" "faraday-excon" "faraday-net_http" "faraday-net_http_persistent" "multipart-post" "ruby2_keywords"];
+ groups = ["default"];
+ platforms = [];
+ source = {
+ remotes = ["https://rubygems.org"];
+ sha256 = "07mhk70gv453pg38md346470hknyhipdqppnplq706ll3k3lzb7v";
+ type = "gem";
+ };
+ version = "1.4.2";
+ };
+ faraday-em_http = {
+ groups = ["default"];
+ platforms = [];
+ source = {
+ remotes = ["https://rubygems.org"];
+ sha256 = "12cnqpbak4vhikrh2cdn94assh3yxza8rq2p9w2j34bqg5q4qgbs";
+ type = "gem";
+ };
+ version = "1.0.0";
+ };
+ faraday-em_synchrony = {
+ groups = ["default"];
+ platforms = [];
+ source = {
+ remotes = ["https://rubygems.org"];
+ sha256 = "1vgrbhkp83sngv6k4mii9f2s9v5lmp693hylfxp2ssfc60fas3a6";
+ type = "gem";
+ };
+ version = "1.0.0";
+ };
+ faraday-excon = {
+ groups = ["default"];
+ platforms = [];
+ source = {
+ remotes = ["https://rubygems.org"];
+ sha256 = "0h09wkb0k0bhm6dqsd47ac601qiaah8qdzjh8gvxfd376x1chmdh";
+ type = "gem";
+ };
+ version = "1.1.0";
+ };
+ faraday-net_http = {
+ groups = ["default"];
+ platforms = [];
+ source = {
+ remotes = ["https://rubygems.org"];
+ sha256 = "1fi8sda5hc54v1w3mqfl5yz09nhx35kglyx72w7b8xxvdr0cwi9j";
+ type = "gem";
+ };
+ version = "1.0.1";
+ };
+ faraday-net_http_persistent = {
+ groups = ["default"];
+ platforms = [];
+ source = {
+ remotes = ["https://rubygems.org"];
+ sha256 = "0l2c835wl7gv34xp49fhd1bl4czkpw2g3ahqsak2251iqv5589ka";
+ type = "gem";
+ };
+ version = "1.1.0";
+ };
+ multipart-post = {
+ groups = ["default"];
+ platforms = [];
+ source = {
+ remotes = ["https://rubygems.org"];
+ sha256 = "1zgw9zlwh2a6i1yvhhc4a84ry1hv824d6g2iw2chs3k5aylpmpfj";
+ type = "gem";
+ };
+ version = "2.1.1";
+ };
+ octokit = {
+ dependencies = ["faraday" "sawyer"];
+ groups = ["default"];
+ platforms = [];
+ source = {
+ remotes = ["https://rubygems.org"];
+ sha256 = "0ak64rb48d8z98nw6q70r6i0i3ivv61iqla40ss5l79491qfnn27";
+ type = "gem";
+ };
+ version = "4.21.0";
+ };
+ public_suffix = {
+ groups = ["default"];
+ platforms = [];
+ source = {
+ remotes = ["https://rubygems.org"];
+ sha256 = "1xqcgkl7bwws1qrlnmxgh8g4g9m10vg60bhlw40fplninb3ng6d9";
+ type = "gem";
+ };
+ version = "4.0.6";
+ };
+ ruby2_keywords = {
+ groups = ["default"];
+ platforms = [];
+ source = {
+ remotes = ["https://rubygems.org"];
+ sha256 = "15wfcqxyfgka05v2a7kpg64x57gl1y4xzvnc9lh60bqx5sf1iqrs";
+ type = "gem";
+ };
+ version = "0.0.4";
+ };
+ sawyer = {
+ dependencies = ["addressable" "faraday"];
+ groups = ["default"];
+ platforms = [];
+ source = {
+ remotes = ["https://rubygems.org"];
+ sha256 = "0yrdchs3psh583rjapkv33mljdivggqn99wkydkjdckcjn43j3cz";
+ type = "gem";
+ };
+ version = "0.8.2";
+ };
+}
diff --git a/pkgs/servers/web-apps/discourse/plugins/discourse-math/default.nix b/pkgs/servers/web-apps/discourse/plugins/discourse-math/default.nix
new file mode 100644
index 000000000000..8cf2a4abc0d1
--- /dev/null
+++ b/pkgs/servers/web-apps/discourse/plugins/discourse-math/default.nix
@@ -0,0 +1,11 @@
+{ mkDiscoursePlugin, fetchFromGitHub }:
+
+mkDiscoursePlugin {
+ name = "discourse-math";
+ src = fetchFromGitHub {
+ owner = "discourse";
+ repo = "discourse-math";
+ rev = "143ddea4558ea9a1b3fd71635bc11e055763c8e7";
+ sha256 = "18pq5ybl3g34i39cpixc3nszvq8gx5yji58zlbbl6428mm011cbx";
+ };
+}
diff --git a/pkgs/servers/web-apps/discourse/plugins/discourse-solved/default.nix b/pkgs/servers/web-apps/discourse/plugins/discourse-solved/default.nix
new file mode 100644
index 000000000000..c382a83d0893
--- /dev/null
+++ b/pkgs/servers/web-apps/discourse/plugins/discourse-solved/default.nix
@@ -0,0 +1,11 @@
+{ mkDiscoursePlugin, fetchFromGitHub }:
+
+mkDiscoursePlugin {
+ name = "discourse-solved";
+ src = fetchFromGitHub {
+ owner = "discourse";
+ repo = "discourse-solved";
+ rev = "179611766d53974308e6f7def21836997c3c55fc";
+ sha256 = "sha256:1s77h42d3bv2lqw33akxh8ss482vxnz4d7qz6xicwqfwv34qjf03";
+ };
+}
diff --git a/pkgs/servers/web-apps/discourse/plugins/discourse-spoiler-alert/default.nix b/pkgs/servers/web-apps/discourse/plugins/discourse-spoiler-alert/default.nix
new file mode 100644
index 000000000000..8eba43e47e40
--- /dev/null
+++ b/pkgs/servers/web-apps/discourse/plugins/discourse-spoiler-alert/default.nix
@@ -0,0 +1,11 @@
+{ mkDiscoursePlugin, fetchFromGitHub }:
+
+mkDiscoursePlugin {
+ name = "discourse-spoiler-alert";
+ src = fetchFromGitHub {
+ owner = "discourse";
+ repo = "discourse-spoiler-alert";
+ rev = "e200cfa571d252cab63f3d30d619b370986e4cee";
+ sha256 = "0ya69ix5g77wz4c9x9gmng6l25ghb5xxlx3icr6jam16q14dzc33";
+ };
+}
diff --git a/pkgs/servers/web-apps/discourse/plugins/discourse-yearly-review/default.nix b/pkgs/servers/web-apps/discourse/plugins/discourse-yearly-review/default.nix
new file mode 100644
index 000000000000..8e76123ae593
--- /dev/null
+++ b/pkgs/servers/web-apps/discourse/plugins/discourse-yearly-review/default.nix
@@ -0,0 +1,11 @@
+{ mkDiscoursePlugin, fetchFromGitHub }:
+
+mkDiscoursePlugin {
+ name = "discourse-yearly-review";
+ src = fetchFromGitHub {
+ owner = "discourse";
+ repo = "discourse-yearly-review";
+ rev = "d1471bdb68945f55342e72e2c525b4f628419a50";
+ sha256 = "sha256:0xpl0l1vpih8xzb6y7k1lm72nj4ya99378viyhqfvpwzsn5pha2a";
+ };
+}
diff --git a/pkgs/servers/web-apps/discourse/use_mv_instead_of_rename.patch b/pkgs/servers/web-apps/discourse/use_mv_instead_of_rename.patch
new file mode 100644
index 000000000000..30493b543e38
--- /dev/null
+++ b/pkgs/servers/web-apps/discourse/use_mv_instead_of_rename.patch
@@ -0,0 +1,22 @@
+diff --git a/lib/discourse.rb b/lib/discourse.rb
+index ea2a3cbafd..66454d9157 100644
+--- a/lib/discourse.rb
++++ b/lib/discourse.rb
+@@ -62,7 +62,7 @@ module Discourse
+ fd.fsync()
+ end
+
+- File.rename(temp_destination, destination)
++ FileUtils.mv(temp_destination, destination)
+
+ nil
+ end
+@@ -76,7 +76,7 @@ module Discourse
+ FileUtils.mkdir_p(File.join(Rails.root, 'tmp'))
+ temp_destination = File.join(Rails.root, 'tmp', SecureRandom.hex)
+ execute_command('ln', '-s', source, temp_destination)
+- File.rename(temp_destination, destination)
++ FileUtils.mv(temp_destination, destination)
+
+ nil
+ end