]>
Commit | Line | Data |
---|---|---|
1 | { varDir ? "/var/lib/mastodon", | |
2 | stdenv, src, writeText, runCommand, | |
3 | ruby_2_6, bundlerEnv, defaultGemConfig, | |
4 | jq, protobuf, protobufc, pkgconfig, libidn, pam, nodejs, yarn, yarn2nix-moretea }: | |
5 | let | |
6 | patched = runCommand "mastodon-patched" { | |
7 | source = src; | |
8 | } '' | |
9 | cp -a $source $out | |
10 | chmod -R u+w $out | |
11 | sed -i -e "/fuubar/s/2.4.0/2.4.1/" $out/Gemfile.lock | |
12 | sed -i -e "s/ff00dc470b5b2d9f145a6d6e977a54de5df2b4c9/ff00dc470b5b2d9f145a6d6e977a54de5df2b4c9#4255dc41fa7df9c3a02c1595f058e248bc37b784/" $out/yarn.lock | |
13 | ''; | |
14 | gems = bundlerEnv { | |
15 | name = "mastodon-env"; | |
16 | ruby = ruby_2_6; | |
17 | gemset = ./gemset.nix; | |
18 | gemdir = patched; | |
19 | groups = [ "default" "production" "test" "development" ]; | |
20 | gemConfig = defaultGemConfig // { | |
21 | redis-rack = attrs: { | |
22 | preBuild = '' | |
23 | sed -i 's!s\.files.*!!' redis-rack.gemspec | |
24 | ''; | |
25 | }; | |
26 | tzinfo = attrs: { | |
27 | preBuild = '' | |
28 | sed -i 's!s\.files.*!!' tzinfo.gemspec | |
29 | ''; | |
30 | }; | |
31 | cld3 = attrs: { | |
32 | buildInputs = [ protobuf protobufc pkgconfig ]; | |
33 | }; | |
34 | idn-ruby = attrs: { | |
35 | buildInputs = [ libidn ]; | |
36 | }; | |
37 | rpam2 = attrs: { | |
38 | buildInputs = [ pam ]; | |
39 | }; | |
40 | }; | |
41 | }; | |
42 | yarnModules = let | |
43 | packagejson = runCommand "package.json" { buildInputs = [ jq ]; } '' | |
44 | cat ${patched}/package.json | jq -r '.version = "${src.version}"' > $out | |
45 | ''; | |
46 | in | |
47 | yarn2nix-moretea.mkYarnModules rec { | |
48 | name = "mastodon-yarn"; | |
49 | pname = name; | |
50 | version = src.version; | |
51 | packageJSON = packagejson; | |
52 | yarnLock = "${patched}/yarn.lock"; | |
53 | yarnNix = ./yarn-packages.nix; | |
54 | pkgConfig = { | |
55 | uws = { | |
56 | postInstall = '' | |
57 | npx node-gyp rebuild > build_log.txt 2>&1 || true | |
58 | ''; | |
59 | }; | |
60 | }; | |
61 | }; | |
62 | mastodon_with_yarn = stdenv.mkDerivation { | |
63 | pname = "mastodon"; | |
64 | version = src.version; | |
65 | inherit src; | |
66 | installPhase = '' | |
67 | cp -a . $out | |
68 | cp -a ${yarnModules}/node_modules $out | |
69 | ''; | |
70 | buildInputs = [ yarnModules ]; | |
71 | }; | |
72 | in | |
73 | stdenv.mkDerivation { | |
74 | name = "mastodon"; | |
75 | version = src.version; | |
76 | inherit mastodon_with_yarn; | |
77 | builder = writeText "build_mastodon" '' | |
78 | source $stdenv/setup | |
79 | set -a | |
80 | SECRET_KEY_BASE=Dummy | |
81 | OTP_SECRET=Dummy | |
82 | set +a | |
83 | cp -a $mastodon_with_yarn $out | |
84 | cd $out | |
85 | chmod u+rwX . public | |
86 | chmod -R u+rwX config/ node_modules/ | |
87 | sed -i -e 's@^end$@ config.action_mailer.sendmail_settings = { location: ENV.fetch("SENDMAIL_LOCATION", "/usr/sbin/sendmail") }\nend@' config/environments/production.rb | |
88 | RAILS_ENV=production ${gems}/bin/rails assets:precompile | |
89 | rm -rf tmp/cache | |
90 | ln -sf ${varDir}/tmp/cache tmp | |
91 | ''; | |
92 | buildInputs = [ gems gems.ruby nodejs yarn ]; | |
93 | passthru = { inherit gems varDir nodejs; }; | |
94 | } |