discourse: Add a proper plugin builder + a few initial packages

Some discourse plugins have Ruby dependencies and require a
specialized builder. This introduces a generic builder that can be
used whether the plugin has Ruby dependencies or not. It also adds a
set of pre-packaged plugins available through `discourse.plugins` and
provides an easy way to add more.
This commit is contained in:
talyz 2021-06-24 19:45:37 +02:00
parent f0ae7fdf7e
commit 7671b90919
No known key found for this signature in database
GPG key ID: 2DED2151F4671A2B
12 changed files with 306 additions and 7 deletions

View file

@ -1,8 +1,9 @@
{ 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 ? []
}:
@ -48,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 ];
} ''
@ -123,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
@ -150,7 +186,7 @@ let
mkdir $NIX_BUILD_TOP/tmp_home
export HOME=$NIX_BUILD_TOP/tmp_home
${lib.concatMapStringsSep "\n" (p: "cp -r ${p} plugins/") plugins}
${lib.concatMapStringsSep "\n" (p: "ln -sf ${p} plugins/${p.pluginName or ""}") plugins}
export RAILS_ENV=production
@ -200,6 +236,10 @@ let
# 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
@ -235,7 +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/") plugins}
${lib.concatMapStringsSep "\n" (p: "ln -sf ${p} $out/share/discourse/plugins/${p.pluginName or ""}") plugins}
runHook postInstall
'';
@ -249,8 +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;
};

View 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"

View 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 {};
}

View file

@ -0,0 +1,11 @@
{ mkDiscoursePlugin, fetchFromGitHub }:
mkDiscoursePlugin {
name = "discourse-canned-replies";
src = fetchFromGitHub {
owner = "discourse";
repo = "discourse-canned-replies";
rev = "7ee748f18a276aca42185e2079c1d4cadeecdaf8";
sha256 = "0j10kxfr6v2rdd58smg2i7iac46z74qnnjk8b91jd1svazhis1ph";
};
}

View file

@ -0,0 +1,3 @@
source 'https://rubygems.org'
gem 'sawyer', '0.8.2'
gem 'octokit', '4.21.0'

View file

@ -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

View file

@ -0,0 +1,12 @@
{ mkDiscoursePlugin, fetchFromGitHub }:
mkDiscoursePlugin {
name = "discourse-github";
bundlerEnvArgs.gemdir = ./.;
src = fetchFromGitHub {
owner = "discourse";
repo = "discourse-github";
rev = "151e353a5a1971157c70c2e2b0f56387f212a81f";
sha256 = "00kra6zd2k1f2vwcdvxnxnammzh72f5qxcqbb94m0z6maj598wdy";
};
}

View file

@ -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";
};
}

View file

@ -0,0 +1,11 @@
{ mkDiscoursePlugin, fetchFromGitHub }:
mkDiscoursePlugin {
name = "discourse-math";
src = fetchFromGitHub {
owner = "discourse";
repo = "discourse-math";
rev = "143ddea4558ea9a1b3fd71635bc11e055763c8e7";
sha256 = "18pq5ybl3g34i39cpixc3nszvq8gx5yji58zlbbl6428mm011cbx";
};
}

View file

@ -0,0 +1,11 @@
{ mkDiscoursePlugin, fetchFromGitHub }:
mkDiscoursePlugin {
name = "discourse-solved";
src = fetchFromGitHub {
owner = "discourse";
repo = "discourse-solved";
rev = "179611766d53974308e6f7def21836997c3c55fc";
sha256 = "sha256:1s77h42d3bv2lqw33akxh8ss482vxnz4d7qz6xicwqfwv34qjf03";
};
}

View file

@ -0,0 +1,11 @@
{ mkDiscoursePlugin, fetchFromGitHub }:
mkDiscoursePlugin {
name = "discourse-spoiler-alert";
src = fetchFromGitHub {
owner = "discourse";
repo = "discourse-spoiler-alert";
rev = "e200cfa571d252cab63f3d30d619b370986e4cee";
sha256 = "0ya69ix5g77wz4c9x9gmng6l25ghb5xxlx3icr6jam16q14dzc33";
};
}

View file

@ -0,0 +1,11 @@
{ mkDiscoursePlugin, fetchFromGitHub }:
mkDiscoursePlugin {
name = "discourse-yearly-review";
src = fetchFromGitHub {
owner = "discourse";
repo = "discourse-yearly-review";
rev = "d1471bdb68945f55342e72e2c525b4f628419a50";
sha256 = "sha256:0xpl0l1vpih8xzb6y7k1lm72nj4ya99378viyhqfvpwzsn5pha2a";
};
}