9 cfg = config.services.privatebin;
11 customToINI = lib.generators.toINI {
12 mkKeyValue = lib.generators.mkKeyValueDefault {
17 else if v == false then
19 else if builtins.isInt v then
20 ''${builtins.toString v}''
21 else if builtins.isPath v then
22 ''"${builtins.toString v}"''
23 else if builtins.isString v then
26 lib.generators.mkValueStringDefault { } v;
30 privatebinSettings = pkgs.writeTextDir "conf.php" (customToINI cfg.settings);
35 defaultUser = "privatebin";
36 defaultGroup = "privatebin";
41 options.services.privatebin = {
43 enable = lib.mkEnableOption "Privatebin: A minimalist, open source online
44 pastebin where the server has zero knowledge of pasted data.";
48 default = defaultUser;
49 description = "User account under which privatebin runs.";
52 group = lib.mkOption {
54 default = if cfg.enableNginx then "nginx" else defaultGroup;
55 defaultText = "If `services.privatebin.enableNginx` is true then `nginx` else ${defaultGroup}";
57 Group under which privatebin runs. It is best to set this to the group
58 of whatever webserver is being used as the frontend.
62 dataDir = lib.mkOption {
63 type = lib.types.path;
64 default = "/var/lib/privatebin";
66 The place where privatebin stores its state.
70 package = lib.mkPackageOption pkgs "privatebin" { };
72 enableNginx = lib.mkOption {
73 type = lib.types.bool;
76 Whether to enable nginx or not. If enabled, an nginx virtual host will
77 be created for access to firefly-iii. If not enabled, then you may use
78 `''${config.services.firefly-iii.package}` as your document root in
79 whichever webserver you wish to setup.
83 virtualHost = lib.mkOption {
85 default = "localhost";
87 The hostname at which you wish privatebin to be served. If you have
88 enabled nginx using `services.privatebin.enableNginx` then this will
93 poolConfig = lib.mkOption {
94 type = lib.types.attrsOf (
101 defaultText = lib.literalExpression ''
104 "pm.max_children" = 32;
105 "pm.start_servers" = 2;
106 "pm.min_spare_servers" = 2;
107 "pm.max_spare_servers" = 4;
108 "pm.max_requests" = 500;
113 Options for the PrivateBin PHP pool. See the documentation on <literal>php-fpm.conf</literal>
114 for details on configuration directives.
118 settings = lib.mkOption {
121 Options for privatebin configuration. Refer to
122 <https://github.com/PrivateBin/PrivateBin/wiki/Configuration> for
123 details on supported values.
125 example = lib.literalExpression ''
128 name = "NixOS Based Privatebin";
130 defaultformatter = "plalib.types.intext";
133 model.class = "Filesystem";
134 model_options.dir = "/var/lib/privatebin/data";
137 type = lib.types.submodule { freeformType = lib.types.attrsOf lib.types.anything; };
141 config = lib.mkIf cfg.enable {
143 services.privatebin.settings = {
144 main = lib.mkDefault { };
145 model.class = lib.mkDefault "Filesystem";
146 model_options.dir = lib.mkDefault "${cfg.dataDir}/data";
147 purge.dir = lib.mkDefault "${cfg.dataDir}/purge";
149 dir = lib.mkDefault "${cfg.dataDir}/traffic";
150 header = "X_FORWARDED_FOR";
154 services.phpfpm.pools.privatebin = {
156 phpPackage = pkgs.php83;
161 "listen.mode" = lib.mkDefault "0660";
162 "listen.owner" = lib.mkDefault user;
163 "listen.group" = lib.mkDefault group;
164 "pm" = lib.mkDefault "dynamic";
165 "pm.max_children" = lib.mkDefault 32;
166 "pm.start_servers" = lib.mkDefault 2;
167 "pm.min_spare_servers" = lib.mkDefault 2;
168 "pm.max_spare_servers" = lib.mkDefault 4;
169 "pm.max_requests" = lib.mkDefault 500;
171 phpEnv.CONFIG_PATH = lib.strings.removeSuffix "/conf.php" (builtins.toString privatebinSettings);
174 services.nginx = lib.mkIf cfg.enableNginx {
176 recommendedTlsSettings = lib.mkDefault true;
177 recommendedOptimisation = lib.mkDefault true;
178 recommendedGzipSettings = lib.mkDefault true;
179 virtualHosts.${cfg.virtualHost} = {
180 root = "${cfg.package}";
183 tryFiles = "$uri $uri/ /index.php?$query_string";
191 include ${config.services.nginx.package}/conf/fastcgi_params ;
192 fastcgi_param SCRIPT_FILENAME $request_filename;
193 fastcgi_param modHeadersAvailable true; #Avoid sending the security headers twice
194 fastcgi_pass unix:${config.services.phpfpm.pools.privatebin.socket};
201 systemd.tmpfiles.settings."10-privatebin" =
202 lib.attrsets.genAttrs
204 "${cfg.dataDir}/data"
205 "${cfg.dataDir}/traffic"
206 "${cfg.dataDir}/purge"
217 users = lib.mkIf (user == defaultUser) {
219 description = "Privatebin service user";
225 groups = lib.mkIf (group == defaultGroup) { ${defaultGroup} = { }; };