2024-08-02 23:45:19 +03:00
|
|
|
{ pkgs, util, container, lib, config, __findFile, ... } @args: with lib; let
|
2024-06-25 04:04:39 +03:00
|
|
|
cfg = config.container.module.paste;
|
2024-08-21 11:31:57 +03:00
|
|
|
package = (pkgs.callPackage <package/privatebin> args);
|
2024-06-01 10:37:49 +03:00
|
|
|
in {
|
2024-06-25 04:04:39 +03:00
|
|
|
options = {
|
|
|
|
container.module.paste = {
|
|
|
|
enable = mkEnableOption "Pastebin.";
|
|
|
|
address = mkOption {
|
|
|
|
default = "10.1.0.14";
|
|
|
|
type = types.str;
|
2024-06-01 10:37:49 +03:00
|
|
|
};
|
2024-06-25 04:04:39 +03:00
|
|
|
port = mkOption {
|
|
|
|
default = 80;
|
|
|
|
type = types.int;
|
2024-06-01 10:37:49 +03:00
|
|
|
};
|
2024-06-25 04:04:39 +03:00
|
|
|
domain = mkOption {
|
|
|
|
default = "paste.${config.container.domain}";
|
|
|
|
type = types.str;
|
2024-06-01 10:37:49 +03:00
|
|
|
};
|
2024-06-25 04:04:39 +03:00
|
|
|
storage = mkOption {
|
|
|
|
default = "${config.container.storage}/paste";
|
|
|
|
type = types.str;
|
2024-06-01 10:37:49 +03:00
|
|
|
};
|
|
|
|
};
|
2024-06-25 04:04:39 +03:00
|
|
|
};
|
2024-06-01 10:37:49 +03:00
|
|
|
|
2024-06-25 04:04:39 +03:00
|
|
|
config = mkIf cfg.enable {
|
|
|
|
systemd.tmpfiles.rules = container.mkContainerDir cfg [
|
|
|
|
"data"
|
|
|
|
"tmp"
|
|
|
|
"nginxtmp"
|
|
|
|
"config"
|
|
|
|
];
|
2024-06-01 10:37:49 +03:00
|
|
|
|
2024-06-25 04:04:39 +03:00
|
|
|
containers.paste = container.mkContainer cfg {
|
|
|
|
bindMounts = {
|
|
|
|
"/srv/data" = {
|
|
|
|
hostPath = "${cfg.storage}/data";
|
|
|
|
isReadOnly = false;
|
|
|
|
};
|
|
|
|
"/tmp" = {
|
|
|
|
hostPath = "${cfg.storage}/tmp";
|
|
|
|
isReadOnly = false;
|
|
|
|
};
|
|
|
|
"/var/lib/nginx/tmp" = {
|
|
|
|
hostPath = "${cfg.storage}/nginxtmp";
|
|
|
|
isReadOnly = false;
|
|
|
|
};
|
|
|
|
"/srv/config" = {
|
|
|
|
hostPath = "${cfg.storage}/config";
|
|
|
|
isReadOnly = false;
|
|
|
|
};
|
2024-06-01 10:37:49 +03:00
|
|
|
};
|
|
|
|
|
2024-06-25 04:04:39 +03:00
|
|
|
config = { config, ... }: container.mkContainerConfig cfg {
|
|
|
|
environment.systemPackages = [ package ];
|
|
|
|
systemd.packages = [ package ];
|
2024-06-01 10:37:49 +03:00
|
|
|
|
2024-06-25 04:04:39 +03:00
|
|
|
users.users.paste = {
|
|
|
|
group = "nginx";
|
|
|
|
isSystemUser = true;
|
2024-06-01 10:37:49 +03:00
|
|
|
};
|
|
|
|
|
2024-06-25 04:04:39 +03:00
|
|
|
services.phpfpm.pools.paste = {
|
|
|
|
user = "paste";
|
|
|
|
group = "nginx";
|
|
|
|
|
|
|
|
phpPackage = pkgs.php;
|
|
|
|
|
|
|
|
settings = {
|
|
|
|
"pm" = "dynamic";
|
|
|
|
"php_admin_value[error_log]" = "stderr";
|
|
|
|
"php_admin_flag[log_errors]" = true;
|
|
|
|
"listen.owner" = "nginx";
|
|
|
|
"catch_workers_output" = true;
|
|
|
|
"pm.max_children" = "32";
|
|
|
|
"pm.start_servers" = "2";
|
|
|
|
"pm.min_spare_servers" = "2";
|
|
|
|
"pm.max_spare_servers" = "4";
|
|
|
|
"pm.max_requests" = "500";
|
|
|
|
};
|
|
|
|
|
|
|
|
phpEnv = {
|
|
|
|
# CONFIG_PATH = "${package}/cfg";
|
|
|
|
};
|
2024-06-01 10:37:49 +03:00
|
|
|
};
|
|
|
|
|
2024-06-25 04:04:39 +03:00
|
|
|
services.nginx = {
|
|
|
|
enable = true;
|
|
|
|
virtualHosts.${cfg.domain} = container.mkServer {
|
|
|
|
default = true;
|
|
|
|
root = "${package}";
|
2024-06-01 10:37:49 +03:00
|
|
|
|
2024-06-25 04:04:39 +03:00
|
|
|
locations = {
|
|
|
|
"/".extraConfig = ''
|
|
|
|
rewrite ^ /index.php;
|
|
|
|
'';
|
2024-06-01 10:37:49 +03:00
|
|
|
|
2024-06-25 04:04:39 +03:00
|
|
|
"~ \\.php$".extraConfig = util.trimTabs ''
|
|
|
|
fastcgi_split_path_info ^(.+\.php)(/.+)$;
|
|
|
|
fastcgi_pass unix:${config.services.phpfpm.pools.paste.socket};
|
|
|
|
include ${config.services.nginx.package}/conf/fastcgi.conf;
|
|
|
|
include ${config.services.nginx.package}/conf/fastcgi_params;
|
|
|
|
'';
|
2024-06-01 10:37:49 +03:00
|
|
|
|
2024-06-25 04:04:39 +03:00
|
|
|
"~ \\.(js|css|ttf|woff2?|png|jpe?g|svg)$".extraConfig = util.trimTabs ''
|
|
|
|
add_header Cache-Control "public, max-age=15778463";
|
|
|
|
add_header X-Content-Type-Options nosniff;
|
|
|
|
add_header X-XSS-Protection "1; mode=block";
|
|
|
|
add_header X-Robots-Tag none;
|
|
|
|
add_header X-Download-Options noopen;
|
|
|
|
add_header X-Permitted-Cross-Domain-Policies none;
|
|
|
|
add_header Referrer-Policy no-referrer;
|
|
|
|
access_log off;
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
extraConfig = util.trimTabs ''
|
|
|
|
try_files $uri /index.php;
|
2024-06-01 10:37:49 +03:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|