1 { lib, stdenv, nodejs-slim, bundlerEnv, nixosTests
2 , yarn, callPackage, ruby, writeShellScript
3 , fetchYarnDeps, fixup-yarn-lock
6 # Allow building a fork or custom version of Mastodon:
8 , version ? srcOverride.version
11 , srcOverride ? callPackage ./source.nix { inherit patches; }
12 , gemset ? ./. + "/gemset.nix"
13 , yarnHash ? srcOverride.yarnHash
16 stdenv.mkDerivation rec {
17 inherit pname version;
21 mastodonGems = bundlerEnv {
22 name = "${pname}-gems-${version}";
23 inherit version gemset ruby;
27 mastodonModules = stdenv.mkDerivation {
28 pname = "${pname}-modules";
31 yarnOfflineCache = fetchYarnDeps {
32 yarnLock = "${src}/yarn.lock";
36 nativeBuildInputs = [ fixup-yarn-lock nodejs-slim yarn mastodonGems mastodonGems.wrappedRuby brotli ];
38 RAILS_ENV = "production";
39 NODE_ENV = "production";
45 fixup-yarn-lock ~/yarn.lock
46 yarn config --offline set yarn-offline-mirror $yarnOfflineCache
47 yarn install --offline --frozen-lockfile --ignore-engines --ignore-scripts --no-progress
50 patchShebangs ~/node_modules
52 # skip running yarn install
55 OTP_SECRET=precompile_placeholder SECRET_KEY_BASE=precompile_placeholder \
56 rails assets:precompile
57 yarn cache clean --offline
58 rm -rf ~/node_modules/.cache
60 # Create missing static gzip and brotli files
61 gzip --best --keep ~/public/assets/500.html
62 gzip --best --keep ~/public/packs/report.html
63 find ~/public/assets -maxdepth 1 -type f -name '.*.json' \
64 -exec gzip --best --keep --force {} ';'
65 brotli --best --keep ~/public/packs/report.html
66 find ~/public/assets -type f -regextype posix-extended -iregex '.*\.(css|js|json|html)' \
67 -exec brotli --best --keep {} ';'
76 cp -r node_modules $out/node_modules
77 cp -r public/assets $out/public
78 cp -r public/packs $out/public
84 propagatedBuildInputs = [ mastodonGems.wrappedRuby ];
85 nativeBuildInputs = [ brotli ];
86 buildInputs = [ mastodonGems nodejs-slim ];
91 ln -s $mastodonModules/node_modules node_modules
92 ln -s $mastodonModules/public/assets public/assets
93 ln -s $mastodonModules/public/packs public/packs
96 for b in $(ls $mastodonGems/bin/)
98 if [ ! -f bin/$b ]; then
99 ln -s $mastodonGems/bin/$b bin/$b
103 # Remove execute permissions
104 chmod 0444 public/emoji/*.svg
106 # Create missing static gzip and brotli files
107 find public -maxdepth 1 -type f -regextype posix-extended -iregex '.*\.(css|js|svg|txt|xml)' \
108 -exec gzip --best --keep --force {} ';' \
109 -exec brotli --best --keep {} ';'
110 find public/emoji -type f -name '.*.svg' \
111 -exec gzip --best --keep --force {} ';' \
112 -exec brotli --best --keep {} ';'
113 ln -s assets/500.html.gz public/500.html.gz
114 ln -s assets/500.html.br public/500.html.br
115 ln -s packs/sw.js.gz public/sw.js.gz
116 ln -s packs/sw.js.br public/sw.js.br
117 ln -s packs/sw.js.map.gz public/sw.js.map.gz
118 ln -s packs/sw.js.map.br public/sw.js.map.br
121 ln -s /var/log/mastodon log
128 run-streaming = writeShellScript "run-streaming.sh" ''
129 # NixOS helper script to consistently use the same NodeJS version the package was built with.
130 ${nodejs-slim}/bin/node ./streaming
137 ln -s ${run-streaming} $out/run-streaming.sh
143 tests.mastodon = nixosTests.mastodon;
144 # run with: nix-shell ./maintainers/scripts/update.nix --argstr package mastodon
145 updateScript = ./update.sh;
149 description = "Self-hosted, globally interconnected microblogging software based on ActivityPub";
150 homepage = "https://joinmastodon.org";
151 license = licenses.agpl3Plus;
152 platforms = [ "x86_64-linux" "i686-linux" "aarch64-linux" ];
153 maintainers = with maintainers; [ happy-river erictapen izorkin ghuntley ];