- ids.uids.mastodon = env.user.uid;
- ids.gids.mastodon = env.user.gid;
-
- users.users.mastodon = {
- name = "mastodon";
- uid = config.ids.uids.mastodon;
- group = "mastodon";
- description = "Mastodon user";
- home = varDir;
- useDefaultShell = true;
- };
-
- users.groups.mastodon.gid = config.ids.gids.mastodon;
-
- systemd.services.mastodon-streaming = {
- description = "Mastodon Streaming";
- wantedBy = [ "multi-user.target" ];
- after = [ "network.target" "mastodon-web.service" ];
-
- environment.NODE_ENV = "production";
- environment.SOCKET = nodeSocket;
-
- path = [ pkgs.nodejs pkgs.bashInteractive ];
-
- script = ''
- exec npm run start
- '';
-
- postStart = ''
- while [ ! -S $SOCKET ]; do
- sleep 0.5
- done
- chmod a+w $SOCKET
- '';
-
- postStop = ''
- rm $SOCKET
- '';
-
- serviceConfig = {
- User = "mastodon";
- EnvironmentFile = "/var/secrets/webapps/tools-mastodon";
- PrivateTmp = true;
- Restart = "always";
- TimeoutSec = 15;
- Type = "simple";
- WorkingDirectory = mastodon;
- };
-
- unitConfig.RequiresMountsFor = varDir;
- };
-
- systemd.services.mastodon-web = {
- description = "Mastodon Web app";
- wantedBy = [ "multi-user.target" ];
- after = [ "network.target" ];
-
- environment.RAILS_ENV = "production";
- environment.BUNDLE_PATH = "${mastodon.gems}/${mastodon.gems.ruby.gemPath}";
- environment.BUNDLE_GEMFILE = "${mastodon.gems.confFiles}/Gemfile";
- environment.SOCKET = railsSocket;
-
- path = [ mastodon.gems mastodon.gems.ruby pkgs.file ];
-
- preStart = ''
- ./bin/bundle exec rails db:migrate
- '';
-
- script = ''
- exec ./bin/bundle exec puma -C config/puma.rb
- '';
-
- serviceConfig = {
- User = "mastodon";
- EnvironmentFile = "/var/secrets/webapps/tools-mastodon";
- PrivateTmp = true;
- Restart = "always";
- TimeoutSec = 60;
- Type = "simple";
- WorkingDirectory = mastodon;
- };
-
- unitConfig.RequiresMountsFor = varDir;
- };
-
- systemd.services.mastodon-sidekiq = {
- description = "Mastodon Sidekiq";
- wantedBy = [ "multi-user.target" ];
- 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 = [ mastodon.gems mastodon.gems.ruby pkgs.imagemagick pkgs.ffmpeg pkgs.file ];
-
- script = ''
- exec ./bin/bundle exec sidekiq -c 5 -q default -q mailers -q pull -q push
- '';
-
- serviceConfig = {
- User = "mastodon";
- EnvironmentFile = "/var/secrets/webapps/tools-mastodon";
- PrivateTmp = true;
- Restart = "always";
- TimeoutSec = 15;
- Type = "simple";
- WorkingDirectory = mastodon;
- };
-
- unitConfig.RequiresMountsFor = varDir;
- };
-
- system.activationScripts.mastodon = {
- deps = [ "users" ];
- text = ''
- install -m 0755 -o mastodon -g mastodon -d ${socketsDir}
- install -m 0755 -o mastodon -g mastodon -d ${varDir} ${varDir}/tmp/cache
- '';