1 { env, ruby_2_5, bundlerEnv, defaultGemConfig, fetchedGithub, stdenv, writeText, pkgs }:
3 varDir = "/var/lib/mastodon_immae";
4 socketsDir = "/run/mastodon";
9 gemdir = (fetchedGithub ./mastodon.json).src;
10 groups = [ "default" "production" "test" "development" ];
11 gemConfig = defaultGemConfig // {
13 buildInputs = with pkgs; [ protobuf protobufc pkgconfig ];
16 buildInputs = with pkgs; [ libidn ];
19 buildInputs = with pkgs; [ pam ];
24 info = fetchedGithub ./mastodon.json;
26 pkgs.yarn2nix.mkYarnModules {
27 name = "mastodon-yarn-modules";
28 packageJSON = "${info.src}/package.json";
29 yarnLock = "${info.src}/yarn.lock";
30 yarnNix = ./yarn-packages.nix;
34 node-gyp rebuild > build_log.txt 2>&1 || true
36 buildInputs = with pkgs; [ nodePackages.node-gyp ];
40 node-pre-gyp install --fallback-to-build
42 buildInputs = with pkgs; [ nodePackages.node-pre-gyp ];
45 buildInputs = with pkgs; [ libsass python ];
47 nodeHeaders = pkgs.fetchurl {
48 url = "https://nodejs.org/download/release/v${pkgs.nodejs.version}/node-v${pkgs.nodejs.version}-headers.tar.gz";
49 sha256 = "12zzsf8my43b8qnlacp871ih5vqafl2vlpqp51xp6h3gckn2frwy";
53 node scripts/build.js --tarball=${nodeHeaders}
58 mastodon = stdenv.mkDerivation (fetchedGithub ./mastodon.json // rec {
61 cp -a ${yarnModules}/node_modules $out
63 buildInputs = [ yarnModules gems ];
65 config = writeText "mastodon_environment" ''
66 REDIS_HOST=${env.redis.host}
67 REDIS_PORT=${env.redis.port}
68 REDIS_DB=${env.redis.db}
69 DB_HOST=${env.postgresql.socket}
70 DB_USER=${env.postgresql.user}
71 DB_NAME=${env.postgresql.database}
72 DB_PASS=${env.postgresql.password}
73 DB_PORT=${env.postgresql.port}
75 LOCAL_DOMAIN=mastodon.immae.eu
77 ALTERNATE_DOMAINS=immae.eu
79 PAPERCLIP_SECRET=${env.paperclip_secret}
80 SECRET_KEY_BASE=${env.secret_key_base}
81 OTP_SECRET=${env.otp_secret}
83 VAPID_PRIVATE_KEY=${env.vapid.private}
84 VAPID_PUBLIC_KEY=${env.vapid.public}
86 SMTP_DELIVERY_METHOD=sendmail
87 SMTP_FROM_ADDRESS=notifications@mastodon.immae.eu
88 SENDMAIL_LOCATION="/run/wrappers/bin/sendmail"
89 PAPERCLIP_ROOT_PATH=${varDir}
91 STREAMING_CLUSTER_NUM=1
95 # LDAP authentication (optional)
97 LDAP_HOST=ldap.immae.eu
99 LDAP_METHOD=simple_tls
100 LDAP_BASE="dc=immae,dc=eu"
101 LDAP_BIND_DN="cn=mastodon,ou=services,dc=immae,dc=eu"
102 LDAP_PASSWORD="${env.ldap.password}"
104 LDAP_SEARCH_FILTER="(&(%{uid}=%{email})(memberOf=cn=users,cn=mastodon,ou=services,dc=immae,dc=eu))"
107 railsRoot = stdenv.mkDerivation {
108 name = "mastodon_immae";
109 inherit config mastodon;
110 builder = writeText "build_mastodon_immae" ''
118 chmod -R u+rwX config/
119 sed -i -e 's@^end$@ config.action_mailer.sendmail_settings = { location: ENV.fetch("SENDMAIL_LOCATION", "/usr/sbin/sendmail") }\nend@' config/environments/production.rb
120 RAILS_ENV=production ${gems}/bin/rails assets:precompile
122 ln -sf ../../../../../../../${varDir}/tmp/cache tmp
124 buildInputs = [ gems gems.ruby pkgs.nodejs pkgs.yarn ];
128 inherit railsRoot config varDir socketsDir gems;
129 nodeSocket = "${socketsDir}/live_immae_node.sock";
130 railsSocket = "${socketsDir}/live_immae_puma.sock";