-{ env, fetchedGithub, stdenv, writeText, pkgs, cacert }:
+{ env, ruby_2_5, bundlerEnv, defaultGemConfig, fetchedGithub, stdenv, writeText, pkgs }:
let
varDir = "/var/lib/mastodon_immae";
socketsDir = "/run/mastodon";
+ gems = bundlerEnv {
+ name = "mastodon-env";
+ ruby = ruby_2_5;
+ gemset = ./gemset.nix;
+ gemdir = (fetchedGithub ./mastodon.json).src;
+ groups = [ "default" "production" "test" "development" ];
+ gemConfig = defaultGemConfig // {
+ 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;
+ in
+ pkgs.yarn2nix.mkYarnModules {
+ name = "mastodon-yarn-modules";
+ packageJSON = "${info.src}/package.json";
+ yarnLock = "${info.src}/yarn.lock";
+ yarnNix = ./yarn-packages.nix;
+ pkgConfig = {
+ uws = {
+ postInstall = ''
+ node-gyp rebuild > build_log.txt 2>&1 || true
+ '';
+ buildInputs = with pkgs; [ nodePackages.node-gyp ];
+ };
+ node-zopfli = {
+ postInstall = ''
+ node-pre-gyp install --fallback-to-build
+ '';
+ buildInputs = with pkgs; [ nodePackages.node-pre-gyp ];
+ };
+ node-sass = {
+ buildInputs = with pkgs; [ binutils libsass python ];
+ postInstall = let
+ nodeHeaders = pkgs.fetchurl {
+ url = "https://nodejs.org/download/release/v${pkgs.nodejs.version}/node-v${pkgs.nodejs.version}-headers.tar.gz";
+ sha256 = "12zzsf8my43b8qnlacp871ih5vqafl2vlpqp51xp6h3gckn2frwy";
+ };
+ in
+ ''
+ export AR=${pkgs.binutils.bintools}/bin/ar
+ node scripts/build.js --tarball=${nodeHeaders}
+ '';
+ };
+ };
+ };
mastodon = stdenv.mkDerivation (fetchedGithub ./mastodon.json // rec {
- buildPhase = ''
- export GIT_SSL_CAINFO=${cacert}/etc/ssl/certs/ca-bundle.crt
- export SSL_CERT_FILE=${cacert}/etc/ssl/certs/ca-bundle.crt
-
- bundle install --deployment --without development test
- yarn install --pure-lockfile
- '';
installPhase = ''
cp -a . $out
+ cp -a ${yarnModules}/node_modules $out
'';
- propagatedBuildInputs = with pkgs; [
- zlib icu libchardet git bundler yarn
- protobuf protobufc libidn libpqxx nodejs
- imagemagick ffmpeg libxml2 libxslt pkgconfig
- autoconf bison libyaml readline ncurses libffi gdbm
- jemalloc which postgresql python3 cacert
- ];
+ buildInputs = [ yarnModules gems ];
});
config = writeText "mastodon_environment" ''
- REDIS_HOST=localhost
- REDIS_PORT=6379
- REDIS_DB=13
- DB_HOST=/run/postgresql
- DB_USER=mastodon
- DB_NAME=mastodon
+ 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=5432
+ DB_PORT=${env.postgresql.port}
LOCAL_DOMAIN=mastodon.immae.eu
LOCAL_HTTPS=true
set +a
cp -a $mastodon $out
cd $out
- chmod u+rwX . node_modules public
- RAILS_ENV=production bundle exec rails assets:precompile
+ chmod u+rwX . public
+ RAILS_ENV=production ${gems}/bin/rails assets:precompile
+ rm -rf tmp/cache
+ ln -sf ../../../../../../../${varDir}/tmp/cache tmp
'';
- propagatedBuildInputs = with pkgs; [
- zlib icu libchardet git bundler yarn
- protobuf protobufc libidn libpqxx nodejs
- imagemagick ffmpeg libxml2 libxslt pkgconfig
- autoconf bison libyaml readline ncurses libffi gdbm
- jemalloc which postgresql python3 cacert
- ];
+ buildInputs = [ gems gems.ruby pkgs.nodejs pkgs.yarn ];
};
in
{
- inherit railsRoot config varDir socketsDir;
+ inherit railsRoot config varDir socketsDir gems;
nodeSocket = "${socketsDir}/live_immae_node.sock";
railsSocket = "${socketsDir}/live_immae_puma.sock";
}