···
52
+
WorkingDirectory = cfg.package;
# State directory and mode
StateDirectory = "mastodon";
StateDirectoryMode = "0750";
···
$sudo ${cfg.package}/bin/tootctl "$@"
115
+
sidekiqUnits = lib.attrsets.mapAttrs' (name: processCfg:
116
+
lib.nameValuePair "mastodon-sidekiq-${name}" (let
117
+
jobClassArgs = toString (builtins.map (c: "-q ${c}") processCfg.jobClasses);
118
+
jobClassLabel = toString ([""] ++ processCfg.jobClasses);
119
+
threads = toString (if processCfg.threads == null then cfg.sidekiqThreads else processCfg.threads);
121
+
after = [ "network.target" "mastodon-init-dirs.service" ]
122
+
++ lib.optional databaseActuallyCreateLocally "postgresql.service"
123
+
++ lib.optional cfg.automaticMigrations "mastodon-init-db.service";
124
+
requires = [ "mastodon-init-dirs.service" ]
125
+
++ lib.optional databaseActuallyCreateLocally "postgresql.service"
126
+
++ lib.optional cfg.automaticMigrations "mastodon-init-db.service";
127
+
description = "Mastodon sidekiq${jobClassLabel}";
128
+
wantedBy = [ "mastodon.target" ];
129
+
environment = env // {
130
+
PORT = toString(cfg.sidekiqPort);
134
+
ExecStart = "${cfg.package}/bin/sidekiq ${jobClassArgs} -c ${threads} -r ${cfg.package}";
135
+
Restart = "always";
137
+
EnvironmentFile = [ "/var/lib/mastodon/.secrets_env" ] ++ cfg.extraEnvFiles;
138
+
WorkingDirectory = cfg.package;
139
+
# System Call Filtering
140
+
SystemCallFilter = [ ("~" + lib.concatStringsSep " " systemCallsList) "@chown" "pipe" "pipe2" ];
142
+
path = with pkgs; [ file imagemagick ffmpeg ];
144
+
) cfg.sidekiqProcesses;
···
sidekiqThreads = lib.mkOption {
199
-
description = lib.mdDoc "Worker threads used by the mastodon-sidekiq service.";
233
+
description = lib.mdDoc "Worker threads used by the mastodon-sidekiq-all service. If `sidekiqProcesses` is configured and any processes specify null `threads`, this value is used.";
238
+
sidekiqProcesses = lib.mkOption {
239
+
description = lib.mdDoc "How many Sidekiq processes should be used to handle background jobs, and which job classes they handle. *Read the [upstream documentation](https://docs.joinmastodon.org/admin/scaling/#sidekiq) before configuring this!*";
240
+
type = with lib.types; attrsOf (submodule {
242
+
jobClasses = lib.mkOption {
243
+
type = listOf (enum [ "default" "push" "pull" "mailers" "scheduler" "ingress" ]);
244
+
description = lib.mdDoc "If not empty, which job classes should be executed by this process. *Only one process should handle the 'scheduler' class. If left empty, this process will handle the 'scheduler' class.*";
246
+
threads = lib.mkOption {
248
+
description = lib.mdDoc "Number of threads this process should use for executing jobs. If null, the configured `sidekiqThreads` are used.";
264
+
jobClasses = [ "ingress" ];
268
+
jobClasses = [ "default" ];
272
+
jobClasses = [ "push" "pull" ];
vapidPublicKeyFile = lib.mkOption {
description = lib.mdDoc ''
Path to file containing the public key used for Web Push
···
485
-
config = lib.mkIf cfg.enable {
559
+
config = lib.mkIf cfg.enable (lib.mkMerge [{
assertion = databaseActuallyCreateLocally -> (cfg.user == cfg.database.user);
···
environment.systemPackages = [ mastodonTootctl ];
594
+
systemd.targets.mastodon = {
595
+
description = "Target for all Mastodon services";
596
+
wantedBy = [ "multi-user.target" ];
597
+
after = [ "network.target" ];
systemd.services.mastodon-init-dirs = {
···
554
-
WorkingDirectory = cfg.package;
634
+
SyslogIdentifier = "mastodon-init-dirs";
SystemCallFilter = [ ("~" + lib.concatStringsSep " " (systemCallsList ++ [ "@resources" ])) "@chown" "pipe" "pipe2" ];
···
requires = [ "mastodon-init-dirs.service" ]
++ lib.optional databaseActuallyCreateLocally "postgresql.service"
++ lib.optional cfg.automaticMigrations "mastodon-init-db.service";
612
-
wantedBy = [ "multi-user.target" ];
692
+
wantedBy = [ "mastodon.target" ];
description = "Mastodon streaming";
environment = env // (if cfg.enableUnixSocket
then { SOCKET = "/run/mastodon-streaming/streaming.socket"; }
···
requires = [ "mastodon-init-dirs.service" ]
++ lib.optional databaseActuallyCreateLocally "postgresql.service"
++ lib.optional cfg.automaticMigrations "mastodon-init-db.service";
639
-
wantedBy = [ "multi-user.target" ];
719
+
wantedBy = [ "mastodon.target" ];
description = "Mastodon web";
environment = env // (if cfg.enableUnixSocket
then { SOCKET = "/run/mastodon-web/web.socket"; }
···
path = with pkgs; [ file imagemagick ffmpeg ];
660
-
systemd.services.mastodon-sidekiq = {
661
-
after = [ "network.target" "mastodon-init-dirs.service" ]
662
-
++ lib.optional databaseActuallyCreateLocally "postgresql.service"
663
-
++ lib.optional cfg.automaticMigrations "mastodon-init-db.service";
664
-
requires = [ "mastodon-init-dirs.service" ]
665
-
++ lib.optional databaseActuallyCreateLocally "postgresql.service"
666
-
++ lib.optional cfg.automaticMigrations "mastodon-init-db.service";
667
-
wantedBy = [ "multi-user.target" ];
668
-
description = "Mastodon sidekiq";
669
-
environment = env // {
670
-
PORT = toString(cfg.sidekiqPort);
671
-
DB_POOL = toString cfg.sidekiqThreads;
674
-
ExecStart = "${cfg.package}/bin/sidekiq -c ${toString cfg.sidekiqThreads} -r ${cfg.package}";
675
-
Restart = "always";
677
-
EnvironmentFile = [ "/var/lib/mastodon/.secrets_env" ] ++ cfg.extraEnvFiles;
678
-
WorkingDirectory = cfg.package;
679
-
# System Call Filtering
680
-
SystemCallFilter = [ ("~" + lib.concatStringsSep " " systemCallsList) "@chown" "pipe" "pipe2" ];
682
-
path = with pkgs; [ file imagemagick ffmpeg ];
systemd.services.mastodon-media-auto-remove = lib.mkIf cfg.mediaAutoRemove.enable {
description = "Mastodon media auto remove";
···
users.groups.${cfg.group}.members = lib.optional cfg.configureNginx config.services.nginx.user;
816
+
{ systemd.services = sidekiqUnits; }
meta.maintainers = with lib.maintainers; [ happy-river erictapen ];