14 # Allow building a fork or custom version of Mastodon:
16 version ? srcOverride.version,
19 srcOverride ? callPackage ./source.nix { inherit patches; },
20 gemset ? ./. + "/gemset.nix",
21 yarnHash ? srcOverride.yarnHash,
24 stdenv.mkDerivation rec {
25 inherit pname version;
29 mastodonGems = bundlerEnv {
30 name = "${pname}-gems-${version}";
31 inherit version gemset ruby;
35 mastodonModules = stdenv.mkDerivation {
36 pname = "${pname}-modules";
39 yarnOfflineCache = callPackage ./yarn.nix {
48 mastodonGems.wrappedRuby
53 RAILS_ENV = "production";
54 NODE_ENV = "production";
60 export YARN_ENABLE_TELEMETRY=0
61 export npm_config_nodedir=${nodejs-slim}
62 export SECRET_KEY_BASE_DUMMY=1
64 mkdir -p ~/.yarn/berry
65 ln -s $yarnOfflineCache ~/.yarn/berry/cache
67 yarn install --immutable --immutable-cache
70 patchShebangs ~/node_modules
72 bundle exec rails assets:precompile
74 yarn cache clean --all
75 rm -rf ~/node_modules/.cache
77 # Remove execute permissions
78 find ~/public/assets -type f ! -perm 0555 \
79 -exec chmod 0444 {} ';'
81 # Create missing static gzip and brotli files
82 find ~/public/assets -type f -regextype posix-extended -iregex '.*\.(css|html|js|json|svg)' \
83 -exec gzip --best --keep --force {} ';' \
84 -exec brotli --best --keep {} ';'
85 gzip --best --keep ~/public/packs/report.html
86 brotli --best --keep ~/public/packs/report.html
95 cp -r node_modules $out/node_modules
96 cp -r public/assets $out/public
97 cp -r public/packs $out/public
103 propagatedBuildInputs = [ mastodonGems.wrappedRuby ];
104 nativeBuildInputs = [ brotli ];
113 ln -s $mastodonModules/node_modules node_modules
114 ln -s $mastodonModules/public/assets public/assets
115 ln -s $mastodonModules/public/packs public/packs
118 for b in $(ls $mastodonGems/bin/)
120 if [ ! -f bin/$b ]; then
121 ln -s $mastodonGems/bin/$b bin/$b
125 # Remove execute permissions
126 find public/emoji -type f ! -perm 0555 \
127 -exec chmod 0444 {} ';'
129 # Create missing static gzip and brotli files
130 find public -maxdepth 1 -type f -regextype posix-extended -iregex '.*\.(js|txt)' \
131 -exec gzip --best --keep --force {} ';' \
132 -exec brotli --best --keep {} ';'
133 find public/emoji -type f -name '*.svg' \
134 -exec gzip --best --keep --force {} ';' \
135 -exec brotli --best --keep {} ';'
136 ln -s assets/500.html.gz public/500.html.gz
137 ln -s assets/500.html.br public/500.html.br
138 ln -s packs/sw.js.gz public/sw.js.gz
139 ln -s packs/sw.js.br public/sw.js.br
140 ln -s packs/sw.js.map.gz public/sw.js.map.gz
141 ln -s packs/sw.js.map.br public/sw.js.map.br
144 ln -s /var/log/mastodon log
152 run-streaming = writeShellScript "run-streaming.sh" ''
153 # NixOS helper script to consistently use the same NodeJS version the package was built with.
154 ${nodejs-slim}/bin/node ./streaming
161 mv .{env*,ruby*} $out/
163 ln -s ${run-streaming} $out/run-streaming.sh
169 tests.mastodon = nixosTests.mastodon;
170 # run with: nix-shell ./maintainers/scripts/update.nix --argstr package mastodon
171 updateScript = ./update.sh;
175 description = "Self-hosted, globally interconnected microblogging software based on ActivityPub";
176 homepage = "https://joinmastodon.org";
177 license = licenses.agpl3Plus;
183 maintainers = with maintainers; [