]> git.immae.eu Git - perso/Immae/Config/Nix.git/blobdiff - virtual/modules/websites/tools/mastodon/mastodon.nix
Start purifying mastodon: bundler
[perso/Immae/Config/Nix.git] / virtual / modules / websites / tools / mastodon / mastodon.nix
index 463de1cce883f7215816cb262fe02e332df0ac76..c2c180727fd12f23322ff1b13b436f7cecc9425b 100644 (file)
@@ -1,25 +1,35 @@
-{ env, fetchedGithub, stdenv, writeText, pkgs, cacert }:
+{ env, ruby_2_5, bundlerEnv, defaultGemConfig, fetchedGithub, stdenv, writeText, pkgs, cacert }:
 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 ];
+      };
+    };
+  };
   mastodon = stdenv.mkDerivation (fetchedGithub ./mastodon.json // rec {
+    __noChroot = true;
     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
+      patchShebangs node_modules
     '';
     installPhase = ''
       cp -a . $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
-    ];
+    propagatedBuildInputs = [ gems pkgs.yarn pkgs.python2 pkgs.nodejs ];
   });
   config = writeText "mastodon_environment" ''
     REDIS_HOST=localhost
@@ -73,19 +83,15 @@ let
         cp -a $mastodon $out
         cd $out
         chmod u+rwX . node_modules public
-        RAILS_ENV=production bundle exec rails assets:precompile
+        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 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";
   }