]> git.immae.eu Git - perso/Immae/Config/Nix.git/blobdiff - virtual/modules/websites/tools/mastodon/default.nix
Start purifying mastodon: bundler
[perso/Immae/Config/Nix.git] / virtual / modules / websites / tools / mastodon / default.nix
index 1549ca95f0ac8350908b324b6974b47bda54347a..f1a207feb97554d305ca2d8e7fc2871705a3955d 100644 (file)
@@ -1,7 +1,8 @@
-{ lib, pkgs, config, mylibs, ... }:
+{ lib, pkgs, config, myconfig, mylibs, ... }:
 let
   mastodon = pkgs.callPackage ./mastodon.nix {
-    inherit (mylibs) fetchedGithub checkEnv;
+    inherit (mylibs) fetchedGithub;
+    env = myconfig.env.tools.mastodon;
   };
 
   cfg = config.services.myWebsites.tools.mastodon;
@@ -11,8 +12,6 @@ in {
   };
 
   config = lib.mkIf cfg.enable {
-    # FIXME: Can we use dynamic users from systemd?
-    # nixos/modules/misc/ids.nix
     ids.uids.mastodon = 399;
     ids.gids.mastodon = 399;
 
@@ -21,7 +20,7 @@ in {
       uid = config.ids.uids.mastodon;
       group = "mastodon";
       description = "Mastodon user";
-      home = "${mastodon.railsRoot}";
+      home = mastodon.railsRoot;
       useDefaultShell = true;
     };
 
@@ -71,16 +70,18 @@ in {
       after = [ "network.target" ];
 
       environment.RAILS_ENV = "production";
+      environment.BUNDLE_PATH = "${mastodon.gems}/lib/ruby/gems/2.5.0";
+      environment.BUNDLE_GEMFILE = "${mastodon.gems.confFiles}/Gemfile";
       environment.SOCKET = mastodon.railsSocket;
 
-      path = [ pkgs.bundler ];
+      path = [ mastodon.gems mastodon.gems.ruby pkgs.file ];
 
       preStart = ''
-        bundle exec rails db:migrate
+        ./bin/bundle exec rails db:migrate
       '';
 
       script = ''
-        exec bundle exec puma -C config/puma.rb
+        exec ./bin/bundle exec puma -C config/puma.rb
       '';
 
       serviceConfig = {
@@ -88,7 +89,7 @@ in {
         EnvironmentFile = mastodon.config;
         PrivateTmp = true;
         Restart = "always";
-        TimeoutSec = 15;
+        TimeoutSec = 60;
         Type = "simple";
         WorkingDirectory = mastodon.railsRoot;
       };
@@ -102,12 +103,14 @@ in {
       after = [ "network.target" "mastodon-web.service" ];
 
       environment.RAILS_ENV="production";
+      environment.BUNDLE_PATH = "${mastodon.gems}/${mastodon.gems.ruby.gemPath}";
+      environment.BUNDLE_GEMFILE = "${mastodon.gems.confFiles}/Gemfile";
       environment.DB_POOL="5";
 
-      path = [ pkgs.bundler ];
+      path = [ mastodon.gems mastodon.gems.ruby pkgs.imagemagick pkgs.ffmpeg pkgs.file ];
 
       script = ''
-        exec bundle exec sidekiq -c 5 -q default -q mailers -q pull -q push
+        exec ./bin/bundle exec sidekiq -c 5 -q default -q mailers -q pull -q push
       '';
 
       serviceConfig = {
@@ -123,18 +126,16 @@ in {
       unitConfig.RequiresMountsFor = mastodon.varDir;
     };
 
-    # FIXME: initial sync
     system.activationScripts.mastodon = {
       deps = [ "users" ];
       text = ''
       install -m 0755 -o mastodon -g mastodon -d ${mastodon.socketsDir}
-      install -m 0755 -o mastodon -g mastodon -d ${mastodon.varDir}
+      install -m 0755 -o mastodon -g mastodon -d ${mastodon.varDir} ${mastodon.varDir}/tmp/cache
       '';
     };
 
     services.myWebsites.tools.modules = [
       "headers" "proxy" "proxy_wstunnel" "proxy_http" "proxy_balancer"
-      # FIXME: probably only one balancer method is needed:
       "lbmethod_byrequests" "lbmethod_bytraffic" "lbmethod_bybusyness" "lbmethod_heartbeat"
     ];
     security.acme.certs."eldiron".extraDomains."mastodon.immae.eu" = null;