2022-03-20 23:35:17 +00:00
|
|
|
{ lib, stdenv, nodejs-slim, mkYarnPackage, fetchFromGitHub, bundlerEnv, nixosTests
|
2021-05-17 00:33:58 +01:00
|
|
|
, yarn, callPackage, imagemagick, ffmpeg, file, ruby_3_0, writeShellScript
|
2022-03-20 19:18:19 +00:00
|
|
|
, fetchYarnDeps, fixup_yarn_lock
|
2022-08-23 00:21:20 +01:00
|
|
|
, brotli
|
2019-05-02 15:50:28 +01:00
|
|
|
|
|
|
|
# Allow building a fork or custom version of Mastodon:
|
|
|
|
, pname ? "mastodon"
|
|
|
|
, version ? import ./version.nix
|
|
|
|
, srcOverride ? null
|
|
|
|
, dependenciesDir ? ./. # Should contain gemset.nix, yarn.nix and package.json.
|
|
|
|
}:
|
|
|
|
|
|
|
|
stdenv.mkDerivation rec {
|
|
|
|
inherit pname version;
|
|
|
|
|
|
|
|
# Using overrideAttrs on src does not build the gems and modules with the overridden src.
|
|
|
|
# Putting the callPackage up in the arguments list also does not work.
|
|
|
|
src = if srcOverride != null then srcOverride else callPackage ./source.nix {};
|
|
|
|
|
2023-01-07 21:14:35 +00:00
|
|
|
mastodonGems = bundlerEnv {
|
2019-05-02 15:50:28 +01:00
|
|
|
name = "${pname}-gems-${version}";
|
|
|
|
inherit version;
|
2021-05-17 00:33:58 +01:00
|
|
|
ruby = ruby_3_0;
|
2019-05-02 15:50:28 +01:00
|
|
|
gemdir = src;
|
|
|
|
gemset = dependenciesDir + "/gemset.nix";
|
|
|
|
# This fix (copied from https://github.com/NixOS/nixpkgs/pull/76765) replaces the gem
|
|
|
|
# symlinks with directories, resolving this error when running rake:
|
|
|
|
# /nix/store/451rhxkggw53h7253izpbq55nrhs7iv0-mastodon-gems-3.0.1/lib/ruby/gems/2.6.0/gems/bundler-1.17.3/lib/bundler/settings.rb:6:in `<module:Bundler>': uninitialized constant Bundler::Settings (NameError)
|
|
|
|
postBuild = ''
|
|
|
|
for gem in "$out"/lib/ruby/gems/*/gems/*; do
|
|
|
|
cp -a "$gem/" "$gem.new"
|
|
|
|
rm "$gem"
|
|
|
|
# needed on macOS, otherwise the mv yields permission denied
|
|
|
|
chmod +w "$gem.new"
|
|
|
|
mv "$gem.new" "$gem"
|
|
|
|
done
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2023-01-07 21:14:35 +00:00
|
|
|
mastodonModules = stdenv.mkDerivation {
|
2019-05-02 15:50:28 +01:00
|
|
|
pname = "${pname}-modules";
|
|
|
|
inherit src version;
|
|
|
|
|
2022-09-26 16:18:52 +01:00
|
|
|
yarnOfflineCache = fetchYarnDeps {
|
|
|
|
yarnLock = "${src}/yarn.lock";
|
2022-11-06 16:44:38 +00:00
|
|
|
sha256 = "sha256-fuU92fydoazSXBHwA+DG//gRgWVYQ1M3m2oNS2iwv4I=";
|
2022-09-26 16:18:52 +01:00
|
|
|
};
|
|
|
|
|
2022-08-23 00:21:20 +01:00
|
|
|
nativeBuildInputs = [ fixup_yarn_lock nodejs-slim yarn mastodonGems mastodonGems.wrappedRuby brotli ];
|
2019-05-02 15:50:28 +01:00
|
|
|
|
2022-03-20 19:18:19 +00:00
|
|
|
RAILS_ENV = "production";
|
|
|
|
NODE_ENV = "production";
|
2019-05-02 15:50:28 +01:00
|
|
|
|
|
|
|
buildPhase = ''
|
2022-03-20 19:18:19 +00:00
|
|
|
export HOME=$PWD
|
2022-09-25 19:39:15 +01:00
|
|
|
# This option is needed for openssl-3 compatibility
|
|
|
|
# Otherwise we encounter this upstream issue: https://github.com/mastodon/mastodon/issues/17924
|
|
|
|
export NODE_OPTIONS=--openssl-legacy-provider
|
2022-03-20 19:18:19 +00:00
|
|
|
fixup_yarn_lock ~/yarn.lock
|
2022-09-26 16:18:52 +01:00
|
|
|
yarn config --offline set yarn-offline-mirror $yarnOfflineCache
|
2022-03-20 19:18:19 +00:00
|
|
|
yarn install --offline --frozen-lockfile --ignore-engines --ignore-scripts --no-progress
|
2022-03-20 23:35:17 +00:00
|
|
|
|
|
|
|
patchShebangs ~/bin
|
2022-03-20 19:18:19 +00:00
|
|
|
patchShebangs ~/node_modules
|
|
|
|
|
2022-03-20 23:35:17 +00:00
|
|
|
# skip running yarn install
|
|
|
|
rm -rf ~/bin/yarn
|
|
|
|
|
2022-03-20 19:18:19 +00:00
|
|
|
OTP_SECRET=precompile_placeholder SECRET_KEY_BASE=precompile_placeholder \
|
|
|
|
rails assets:precompile
|
|
|
|
yarn cache clean --offline
|
|
|
|
rm -rf ~/node_modules/.cache
|
2022-08-23 00:21:20 +01:00
|
|
|
|
|
|
|
# Create missing static gzip and brotli files
|
|
|
|
gzip -9 -n -c ~/public/assets/500.html > ~/public/assets/500.html.gz
|
|
|
|
gzip -9 -n -c ~/public/packs/report.html > ~/public/packs/report.html.gz
|
|
|
|
find ~/public/assets -maxdepth 1 -type f -name ".*.json" | while read file; do
|
|
|
|
gzip -9 -n -c $file > $file.gz
|
|
|
|
done
|
|
|
|
brotli --best -f ~/public/packs/report.html -o ~/public/packs/report.html.br
|
|
|
|
find ~/public/assets -type f -regextype posix-extended -iregex '.*\.(css|js|json|html)' | while read file; do
|
|
|
|
brotli --best -f $file -o $file.br
|
|
|
|
done
|
2019-05-02 15:50:28 +01:00
|
|
|
'';
|
|
|
|
|
|
|
|
installPhase = ''
|
|
|
|
mkdir -p $out/public
|
2022-03-20 19:18:19 +00:00
|
|
|
cp -r node_modules $out/node_modules
|
2019-05-02 15:50:28 +01:00
|
|
|
cp -r public/assets $out/public
|
|
|
|
cp -r public/packs $out/public
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2023-01-07 21:14:35 +00:00
|
|
|
propagatedBuildInputs = [ imagemagick ffmpeg file mastodonGems.wrappedRuby ];
|
|
|
|
buildInputs = [ mastodonGems nodejs-slim ];
|
2019-05-02 15:50:28 +01:00
|
|
|
|
|
|
|
buildPhase = ''
|
2023-01-07 21:14:35 +00:00
|
|
|
ln -s $mastodonModules/node_modules node_modules
|
|
|
|
ln -s $mastodonModules/public/assets public/assets
|
|
|
|
ln -s $mastodonModules/public/packs public/packs
|
2019-05-02 15:50:28 +01:00
|
|
|
|
|
|
|
patchShebangs bin/
|
2023-01-07 21:14:35 +00:00
|
|
|
for b in $(ls $mastodonGems/bin/)
|
2019-05-02 15:50:28 +01:00
|
|
|
do
|
|
|
|
if [ ! -f bin/$b ]; then
|
2023-01-07 21:14:35 +00:00
|
|
|
ln -s $mastodonGems/bin/$b bin/$b
|
2019-05-02 15:50:28 +01:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2022-08-23 00:21:20 +01:00
|
|
|
# Create missing static gzip and brotli files
|
|
|
|
find public -maxdepth 1 -type f -regextype posix-extended -iregex '.*\.(css|js|svg|txt|xml)' | while read file; do
|
|
|
|
gzip -9 -n -c $file > $file.gz
|
|
|
|
brotli --best -f $file -o $file.br
|
|
|
|
done
|
|
|
|
find public/emoji -type f -name "*.svg" | while read file; do
|
|
|
|
gzip -9 -n -c $file > $file.gz
|
|
|
|
brotli --best -f $file -o $file.br
|
|
|
|
done
|
|
|
|
ln -s assets/500.html.gz public/500.html.gz
|
|
|
|
ln -s assets/500.html.br public/500.html.br
|
|
|
|
ln -s packs/sw.js.gz public/sw.js.gz
|
|
|
|
ln -s packs/sw.js.br public/sw.js.br
|
|
|
|
ln -s packs/sw.js.map.gz public/sw.js.map.gz
|
|
|
|
ln -s packs/sw.js.map.br public/sw.js.map.br
|
|
|
|
|
2019-05-02 15:50:28 +01:00
|
|
|
rm -rf log
|
|
|
|
ln -s /var/log/mastodon log
|
|
|
|
ln -s /tmp tmp
|
|
|
|
'';
|
2021-02-16 07:09:14 +00:00
|
|
|
|
|
|
|
installPhase = let
|
|
|
|
run-streaming = writeShellScript "run-streaming.sh" ''
|
|
|
|
# NixOS helper script to consistently use the same NodeJS version the package was built with.
|
|
|
|
${nodejs-slim}/bin/node ./streaming
|
|
|
|
'';
|
|
|
|
in ''
|
2019-05-02 15:50:28 +01:00
|
|
|
mkdir -p $out
|
|
|
|
cp -r * $out/
|
2021-02-16 07:09:14 +00:00
|
|
|
ln -s ${run-streaming} $out/run-streaming.sh
|
2019-05-02 15:50:28 +01:00
|
|
|
'';
|
|
|
|
|
2022-03-20 19:18:19 +00:00
|
|
|
passthru = {
|
|
|
|
tests.mastodon = nixosTests.mastodon;
|
|
|
|
updateScript = callPackage ./update.nix {};
|
|
|
|
};
|
2022-03-18 14:39:32 +00:00
|
|
|
|
2019-05-02 15:50:28 +01:00
|
|
|
meta = with lib; {
|
|
|
|
description = "Self-hosted, globally interconnected microblogging software based on ActivityPub";
|
|
|
|
homepage = "https://joinmastodon.org";
|
|
|
|
license = licenses.agpl3Plus;
|
2022-02-19 13:59:05 +00:00
|
|
|
platforms = [ "x86_64-linux" "i686-linux" "aarch64-linux" ];
|
2022-11-16 07:52:00 +00:00
|
|
|
maintainers = with maintainers; [ happy-river erictapen izorkin ghuntley ];
|
2019-05-02 15:50:28 +01:00
|
|
|
};
|
|
|
|
}
|