]>
Commit | Line | Data |
---|---|---|
1 | { varDir ? "/var/lib/mastodon", mylibs, | |
2 | stdenv, writeText, runCommand, | |
3 | ruby_2_6, bundlerEnv, defaultGemConfig, | |
4 | jq, protobuf, protobufc, pkgconfig, libidn, pam, nodejs, yarn }: | |
5 | let | |
6 | info = mylibs.fetchedGithub ./mastodon.json // { | |
7 | src= runCommand "mastodon-patched" { | |
8 | source = (mylibs.fetchedGithub ./mastodon.json).src; | |
9 | } '' | |
10 | cp -a $source $out | |
11 | chmod -R u+w $out | |
12 | sed -i -e "/fuubar/s/2.4.0/2.4.1/" $out/Gemfile.lock | |
13 | ''; | |
14 | }; | |
15 | gems = bundlerEnv { | |
16 | name = "mastodon-env"; | |
17 | ruby = ruby_2_6; | |
18 | gemset = ./gemset.nix; | |
19 | gemdir = info.src; | |
20 | groups = [ "default" "production" "test" "development" ]; | |
21 | gemConfig = defaultGemConfig // { | |
22 | redis-rack = attrs: { | |
23 | preBuild = '' | |
24 | sed -i 's!s\.files.*!!' redis-rack.gemspec | |
25 | ''; | |
26 | }; | |
27 | tzinfo = attrs: { | |
28 | preBuild = '' | |
29 | sed -i 's!s\.files.*!!' tzinfo.gemspec | |
30 | ''; | |
31 | }; | |
32 | cld3 = attrs: { | |
33 | buildInputs = [ protobuf protobufc pkgconfig ]; | |
34 | }; | |
35 | idn-ruby = attrs: { | |
36 | buildInputs = [ libidn ]; | |
37 | }; | |
38 | rpam2 = attrs: { | |
39 | buildInputs = [ pam ]; | |
40 | }; | |
41 | }; | |
42 | }; | |
43 | yarnModules = let | |
44 | packagejson = runCommand "package.json" { buildInputs = [ jq ]; } '' | |
45 | cat ${info.src}/package.json | jq -r '.version = "${info.version}"' > $out | |
46 | ''; | |
47 | in | |
48 | mylibs.yarn2nixPackage.mkYarnModules rec { | |
49 | name = "mastodon-yarn"; | |
50 | pname = name; | |
51 | version = info.version; | |
52 | packageJSON = packagejson; | |
53 | yarnLock = "${info.src}/yarn.lock"; | |
54 | yarnNix = ./yarn-packages.nix; | |
55 | pkgConfig = { | |
56 | all = { | |
57 | buildInputs = [ mylibs.yarn2nixPackage.src ]; | |
58 | }; | |
59 | uws = { | |
60 | postInstall = '' | |
61 | npx node-gyp rebuild > build_log.txt 2>&1 || true | |
62 | ''; | |
63 | }; | |
64 | }; | |
65 | }; | |
66 | mastodon_with_yarn = stdenv.mkDerivation (info // rec { | |
67 | installPhase = '' | |
68 | cp -a . $out | |
69 | cp -a ${yarnModules}/node_modules $out | |
70 | ''; | |
71 | buildInputs = [ yarnModules ]; | |
72 | }); | |
73 | in | |
74 | stdenv.mkDerivation { | |
75 | name = "mastodon"; | |
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; }; | |
94 | } |