diff options
Diffstat (limited to 'nixpkgs/pkgs/servers/web-apps/discourse/default.nix')
-rw-r--r-- | nixpkgs/pkgs/servers/web-apps/discourse/default.nix | 64 |
1 files changed, 56 insertions, 8 deletions
diff --git a/nixpkgs/pkgs/servers/web-apps/discourse/default.nix b/nixpkgs/pkgs/servers/web-apps/discourse/default.nix index 5e7c4d5368a4..5a3301040d33 100644 --- a/nixpkgs/pkgs/servers/web-apps/discourse/default.nix +++ b/nixpkgs/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; }; |