1 { config, options, lib, pkgs, stdenv, ... }:
3 cfg = config.services.pleroma;
6 services.pleroma = with lib; {
7 enable = mkEnableOption (lib.mdDoc "pleroma");
11 default = pkgs.pleroma;
12 defaultText = literalExpression "pkgs.pleroma";
13 description = lib.mdDoc "Pleroma package to use.";
19 description = lib.mdDoc "User account under which pleroma runs.";
25 description = lib.mdDoc "Group account under which pleroma runs.";
30 default = "/var/lib/pleroma";
32 description = lib.mdDoc "Directory where the pleroma service will save the uploads and static files.";
36 type = with types; listOf str;
37 description = lib.mdDoc ''
38 Pleroma public configuration.
40 This list gets appended from left to
41 right into /etc/pleroma/config.exs. Elixir evaluates its
42 configuration imperatively, meaning you can override a
43 setting by appending a new str to this NixOS option list.
45 *DO NOT STORE ANY PLEROMA SECRET
47 [services.pleroma.secretConfigFile](#opt-services.pleroma.secretConfigFile)
50 This setting is going to be stored in a file part of
51 the Nix store. The Nix store being world-readable, it's not
52 the right place to store any secret
54 Have a look to Pleroma section in the NixOS manual for more
59 secretConfigFile = mkOption {
61 default = "/var/lib/pleroma/secrets.exs";
62 description = lib.mdDoc ''
63 Path to the file containing your secret pleroma configuration.
65 *DO NOT POINT THIS OPTION TO THE NIX
66 STORE*, the store being world-readable, it'll
67 compromise all your secrets.
73 config = lib.mkIf cfg.enable {
75 users."${cfg.user}" = {
76 description = "Pleroma user";
81 groups."${cfg.group}" = {};
84 environment.systemPackages = [ cfg.package ];
86 environment.etc."/pleroma/config.exs".text = ''
87 ${lib.concatMapStrings (x: "${x}") cfg.configs}
89 # The lau/tzdata library is trying to download the latest
90 # timezone database in the OTP priv directory by default.
91 # This directory being in the store, it's read-only.
92 # Setting that up to a more appropriate location.
93 config :tzdata, :data_dir, "/var/lib/pleroma/elixir_tzdata_data"
95 import_config "${cfg.secretConfigFile}"
98 systemd.services.pleroma = {
99 description = "Pleroma social network";
100 after = [ "network-online.target" "postgresql.service" ];
101 wantedBy = [ "multi-user.target" ];
102 restartTriggers = [ config.environment.etc."/pleroma/config.exs".source ];
103 environment.RELEASE_COOKIE = "/var/lib/pleroma/.cookie";
108 WorkingDirectory = "~";
109 StateDirectory = "pleroma pleroma/static pleroma/uploads";
110 StateDirectoryMode = "700";
112 # Checking the conf file is there then running the database
113 # migration before each service start, just in case there are
116 # It's sub-optimal as we'll always run this, even if pleroma
117 # has not been updated. But the no-op process is pretty fast.
118 # Better be safe than sorry migration-wise.
120 let preScript = pkgs.writers.writeBashBin "pleromaStartPre" ''
121 if [ ! -f /var/lib/pleroma/.cookie ]
123 echo "Creating cookie file"
124 dd if=/dev/urandom bs=1 count=16 | hexdump -e '16/1 "%02x"' > /var/lib/pleroma/.cookie
126 ${cfg.package}/bin/pleroma_ctl migrate
128 in "${preScript}/bin/pleromaStartPre";
130 ExecStart = "${cfg.package}/bin/pleroma start";
131 ExecStop = "${cfg.package}/bin/pleroma stop";
132 ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
134 # Systemd sandboxing directives.
135 # Taken from the upstream contrib systemd service at
136 # pleroma/installation/pleroma.service
139 ProtectSystem = "full";
140 PrivateDevices = false;
141 NoNewPrivileges = true;
142 CapabilityBoundingSet = "~CAP_SYS_ADMIN";
147 meta.maintainers = with lib.maintainers; [ ninjatrappeur ];
148 meta.doc = ./pleroma.xml;