X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=virtual%2Fmodules%2Fwebsites%2Ftools%2Fmastodon%2Fmastodon.nix;h=770aa2cb5b584cf3157ae92a7116206a4a032c85;hb=6f4574e7b57043340a2a520c4bbeb17dde72e0ea;hp=9457a13a08e205da9ca79fa2e922708df536c759;hpb=d65bf723f3f4548228c24337483286f6c79799cf;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 9457a13..770aa2c 100644 --- a/virtual/modules/websites/tools/mastodon/mastodon.nix +++ b/virtual/modules/websites/tools/mastodon/mastodon.nix @@ -1,56 +1,88 @@ -{ checkEnv, fetchedGithub, stdenv, writeText, pkgs, cacert }: +{ env, ruby_2_5, bundlerEnv, defaultGemConfig, fetchedGithub, stdenv, writeText, pkgs }: let varDir = "/var/lib/mastodon_immae"; socketsDir = "/run/mastodon"; - # FIXME: use gemsets and nodejs equivalent + 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 = - assert checkEnv "NIXOPS_MASTODON_DB_PASS"; - assert checkEnv "NIXOPS_MASTODON_PAPERCLIP_SECRET"; - assert checkEnv "NIXOPS_MASTODON_SECRET_KEY_BASE"; - assert checkEnv "NIXOPS_MASTODON_OTP_SECRET"; - assert checkEnv "NIXOPS_MASTODON_VAPID_PRIVATE_KEY"; - assert checkEnv "NIXOPS_MASTODON_VAPID_PUBLIC_KEY"; - assert checkEnv "NIXOPS_MASTODON_OTP_SECRET"; - assert checkEnv "NIXOPS_MASTODON_LDAP_PASSWORD"; - writeText "mastodon_environment" '' - REDIS_HOST=localhost - REDIS_PORT=6379 - REDIS_DB=13 - DB_HOST=/run/postgresql - DB_USER=mastodon - DB_NAME=mastodon - DB_PASS=${builtins.getEnv "NIXOPS_MASTODON_DB_PASS"} - DB_PORT=5432 + config = writeText "mastodon_environment" '' + 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=${builtins.getEnv "NIXOPS_MASTODON_PAPERCLIP_SECRET"} - SECRET_KEY_BASE=${builtins.getEnv "NIXOPS_MASTODON_SECRET_KEY_BASE"} - OTP_SECRET=${builtins.getEnv "NIXOPS_MASTODON_OTP_SECRET"} + PAPERCLIP_SECRET=${env.paperclip_secret} + SECRET_KEY_BASE=${env.secret_key_base} + OTP_SECRET=${env.otp_secret} - VAPID_PRIVATE_KEY=${builtins.getEnv "NIXOPS_MASTODON_VAPID_PRIVATE_KEY"} - VAPID_PUBLIC_KEY=${builtins.getEnv "NIXOPS_MASTODON_VAPID_PUBLIC_KEY"} + VAPID_PRIVATE_KEY=${env.vapid.private} + VAPID_PUBLIC_KEY=${env.vapid.public} SMTP_SERVER=mail.immae.eu SMTP_PORT=587 @@ -67,7 +99,7 @@ let LDAP_METHOD=simple_tls LDAP_BASE="dc=immae,dc=eu" LDAP_BIND_DN="cn=mastodon,ou=services,dc=immae,dc=eu" - LDAP_PASSWORD="${builtins.getEnv "NIXOPS_MASTODON_LDAP_PASSWORD"}" + LDAP_PASSWORD="${env.ldap.password}" LDAP_UID="uid" LDAP_SEARCH_FILTER="(&(%{uid}=%{email})(memberOf=cn=users,cn=mastodon,ou=services,dc=immae,dc=eu))" ''; @@ -82,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"; }