8 cfg = config.services.pleroma;
12 services.pleroma = with lib; {
13 enable = mkEnableOption "pleroma";
15 package = mkPackageOption pkgs "pleroma" { };
20 description = "User account under which pleroma runs.";
26 description = "Group account under which pleroma runs.";
31 default = "/var/lib/pleroma";
33 description = "Directory where the pleroma service will save the uploads and static files.";
37 type = with types; listOf str;
39 Pleroma public configuration.
41 This list gets appended from left to
42 right into /etc/pleroma/config.exs. Elixir evaluates its
43 configuration imperatively, meaning you can override a
44 setting by appending a new str to this NixOS option list.
46 *DO NOT STORE ANY PLEROMA SECRET
48 [services.pleroma.secretConfigFile](#opt-services.pleroma.secretConfigFile)
51 This setting is going to be stored in a file part of
52 the Nix store. The Nix store being world-readable, it's not
53 the right place to store any secret
55 Have a look to Pleroma section in the NixOS manual for more
60 secretConfigFile = mkOption {
62 default = "/var/lib/pleroma/secrets.exs";
64 Path to the file containing your secret pleroma configuration.
66 *DO NOT POINT THIS OPTION TO THE NIX
67 STORE*, the store being world-readable, it'll
68 compromise all your secrets.
74 config = lib.mkIf cfg.enable {
76 users."${cfg.user}" = {
77 description = "Pleroma user";
82 groups."${cfg.group}" = { };
85 environment.systemPackages = [ cfg.package ];
87 environment.etc."/pleroma/config.exs".text = ''
88 ${lib.concatMapStrings (x: "${x}") cfg.configs}
90 # The lau/tzdata library is trying to download the latest
91 # timezone database in the OTP priv directory by default.
92 # This directory being in the store, it's read-only.
93 # Setting that up to a more appropriate location.
94 config :tzdata, :data_dir, "/var/lib/pleroma/elixir_tzdata_data"
96 import_config "${cfg.secretConfigFile}"
101 commonSystemdServiceConfig = {
104 WorkingDirectory = "~";
105 StateDirectory = "pleroma pleroma/static pleroma/uploads";
106 StateDirectoryMode = "700";
107 # Systemd sandboxing directives.
108 # Taken from the upstream contrib systemd service at
109 # pleroma/installation/pleroma.service
112 ProtectSystem = "full";
113 PrivateDevices = false;
114 NoNewPrivileges = true;
115 CapabilityBoundingSet = "~CAP_SYS_ADMIN";
120 pleroma-migrations = {
121 description = "Pleroma social network migrations";
122 wants = [ "network-online.target" ];
124 "network-online.target"
127 wantedBy = [ "pleroma.service" ];
128 environment.RELEASE_COOKIE = "/var/lib/pleroma/.cookie";
129 serviceConfig = commonSystemdServiceConfig // {
131 # Checking the conf file is there then running the database
132 # migration before each service start, just in case there are
135 # It's sub-optimal as we'll always run this, even if pleroma
136 # has not been updated. But the no-op process is pretty fast.
137 # Better be safe than sorry migration-wise.
140 preScript = pkgs.writers.writeBashBin "pleroma-migrations" ''
141 if [ ! -f /var/lib/pleroma/.cookie ]
143 echo "Creating cookie file"
144 dd if=/dev/urandom bs=1 count=16 | hexdump -e '16/1 "%02x"' > /var/lib/pleroma/.cookie
146 ${cfg.package}/bin/pleroma_ctl migrate
149 "${preScript}/bin/pleroma-migrations";
151 # disksup requires bash
152 path = [ pkgs.bash ];
156 description = "Pleroma social network";
157 wants = [ "pleroma-migrations.service" ];
158 after = [ "pleroma-migrations.service" ];
159 wantedBy = [ "multi-user.target" ];
160 restartTriggers = [ config.environment.etc."/pleroma/config.exs".source ];
161 environment.RELEASE_COOKIE = "/var/lib/pleroma/.cookie";
162 serviceConfig = commonSystemdServiceConfig // {
164 ExecStart = "${cfg.package}/bin/pleroma start";
165 ExecStop = "${cfg.package}/bin/pleroma stop";
166 ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
168 # disksup requires bash
169 path = [ pkgs.bash ];
173 meta.maintainers = with lib.maintainers; [ picnoir ];
174 meta.doc = ./pleroma.md;