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