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