1 { lib, stdenv, nodejs-slim, bundlerEnv, nixosTests
2 , yarn, callPackage, imagemagick, ffmpeg, file, ruby, writeShellScript
3 , fetchYarnDeps, fixup_yarn_lock
6 # Allow building a fork or custom version of Mastodon:
8 , version ? srcOverride.version
10 , srcOverride ? callPackage ./source.nix {}
11 , gemset ? ./. + "/gemset.nix"
12 , yarnHash ? srcOverride.yarnHash
15 stdenv.mkDerivation rec {
16 inherit pname version;
20 mastodonGems = bundlerEnv {
21 name = "${pname}-gems-${version}";
22 inherit version gemset ruby;
24 # This fix (copied from https://github.com/NixOS/nixpkgs/pull/76765) replaces the gem
25 # symlinks with directories, resolving this error when running rake:
26 # /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)
28 for gem in "$out"/lib/ruby/gems/*/gems/*; do
29 cp -a "$gem/" "$gem.new"
31 # needed on macOS, otherwise the mv yields permission denied
38 mastodonModules = stdenv.mkDerivation {
39 pname = "${pname}-modules";
42 yarnOfflineCache = fetchYarnDeps {
43 yarnLock = "${src}/yarn.lock";
47 nativeBuildInputs = [ fixup_yarn_lock nodejs-slim yarn mastodonGems mastodonGems.wrappedRuby brotli ];
49 RAILS_ENV = "production";
50 NODE_ENV = "production";
56 # This option is needed for openssl-3 compatibility
57 # Otherwise we encounter this upstream issue: https://github.com/mastodon/mastodon/issues/17924
58 export NODE_OPTIONS=--openssl-legacy-provider
59 fixup_yarn_lock ~/yarn.lock
60 yarn config --offline set yarn-offline-mirror $yarnOfflineCache
61 yarn install --offline --frozen-lockfile --ignore-engines --ignore-scripts --no-progress
64 patchShebangs ~/node_modules
66 # skip running yarn install
69 OTP_SECRET=precompile_placeholder SECRET_KEY_BASE=precompile_placeholder \
70 rails assets:precompile
71 yarn cache clean --offline
72 rm -rf ~/node_modules/.cache
74 # Create missing static gzip and brotli files
75 gzip --best --keep ~/public/assets/500.html
76 gzip --best --keep ~/public/packs/report.html
77 find ~/public/assets -maxdepth 1 -type f -name '.*.json' \
78 -exec gzip --best --keep --force {} ';'
79 brotli --best --keep ~/public/packs/report.html
80 find ~/public/assets -type f -regextype posix-extended -iregex '.*\.(css|js|json|html)' \
81 -exec brotli --best --keep {} ';'
90 cp -r node_modules $out/node_modules
91 cp -r public/assets $out/public
92 cp -r public/packs $out/public
98 propagatedBuildInputs = [ imagemagick ffmpeg file mastodonGems.wrappedRuby ];
99 buildInputs = [ mastodonGems nodejs-slim ];
104 ln -s $mastodonModules/node_modules node_modules
105 ln -s $mastodonModules/public/assets public/assets
106 ln -s $mastodonModules/public/packs public/packs
109 for b in $(ls $mastodonGems/bin/)
111 if [ ! -f bin/$b ]; then
112 ln -s $mastodonGems/bin/$b bin/$b
116 # Remove execute permissions
117 chmod 0444 public/emoji/*.svg
119 # Create missing static gzip and brotli files
120 find public -maxdepth 1 -type f -regextype posix-extended -iregex '.*\.(css|js|svg|txt|xml)' \
121 -exec gzip --best --keep --force {} ';' \
122 -exec brotli --best --keep {} ';'
123 find public/emoji -type f -name '.*.svg' \
124 -exec gzip --best --keep --force {} ';' \
125 -exec brotli --best --keep {} ';'
126 ln -s assets/500.html.gz public/500.html.gz
127 ln -s assets/500.html.br public/500.html.br
128 ln -s packs/sw.js.gz public/sw.js.gz
129 ln -s packs/sw.js.br public/sw.js.br
130 ln -s packs/sw.js.map.gz public/sw.js.map.gz
131 ln -s packs/sw.js.map.br public/sw.js.map.br
134 ln -s /var/log/mastodon log
141 run-streaming = writeShellScript "run-streaming.sh" ''
142 # NixOS helper script to consistently use the same NodeJS version the package was built with.
143 ${nodejs-slim}/bin/node ./streaming
150 ln -s ${run-streaming} $out/run-streaming.sh
156 tests.mastodon = nixosTests.mastodon;
157 # run with: nix-shell ./maintainers/scripts/update.nix --argstr package mastodon
158 updateScript = ./update.sh;
162 description = "Self-hosted, globally interconnected microblogging software based on ActivityPub";
163 homepage = "https://joinmastodon.org";
164 license = licenses.agpl3Plus;
165 platforms = [ "x86_64-linux" "i686-linux" "aarch64-linux" ];
166 maintainers = with maintainers; [ happy-river erictapen izorkin ghuntley ];