]>
Commit | Line | Data |
---|---|---|
7f6bd78f | 1 | { env, ruby_2_6, bundlerEnv, defaultGemConfig, yarn2nixPackage, 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"; | |
7f6bd78f | 7 | ruby = ruby_2_6; |
2ff7e086 IB |
8 | gemset = ./gemset.nix; |
9 | gemdir = (fetchedGithub ./mastodon.json).src; | |
10 | groups = [ "default" "production" "test" "development" ]; | |
11 | gemConfig = defaultGemConfig // { | |
7f6bd78f IB |
12 | redis-rack = attrs: { |
13 | preBuild = '' | |
14 | sed -i 's!s\.files.*!!' redis-rack.gemspec | |
15 | ''; | |
16 | }; | |
17 | tzinfo = attrs: { | |
18 | preBuild = '' | |
19 | sed -i 's!s\.files.*!!' tzinfo.gemspec | |
20 | ''; | |
21 | }; | |
2ff7e086 IB |
22 | cld3 = attrs: { |
23 | buildInputs = with pkgs; [ protobuf protobufc pkgconfig ]; | |
24 | }; | |
25 | idn-ruby = attrs: { | |
26 | buildInputs = with pkgs; [ libidn ]; | |
27 | }; | |
28 | rpam2 = attrs: { | |
29 | buildInputs = with pkgs; [ pam ]; | |
30 | }; | |
31 | }; | |
32 | }; | |
f27f4c9d IB |
33 | yarnModules = let |
34 | info = fetchedGithub ./mastodon.json; | |
7f6bd78f IB |
35 | packagejson = pkgs.runCommand "package.json" { buildInputs = [ pkgs.jq ]; } '' |
36 | cat ${info.src}/package.json | jq -r '.version = "${info.version}"' > $out | |
37 | ''; | |
f27f4c9d | 38 | in |
7f6bd78f IB |
39 | yarn2nixPackage.mkYarnModules rec { |
40 | name = "mastodon-yarn"; | |
41 | pname = name; | |
42 | version = info.version; | |
43 | packageJSON = packagejson; | |
f27f4c9d IB |
44 | yarnLock = "${info.src}/yarn.lock"; |
45 | yarnNix = ./yarn-packages.nix; | |
46 | pkgConfig = { | |
167b8165 IB |
47 | all = { |
48 | buildInputs = [ yarn2nixPackage.src ]; | |
49 | }; | |
f27f4c9d IB |
50 | uws = { |
51 | postInstall = '' | |
a4993193 | 52 | npx node-gyp rebuild > build_log.txt 2>&1 || true |
f27f4c9d | 53 | ''; |
f27f4c9d | 54 | }; |
f27f4c9d IB |
55 | }; |
56 | }; | |
35a397cd | 57 | mastodon = stdenv.mkDerivation (fetchedGithub ./mastodon.json // rec { |
35a397cd IB |
58 | installPhase = '' |
59 | cp -a . $out | |
f27f4c9d | 60 | cp -a ${yarnModules}/node_modules $out |
35a397cd | 61 | ''; |
7f6bd78f | 62 | buildInputs = [ yarnModules ]; |
35a397cd | 63 | }); |
32c84ff8 IB |
64 | keys.mastodon = { |
65 | dest = "webapps/tools-mastodon"; | |
50933a04 IB |
66 | user = "mastodon"; |
67 | group = "mastodon"; | |
68 | permissions = "0400"; | |
69 | text = '' | |
70 | REDIS_HOST=${env.redis.host} | |
71 | REDIS_PORT=${env.redis.port} | |
72 | REDIS_DB=${env.redis.db} | |
73 | DB_HOST=${env.postgresql.socket} | |
74 | DB_USER=${env.postgresql.user} | |
75 | DB_NAME=${env.postgresql.database} | |
76 | DB_PASS=${env.postgresql.password} | |
77 | DB_PORT=${env.postgresql.port} | |
35a397cd | 78 | |
50933a04 IB |
79 | LOCAL_DOMAIN=mastodon.immae.eu |
80 | LOCAL_HTTPS=true | |
81 | ALTERNATE_DOMAINS=immae.eu | |
35a397cd | 82 | |
50933a04 IB |
83 | PAPERCLIP_SECRET=${env.paperclip_secret} |
84 | SECRET_KEY_BASE=${env.secret_key_base} | |
85 | OTP_SECRET=${env.otp_secret} | |
35a397cd | 86 | |
50933a04 IB |
87 | VAPID_PRIVATE_KEY=${env.vapid.private} |
88 | VAPID_PUBLIC_KEY=${env.vapid.public} | |
35a397cd | 89 | |
50933a04 IB |
90 | SMTP_DELIVERY_METHOD=sendmail |
91 | SMTP_FROM_ADDRESS=mastodon@tools.immae.eu | |
92 | SENDMAIL_LOCATION="/run/wrappers/bin/sendmail" | |
93 | PAPERCLIP_ROOT_PATH=${varDir} | |
35a397cd | 94 | |
50933a04 | 95 | STREAMING_CLUSTER_NUM=1 |
35a397cd | 96 | |
50933a04 | 97 | RAILS_LOG_LEVEL=warn |
46228a29 | 98 | |
50933a04 IB |
99 | # LDAP authentication (optional) |
100 | LDAP_ENABLED=true | |
101 | LDAP_HOST=ldap.immae.eu | |
102 | LDAP_PORT=636 | |
103 | LDAP_METHOD=simple_tls | |
104 | LDAP_BASE="dc=immae,dc=eu" | |
105 | LDAP_BIND_DN="cn=mastodon,ou=services,dc=immae,dc=eu" | |
106 | LDAP_PASSWORD="${env.ldap.password}" | |
107 | LDAP_UID="uid" | |
108 | LDAP_SEARCH_FILTER="(&(%{uid}=%{email})(memberOf=cn=users,cn=mastodon,ou=services,dc=immae,dc=eu))" | |
35a397cd | 109 | ''; |
50933a04 | 110 | }; |
35a397cd IB |
111 | |
112 | railsRoot = stdenv.mkDerivation { | |
113 | name = "mastodon_immae"; | |
50933a04 | 114 | inherit mastodon; |
35a397cd IB |
115 | builder = writeText "build_mastodon_immae" '' |
116 | source $stdenv/setup | |
117 | set -a | |
508943b4 IB |
118 | SECRET_KEY_BASE=Dummy |
119 | OTP_SECRET=Dummy | |
35a397cd IB |
120 | set +a |
121 | cp -a $mastodon $out | |
122 | cd $out | |
f27f4c9d | 123 | chmod u+rwX . public |
591ebd87 IB |
124 | chmod -R u+rwX config/ |
125 | 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 |
126 | RAILS_ENV=production ${gems}/bin/rails assets:precompile |
127 | rm -rf tmp/cache | |
3c8d7f87 | 128 | ln -sf ${varDir}/tmp/cache tmp |
35a397cd | 129 | ''; |
f27f4c9d | 130 | buildInputs = [ gems gems.ruby pkgs.nodejs pkgs.yarn ]; |
35a397cd IB |
131 | }; |
132 | in | |
133 | { | |
32c84ff8 IB |
134 | inherit railsRoot varDir socketsDir gems; |
135 | keys = builtins.attrValues keys; | |
35a397cd IB |
136 | nodeSocket = "${socketsDir}/live_immae_node.sock"; |
137 | railsSocket = "${socketsDir}/live_immae_puma.sock"; | |
138 | } |