Merge pull request #127931 from talyz/discourse-plugins
discourse: Fix plugin support
This commit is contained in:
commit
272773e1cb
14 changed files with 339 additions and 10 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
13
pkgs/servers/web-apps/discourse/plugin_gem_api_version.patch
Normal file
13
pkgs/servers/web-apps/discourse/plugin_gem_api_version.patch
Normal file
|
@ -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"
|
||||
|
12
pkgs/servers/web-apps/discourse/plugins/all-plugins.nix
Normal file
12
pkgs/servers/web-apps/discourse/plugins/all-plugins.nix
Normal file
|
@ -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 {};
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
{ mkDiscoursePlugin, fetchFromGitHub }:
|
||||
|
||||
mkDiscoursePlugin {
|
||||
name = "discourse-canned-replies";
|
||||
src = fetchFromGitHub {
|
||||
owner = "discourse";
|
||||
repo = "discourse-canned-replies";
|
||||
rev = "7ee748f18a276aca42185e2079c1d4cadeecdaf8";
|
||||
sha256 = "0j10kxfr6v2rdd58smg2i7iac46z74qnnjk8b91jd1svazhis1ph";
|
||||
};
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
source 'https://rubygems.org'
|
||||
gem 'sawyer', '0.8.2'
|
||||
gem 'octokit', '4.21.0'
|
|
@ -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
|
|
@ -0,0 +1,12 @@
|
|||
{ mkDiscoursePlugin, fetchFromGitHub }:
|
||||
|
||||
mkDiscoursePlugin {
|
||||
name = "discourse-github";
|
||||
bundlerEnvArgs.gemdir = ./.;
|
||||
src = fetchFromGitHub {
|
||||
owner = "discourse";
|
||||
repo = "discourse-github";
|
||||
rev = "151e353a5a1971157c70c2e2b0f56387f212a81f";
|
||||
sha256 = "00kra6zd2k1f2vwcdvxnxnammzh72f5qxcqbb94m0z6maj598wdy";
|
||||
};
|
||||
}
|
|
@ -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";
|
||||
};
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
{ mkDiscoursePlugin, fetchFromGitHub }:
|
||||
|
||||
mkDiscoursePlugin {
|
||||
name = "discourse-math";
|
||||
src = fetchFromGitHub {
|
||||
owner = "discourse";
|
||||
repo = "discourse-math";
|
||||
rev = "143ddea4558ea9a1b3fd71635bc11e055763c8e7";
|
||||
sha256 = "18pq5ybl3g34i39cpixc3nszvq8gx5yji58zlbbl6428mm011cbx";
|
||||
};
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
{ mkDiscoursePlugin, fetchFromGitHub }:
|
||||
|
||||
mkDiscoursePlugin {
|
||||
name = "discourse-solved";
|
||||
src = fetchFromGitHub {
|
||||
owner = "discourse";
|
||||
repo = "discourse-solved";
|
||||
rev = "179611766d53974308e6f7def21836997c3c55fc";
|
||||
sha256 = "sha256:1s77h42d3bv2lqw33akxh8ss482vxnz4d7qz6xicwqfwv34qjf03";
|
||||
};
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
{ mkDiscoursePlugin, fetchFromGitHub }:
|
||||
|
||||
mkDiscoursePlugin {
|
||||
name = "discourse-spoiler-alert";
|
||||
src = fetchFromGitHub {
|
||||
owner = "discourse";
|
||||
repo = "discourse-spoiler-alert";
|
||||
rev = "e200cfa571d252cab63f3d30d619b370986e4cee";
|
||||
sha256 = "0ya69ix5g77wz4c9x9gmng6l25ghb5xxlx3icr6jam16q14dzc33";
|
||||
};
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
{ mkDiscoursePlugin, fetchFromGitHub }:
|
||||
|
||||
mkDiscoursePlugin {
|
||||
name = "discourse-yearly-review";
|
||||
src = fetchFromGitHub {
|
||||
owner = "discourse";
|
||||
repo = "discourse-yearly-review";
|
||||
rev = "d1471bdb68945f55342e72e2c525b4f628419a50";
|
||||
sha256 = "sha256:0xpl0l1vpih8xzb6y7k1lm72nj4ya99378viyhqfvpwzsn5pha2a";
|
||||
};
|
||||
}
|
|
@ -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
|
Loading…
Reference in a new issue