helm/reference/wallabag.nix

121 lines
3.4 KiB
Nix
Raw Permalink Normal View History

{ pkgs, config, lib, ... }:
let
phppoolName = "wallabag";
dataDir = "/var/lib/wallabag";
vhost = "read.mossnet.local";
in
{
services.nginx.virtualHosts."${vhost}" = {
forceSSL = false;
enableACME = false;
root = "/var/lib/wallabag/web";
listen = [ { addr = "192.168.1.6"; port = 800; } ];
locations."/" = {
extraConfig = ''
try_files $uri /app.php$is_args$args;
'';
};
locations."/assets".root = "${dataDir}/web";
locations."~ ^/app\.php(/|$)" = {
extraConfig = ''
include ${pkgs.nginx}/conf/fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
fastcgi_pass unix:${config.services.phpfpm.pools."${phppoolName}".socket};
fastcgi_param SCRIPT_FILENAME {pkgs.wallabag}/web/$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT {pkgs.wallabag}/web;
'';
};
locations."~ \.php$" = {
extraConfig = ''
return 404;
'';
};
};
services.postgresql = {
enable = true;
# Ensure the database, user, and permissions always exist
ensureDatabases = [ "wallabag" ];
ensureUsers = [
{ name = "wallabag";
ensurePermissions."DATABASE wallabag" = "ALL PRIVILEGES";
}
];
};
services.phpfpm.pools."${phppoolName}" = {
user = "wallabag";
group = "wallabag";
phpEnv."WALLABAG_DATA" = "/var/lib/wallabag";
phpEnv."PATH" = lib.makeBinPath [ pkgs.php ];
settings = {
"listen.owner" = "nginx";
"listen.group" = "nginx";
"user" = "wallabag";
"pm" = "dynamic";
"pm.max_children" = "75";
"pm.min_spare_servers" = "5";
"pm.max_spare_servers" = "20";
"pm.max_requests" = "10";
"catch_workers_output" = "1";
};
};
systemd.services.wallabag-install = {
description = "Wallabag install service";
wantedBy = [ "multi-user.target" ];
before = [ "phpfpm-wallabag.service" ];
after = [ "mysql.service" "postgresql.service" ];
path = [ pkgs.coreutils pkgs.php73 pkgs.php73Packages.composer ];
serviceConfig = {
User = "wallabag";
Type = "oneshot";
RemainAfterExit = "yes";
PermissionsStartOnly = true;
};
preStart = ''
mkdir -p "${dataDir}"
chown wallabag:nginx "${dataDir}"
'';
script = ''
echo "Setting up wallabag files in ${dataDir} ..."
cd "${dataDir}"
rm -rf var/cache/*
rm -f ${dataDir}/app
rm -f ${dataDir}/bin
ln -sf ${pkgs.wallabag}/app app
ln -sf ${pkgs.wallabag}/composer.{json,lock} .
ln -sf ${pkgs.wallabag}/bin/ bin
export WALLABAG_DATA="${dataDir}"
if [ ! -f installed ]; then
php /var/lib/wallabag/bin/console --env=prod doctrine:database:create --if-not-exists --no-interaction
php /var/lib/wallabag/bin/console --env=prod doctrine:migrations:migrate --no-interaction
# Until https://github.com/wallabag/wallabag/issues/3662 is fixed
yes no | php /var/lib/wallabag/bin/console --env=prod wallabag:install
touch installed
else
php ${pkgs.wallabag}/bin/console --env=prod doctrine:migrations:migrate --no-interaction
fi
php ${pkgs.wallabag}/bin/console --env=prod cache:clear
'';
};
users.extraUsers.wallabag = { group = "wallabag"; };
users.extraGroups.wallabag = { };
networking.firewall.allowedTCPPorts = [ 800 ];
}