2020-11-08 14:05:37 +00:00
|
|
|
{ config, options, lib, pkgs, stdenv, ... }:
|
|
|
|
let
|
|
|
|
cfg = config.services.pleroma;
|
|
|
|
in {
|
|
|
|
options = {
|
|
|
|
services.pleroma = with lib; {
|
2022-08-28 19:18:44 +00:00
|
|
|
enable = mkEnableOption (lib.mdDoc "pleroma");
|
2020-11-08 14:05:37 +00:00
|
|
|
|
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
2022-05-06 10:38:28 +00:00
|
|
|
default = pkgs.pleroma;
|
2021-10-03 16:06:03 +00:00
|
|
|
defaultText = literalExpression "pkgs.pleroma";
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "Pleroma package to use.";
|
2020-11-08 14:05:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
user = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "pleroma";
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "User account under which pleroma runs.";
|
2020-11-08 14:05:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
group = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "pleroma";
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "Group account under which pleroma runs.";
|
2020-11-08 14:05:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
stateDir = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "/var/lib/pleroma";
|
|
|
|
readOnly = true;
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "Directory where the pleroma service will save the uploads and static files.";
|
2020-11-08 14:05:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
configs = mkOption {
|
|
|
|
type = with types; listOf str;
|
2022-08-03 20:46:41 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-11-08 14:05:37 +00:00
|
|
|
Pleroma public configuration.
|
|
|
|
|
|
|
|
This list gets appended from left to
|
|
|
|
right into /etc/pleroma/config.exs. Elixir evaluates its
|
|
|
|
configuration imperatively, meaning you can override a
|
|
|
|
setting by appending a new str to this NixOS option list.
|
|
|
|
|
2022-08-03 20:46:41 +00:00
|
|
|
*DO NOT STORE ANY PLEROMA SECRET
|
|
|
|
HERE*, use
|
|
|
|
[services.pleroma.secretConfigFile](#opt-services.pleroma.secretConfigFile)
|
2020-11-08 14:05:37 +00:00
|
|
|
instead.
|
|
|
|
|
|
|
|
This setting is going to be stored in a file part of
|
|
|
|
the Nix store. The Nix store being world-readable, it's not
|
|
|
|
the right place to store any secret
|
|
|
|
|
|
|
|
Have a look to Pleroma section in the NixOS manual for more
|
2022-12-18 00:31:14 +00:00
|
|
|
information.
|
2020-11-08 14:05:37 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
secretConfigFile = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "/var/lib/pleroma/secrets.exs";
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-11-08 14:05:37 +00:00
|
|
|
Path to the file containing your secret pleroma configuration.
|
|
|
|
|
2022-07-28 21:19:15 +00:00
|
|
|
*DO NOT POINT THIS OPTION TO THE NIX
|
|
|
|
STORE*, the store being world-readable, it'll
|
2020-11-08 14:05:37 +00:00
|
|
|
compromise all your secrets.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = lib.mkIf cfg.enable {
|
|
|
|
users = {
|
|
|
|
users."${cfg.user}" = {
|
|
|
|
description = "Pleroma user";
|
|
|
|
home = cfg.stateDir;
|
2021-08-08 12:00:00 +00:00
|
|
|
group = cfg.group;
|
2021-03-07 13:54:00 +00:00
|
|
|
isSystemUser = true;
|
2020-11-08 14:05:37 +00:00
|
|
|
};
|
|
|
|
groups."${cfg.group}" = {};
|
|
|
|
};
|
|
|
|
|
|
|
|
environment.systemPackages = [ cfg.package ];
|
|
|
|
|
|
|
|
environment.etc."/pleroma/config.exs".text = ''
|
|
|
|
${lib.concatMapStrings (x: "${x}") cfg.configs}
|
|
|
|
|
|
|
|
# The lau/tzdata library is trying to download the latest
|
|
|
|
# timezone database in the OTP priv directory by default.
|
|
|
|
# This directory being in the store, it's read-only.
|
|
|
|
# Setting that up to a more appropriate location.
|
|
|
|
config :tzdata, :data_dir, "/var/lib/pleroma/elixir_tzdata_data"
|
|
|
|
|
|
|
|
import_config "${cfg.secretConfigFile}"
|
|
|
|
'';
|
|
|
|
|
|
|
|
systemd.services.pleroma = {
|
|
|
|
description = "Pleroma social network";
|
|
|
|
after = [ "network-online.target" "postgresql.service" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
restartTriggers = [ config.environment.etc."/pleroma/config.exs".source ];
|
2022-05-06 10:38:28 +00:00
|
|
|
environment.RELEASE_COOKIE = "/var/lib/pleroma/.cookie";
|
2020-11-08 14:05:37 +00:00
|
|
|
serviceConfig = {
|
|
|
|
User = cfg.user;
|
|
|
|
Group = cfg.group;
|
|
|
|
Type = "exec";
|
|
|
|
WorkingDirectory = "~";
|
|
|
|
StateDirectory = "pleroma pleroma/static pleroma/uploads";
|
|
|
|
StateDirectoryMode = "700";
|
|
|
|
|
|
|
|
# Checking the conf file is there then running the database
|
|
|
|
# migration before each service start, just in case there are
|
|
|
|
# some pending ones.
|
|
|
|
#
|
|
|
|
# It's sub-optimal as we'll always run this, even if pleroma
|
|
|
|
# has not been updated. But the no-op process is pretty fast.
|
|
|
|
# Better be safe than sorry migration-wise.
|
|
|
|
ExecStartPre =
|
2021-12-07 16:32:55 +00:00
|
|
|
let preScript = pkgs.writers.writeBashBin "pleromaStartPre" ''
|
2022-05-06 10:38:28 +00:00
|
|
|
if [ ! -f /var/lib/pleroma/.cookie ]
|
2021-12-07 16:32:55 +00:00
|
|
|
then
|
|
|
|
echo "Creating cookie file"
|
2022-05-06 10:38:28 +00:00
|
|
|
dd if=/dev/urandom bs=1 count=16 | hexdump -e '16/1 "%02x"' > /var/lib/pleroma/.cookie
|
2021-12-07 16:32:55 +00:00
|
|
|
fi
|
|
|
|
${cfg.package}/bin/pleroma_ctl migrate
|
|
|
|
'';
|
2020-11-08 14:05:37 +00:00
|
|
|
in "${preScript}/bin/pleromaStartPre";
|
|
|
|
|
|
|
|
ExecStart = "${cfg.package}/bin/pleroma start";
|
|
|
|
ExecStop = "${cfg.package}/bin/pleroma stop";
|
|
|
|
ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
|
|
|
|
|
|
|
|
# Systemd sandboxing directives.
|
|
|
|
# Taken from the upstream contrib systemd service at
|
|
|
|
# pleroma/installation/pleroma.service
|
|
|
|
PrivateTmp = true;
|
|
|
|
ProtectHome = true;
|
|
|
|
ProtectSystem = "full";
|
|
|
|
PrivateDevices = false;
|
|
|
|
NoNewPrivileges = true;
|
|
|
|
CapabilityBoundingSet = "~CAP_SYS_ADMIN";
|
|
|
|
};
|
2022-12-25 12:38:55 +00:00
|
|
|
# disksup requires bash
|
|
|
|
path = [ pkgs.bash ];
|
2020-11-08 14:05:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
meta.maintainers = with lib.maintainers; [ ninjatrappeur ];
|
|
|
|
meta.doc = ./pleroma.xml;
|
|
|
|
}
|