X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=virtual%2Fmodules%2Fwebsites%2Ftools%2Fmastodon%2Fmastodon.nix;h=770aa2cb5b584cf3157ae92a7116206a4a032c85;hb=6f4574e7b57043340a2a520c4bbeb17dde72e0ea;hp=463de1cce883f7215816cb262fe02e332df0ac76;hpb=9d90e7e281e8f4cf9371c17c812a1ac9c08aa66d;p=perso%2FImmae%2FConfig%2FNix.git diff --git a/virtual/modules/websites/tools/mastodon/mastodon.nix b/virtual/modules/websites/tools/mastodon/mastodon.nix index 463de1c..770aa2c 100644 --- a/virtual/modules/websites/tools/mastodon/mastodon.nix +++ b/virtual/modules/websites/tools/mastodon/mastodon.nix @@ -1,35 +1,77 @@ -{ 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 @@ -72,20 +114,16 @@ let 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"; }