]>
Commit | Line | Data |
---|---|---|
f27f4c9d | 1 | { env, ruby_2_5, bundlerEnv, defaultGemConfig, fetchedGithub, stdenv, writeText, pkgs }: |
35a397cd IB |
2 | let |
3 | varDir = "/var/lib/mastodon_immae"; | |
4 | socketsDir = "/run/mastodon"; | |
2ff7e086 IB |
5 | gems = bundlerEnv { |
6 | name = "mastodon-env"; | |
a4993193 IB |
7 | # https://git.immae.eu/mantisbt/view.php?id=131 |
8 | ruby = ruby_2_5.overrideAttrs(old: { | |
9 | postInstall = builtins.replaceStrings [" --destdir $GEM_HOME"] [""] old.postInstall; | |
10 | }); | |
2ff7e086 IB |
11 | gemset = ./gemset.nix; |
12 | gemdir = (fetchedGithub ./mastodon.json).src; | |
13 | groups = [ "default" "production" "test" "development" ]; | |
14 | gemConfig = defaultGemConfig // { | |
15 | cld3 = attrs: { | |
16 | buildInputs = with pkgs; [ protobuf protobufc pkgconfig ]; | |
17 | }; | |
18 | idn-ruby = attrs: { | |
19 | buildInputs = with pkgs; [ libidn ]; | |
20 | }; | |
21 | rpam2 = attrs: { | |
22 | buildInputs = with pkgs; [ pam ]; | |
23 | }; | |
24 | }; | |
25 | }; | |
f27f4c9d IB |
26 | yarnModules = let |
27 | info = fetchedGithub ./mastodon.json; | |
28 | in | |
29 | pkgs.yarn2nix.mkYarnModules { | |
30 | name = "mastodon-yarn-modules"; | |
31 | packageJSON = "${info.src}/package.json"; | |
32 | yarnLock = "${info.src}/yarn.lock"; | |
33 | yarnNix = ./yarn-packages.nix; | |
34 | pkgConfig = { | |
35 | uws = { | |
36 | postInstall = '' | |
a4993193 | 37 | npx node-gyp rebuild > build_log.txt 2>&1 || true |
f27f4c9d | 38 | ''; |
f27f4c9d IB |
39 | }; |
40 | node-zopfli = { | |
41 | postInstall = '' | |
a4993193 | 42 | npx node-pre-gyp install --fallback-to-build |
f27f4c9d | 43 | ''; |
f27f4c9d IB |
44 | }; |
45 | node-sass = { | |
24a7da33 | 46 | buildInputs = with pkgs; [ libsass python ]; |
f27f4c9d IB |
47 | postInstall = let |
48 | nodeHeaders = pkgs.fetchurl { | |
49 | url = "https://nodejs.org/download/release/v${pkgs.nodejs.version}/node-v${pkgs.nodejs.version}-headers.tar.gz"; | |
a4993193 | 50 | sha256 = "16f20ya3ys6w5w6y6l4536f7jrgk4gz46bf71w1r1xxb26a54m32"; |
f27f4c9d IB |
51 | }; |
52 | in | |
53 | '' | |
f27f4c9d IB |
54 | node scripts/build.js --tarball=${nodeHeaders} |
55 | ''; | |
56 | }; | |
57 | }; | |
58 | }; | |
35a397cd | 59 | mastodon = stdenv.mkDerivation (fetchedGithub ./mastodon.json // rec { |
35a397cd IB |
60 | installPhase = '' |
61 | cp -a . $out | |
f27f4c9d | 62 | cp -a ${yarnModules}/node_modules $out |
35a397cd | 63 | ''; |
f27f4c9d | 64 | buildInputs = [ yarnModules gems ]; |
35a397cd | 65 | }); |
9d90e7e2 | 66 | config = writeText "mastodon_environment" '' |
b0781dbc IB |
67 | REDIS_HOST=${env.redis.host} |
68 | REDIS_PORT=${env.redis.port} | |
69 | REDIS_DB=${env.redis.db} | |
6f4574e7 IB |
70 | DB_HOST=${env.postgresql.socket} |
71 | DB_USER=${env.postgresql.user} | |
72 | DB_NAME=${env.postgresql.database} | |
9d90e7e2 | 73 | DB_PASS=${env.postgresql.password} |
6f4574e7 | 74 | DB_PORT=${env.postgresql.port} |
35a397cd IB |
75 | |
76 | LOCAL_DOMAIN=mastodon.immae.eu | |
77 | LOCAL_HTTPS=true | |
78 | ALTERNATE_DOMAINS=immae.eu | |
79 | ||
9d90e7e2 IB |
80 | PAPERCLIP_SECRET=${env.paperclip_secret} |
81 | SECRET_KEY_BASE=${env.secret_key_base} | |
82 | OTP_SECRET=${env.otp_secret} | |
35a397cd | 83 | |
9d90e7e2 IB |
84 | VAPID_PRIVATE_KEY=${env.vapid.private} |
85 | VAPID_PUBLIC_KEY=${env.vapid.public} | |
35a397cd | 86 | |
591ebd87 | 87 | SMTP_DELIVERY_METHOD=sendmail |
35a397cd | 88 | SMTP_FROM_ADDRESS=notifications@mastodon.immae.eu |
591ebd87 | 89 | SENDMAIL_LOCATION="/run/wrappers/bin/sendmail" |
35a397cd IB |
90 | PAPERCLIP_ROOT_PATH=${varDir} |
91 | ||
92 | STREAMING_CLUSTER_NUM=1 | |
93 | ||
46228a29 IB |
94 | RAILS_LOG_LEVEL=warn |
95 | ||
35a397cd IB |
96 | # LDAP authentication (optional) |
97 | LDAP_ENABLED=true | |
98 | LDAP_HOST=ldap.immae.eu | |
99 | LDAP_PORT=636 | |
100 | LDAP_METHOD=simple_tls | |
101 | LDAP_BASE="dc=immae,dc=eu" | |
102 | LDAP_BIND_DN="cn=mastodon,ou=services,dc=immae,dc=eu" | |
9d90e7e2 | 103 | LDAP_PASSWORD="${env.ldap.password}" |
35a397cd IB |
104 | LDAP_UID="uid" |
105 | LDAP_SEARCH_FILTER="(&(%{uid}=%{email})(memberOf=cn=users,cn=mastodon,ou=services,dc=immae,dc=eu))" | |
106 | ''; | |
107 | ||
108 | railsRoot = stdenv.mkDerivation { | |
109 | name = "mastodon_immae"; | |
110 | inherit config mastodon; | |
111 | builder = writeText "build_mastodon_immae" '' | |
112 | source $stdenv/setup | |
113 | set -a | |
114 | source $config | |
115 | set +a | |
116 | cp -a $mastodon $out | |
117 | cd $out | |
f27f4c9d | 118 | chmod u+rwX . public |
591ebd87 IB |
119 | chmod -R u+rwX config/ |
120 | sed -i -e 's@^end$@ config.action_mailer.sendmail_settings = { location: ENV.fetch("SENDMAIL_LOCATION", "/usr/sbin/sendmail") }\nend@' config/environments/production.rb | |
2ff7e086 IB |
121 | RAILS_ENV=production ${gems}/bin/rails assets:precompile |
122 | rm -rf tmp/cache | |
3c8d7f87 | 123 | ln -sf ${varDir}/tmp/cache tmp |
35a397cd | 124 | ''; |
f27f4c9d | 125 | buildInputs = [ gems gems.ruby pkgs.nodejs pkgs.yarn ]; |
35a397cd IB |
126 | }; |
127 | in | |
128 | { | |
2ff7e086 | 129 | inherit railsRoot config varDir socketsDir gems; |
35a397cd IB |
130 | nodeSocket = "${socketsDir}/live_immae_node.sock"; |
131 | railsSocket = "${socketsDir}/live_immae_puma.sock"; | |
132 | } |