2023-11-10 18:48:06 +00:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
pkgs,
|
|
|
|
lib,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
2024-06-13 00:14:25 +00:00
|
|
|
inherit (lib)
|
|
|
|
any
|
|
|
|
attrValues
|
2024-06-24 20:57:44 +00:00
|
|
|
boolToString
|
2024-06-13 00:14:25 +00:00
|
|
|
concatMapStringsSep
|
|
|
|
concatStrings
|
2024-06-24 20:57:44 +00:00
|
|
|
concatStringsSep
|
|
|
|
escapeShellArg
|
2024-06-13 00:14:25 +00:00
|
|
|
flatten
|
2024-06-24 20:57:44 +00:00
|
|
|
isBool
|
|
|
|
isInt
|
|
|
|
isList
|
|
|
|
isString
|
2024-06-13 00:14:25 +00:00
|
|
|
literalExpression
|
|
|
|
mapAttrs'
|
|
|
|
mapAttrsToList
|
|
|
|
mkDefault
|
|
|
|
mkEnableOption
|
|
|
|
mkIf
|
|
|
|
mkMerge
|
|
|
|
mkOption
|
|
|
|
nameValuePair
|
2024-06-24 20:57:44 +00:00
|
|
|
optionalString
|
2024-06-13 00:14:25 +00:00
|
|
|
types
|
|
|
|
;
|
|
|
|
|
2023-11-10 18:48:06 +00:00
|
|
|
cfg = config.services.invoiceplane;
|
|
|
|
eachSite = cfg.sites;
|
|
|
|
user = "invoiceplane";
|
|
|
|
webserver = config.services.${cfg.webserver};
|
|
|
|
|
|
|
|
invoiceplane-config =
|
|
|
|
hostName: cfg:
|
|
|
|
pkgs.writeText "ipconfig.php" ''
|
|
|
|
IP_URL=http://${hostName}
|
|
|
|
ENABLE_DEBUG=false
|
|
|
|
DISABLE_SETUP=false
|
|
|
|
REMOVE_INDEXPHP=false
|
|
|
|
DB_HOSTNAME=${cfg.database.host}
|
|
|
|
DB_USERNAME=${cfg.database.user}
|
|
|
|
# NOTE: file_get_contents adds newline at the end of returned string
|
2024-06-24 20:57:44 +00:00
|
|
|
DB_PASSWORD=${
|
2023-11-10 18:48:06 +00:00
|
|
|
optionalString (
|
2024-06-24 20:57:44 +00:00
|
|
|
cfg.database.passwordFile != null
|
|
|
|
) "trim(file_get_contents('${cfg.database.passwordFile}'), \"\\r\\n\")"
|
|
|
|
}
|
2023-11-10 18:48:06 +00:00
|
|
|
DB_DATABASE=${cfg.database.name}
|
2024-06-24 20:57:44 +00:00
|
|
|
DB_PORT=${toString cfg.database.port}
|
|
|
|
SESS_EXPIRATION=864000
|
|
|
|
ENABLE_INVOICE_DELETION=false
|
|
|
|
DISABLE_READ_ONLY=false
|
|
|
|
ENCRYPTION_KEY=
|
|
|
|
ENCRYPTION_CIPHER=AES-256
|
|
|
|
SETUP_COMPLETED=false
|
|
|
|
REMOVE_INDEXPHP=true
|
2023-11-10 18:48:06 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
mkPhpValue =
|
2024-08-19 10:38:46 +00:00
|
|
|
v:
|
2023-11-10 18:48:06 +00:00
|
|
|
if isString v then
|
2024-06-24 20:57:44 +00:00
|
|
|
escapeShellArg v
|
2023-11-10 18:48:06 +00:00
|
|
|
# NOTE: If any value contains a , (comma) this will not get escaped
|
|
|
|
else if isList v && any lib.strings.isCoercibleToString v then
|
2024-06-24 20:57:44 +00:00
|
|
|
escapeShellArg (concatMapStringsSep "," toString v)
|
|
|
|
else if isInt v then
|
|
|
|
toString v
|
|
|
|
else if isBool v then
|
|
|
|
boolToString v
|
2024-08-19 10:38:46 +00:00
|
|
|
else
|
2024-06-24 20:57:44 +00:00
|
|
|
abort "The Invoiceplane config value ${lib.generators.toPretty { } v} can not be encoded.";
|
2024-08-19 10:38:46 +00:00
|
|
|
|
2024-06-24 20:57:44 +00:00
|
|
|
extraConfig =
|
2023-11-10 18:48:06 +00:00
|
|
|
hostName: cfg:
|
2024-08-19 10:38:46 +00:00
|
|
|
let
|
2024-06-24 20:57:44 +00:00
|
|
|
settings = mapAttrsToList (k: v: "${k}=${mkPhpValue v}") cfg.settings;
|
2024-08-19 10:38:46 +00:00
|
|
|
in
|
2024-06-24 20:57:44 +00:00
|
|
|
pkgs.writeText "extraConfig.php" (concatStringsSep "\n" settings);
|
2024-08-19 10:38:46 +00:00
|
|
|
|
|
|
|
pkg =
|
2023-11-10 18:48:06 +00:00
|
|
|
hostName: cfg:
|
|
|
|
pkgs.stdenv.mkDerivation rec {
|
|
|
|
pname = "invoiceplane-${hostName}";
|
|
|
|
version = src.version;
|
|
|
|
src = pkgs.invoiceplane;
|
2024-08-19 10:38:46 +00:00
|
|
|
|
2023-11-10 18:48:06 +00:00
|
|
|
postPatch = ''
|
|
|
|
# Patch index.php file to load additional config file
|
|
|
|
substituteInPlace index.php \
|
|
|
|
--replace-fail "require('vendor/autoload.php');" "require('vendor/autoload.php'); \$dotenv = Dotenv\Dotenv::createImmutable(__DIR__, 'extraConfig.php'); \$dotenv->load();";
|
2024-08-19 10:38:46 +00:00
|
|
|
'';
|
|
|
|
|
2023-11-10 18:48:06 +00:00
|
|
|
installPhase = ''
|
|
|
|
mkdir -p $out
|
2024-08-19 10:38:46 +00:00
|
|
|
cp -r * $out/
|
|
|
|
|
2023-11-10 18:48:06 +00:00
|
|
|
# symlink uploads and log directories
|
|
|
|
rm -r $out/uploads $out/application/logs $out/vendor/mpdf/mpdf/tmp
|
|
|
|
ln -sf ${cfg.stateDir}/uploads $out/
|
|
|
|
ln -sf ${cfg.stateDir}/logs $out/application/
|
|
|
|
ln -sf ${cfg.stateDir}/tmp $out/vendor/mpdf/mpdf/
|
2024-08-19 10:38:46 +00:00
|
|
|
|
2023-11-10 18:48:06 +00:00
|
|
|
# symlink the InvoicePlane config
|
|
|
|
ln -s ${cfg.stateDir}/ipconfig.php $out/ipconfig.php
|
2024-08-19 10:38:46 +00:00
|
|
|
|
2023-11-10 18:48:06 +00:00
|
|
|
# symlink the extraConfig file
|
|
|
|
ln -s ${extraConfig hostName cfg} $out/extraConfig.php
|
2024-08-19 10:38:46 +00:00
|
|
|
|
2023-11-10 18:48:06 +00:00
|
|
|
# symlink additional templates
|
|
|
|
${concatMapStringsSep "\n" (
|
|
|
|
template: "cp -r ${template}/. $out/application/views/invoice_templates/pdf/"
|
|
|
|
) cfg.invoiceTemplates}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-06-24 20:57:44 +00:00
|
|
|
siteOpts =
|
|
|
|
{ name, ... }:
|
2023-11-10 18:48:06 +00:00
|
|
|
{
|
|
|
|
options = {
|
|
|
|
|
2024-06-24 20:57:44 +00:00
|
|
|
enable = mkEnableOption "InvoicePlane web application";
|
2023-11-10 18:48:06 +00:00
|
|
|
|
|
|
|
stateDir = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
default = "/var/lib/invoiceplane/${name}";
|
2024-06-24 20:57:44 +00:00
|
|
|
description = ''
|
2023-11-10 18:48:06 +00:00
|
|
|
This directory is used for uploads of attachments and cache.
|
|
|
|
The directory passed here is automatically created and permissions
|
|
|
|
adjusted as required.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
database = {
|
|
|
|
host = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "localhost";
|
2024-06-24 20:57:44 +00:00
|
|
|
description = "Database host address.";
|
2023-11-10 18:48:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
port = mkOption {
|
|
|
|
type = types.port;
|
|
|
|
default = 3306;
|
2024-06-24 20:57:44 +00:00
|
|
|
description = "Database host port.";
|
2023-11-10 18:48:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
name = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "invoiceplane";
|
2024-06-24 20:57:44 +00:00
|
|
|
description = "Database name.";
|
2023-11-10 18:48:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
user = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "invoiceplane";
|
2024-06-24 20:57:44 +00:00
|
|
|
description = "Database user.";
|
2023-11-10 18:48:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
passwordFile = mkOption {
|
|
|
|
type = types.nullOr types.path;
|
|
|
|
default = null;
|
|
|
|
example = "/run/keys/invoiceplane-dbpassword";
|
2024-06-24 20:57:44 +00:00
|
|
|
description = ''
|
2023-11-10 18:48:06 +00:00
|
|
|
A file containing the password corresponding to
|
|
|
|
{option}`database.user`.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
createLocally = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
2024-06-24 20:57:44 +00:00
|
|
|
description = "Create the database and database user locally.";
|
2023-11-10 18:48:06 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
invoiceTemplates = mkOption {
|
|
|
|
type = types.listOf types.path;
|
|
|
|
default = [ ];
|
2024-06-24 20:57:44 +00:00
|
|
|
description = ''
|
2023-11-10 18:48:06 +00:00
|
|
|
List of path(s) to respective template(s) which are copied from the 'invoice_templates/pdf' directory.
|
|
|
|
|
|
|
|
::: {.note}
|
|
|
|
These templates need to be packaged before use, see example.
|
|
|
|
:::
|
|
|
|
'';
|
|
|
|
example = literalExpression ''
|
|
|
|
let
|
|
|
|
# Let's package an example template
|
|
|
|
template-vtdirektmarketing = pkgs.stdenv.mkDerivation {
|
|
|
|
name = "vtdirektmarketing";
|
|
|
|
# Download the template from a public repository
|
|
|
|
src = pkgs.fetchgit {
|
|
|
|
url = "https://git.project-insanity.org/onny/invoiceplane-vtdirektmarketing.git";
|
|
|
|
sha256 = "1hh0q7wzsh8v8x03i82p6qrgbxr4v5fb05xylyrpp975l8axyg2z";
|
|
|
|
};
|
|
|
|
sourceRoot = ".";
|
|
|
|
# Installing simply means copying template php file to the output directory
|
|
|
|
installPhase = ""
|
|
|
|
mkdir -p $out
|
|
|
|
cp invoiceplane-vtdirektmarketing/vtdirektmarketing.php $out/
|
|
|
|
"";
|
|
|
|
};
|
|
|
|
# And then pass this package to the template list like this:
|
|
|
|
in [ template-vtdirektmarketing ]
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
poolConfig = mkOption {
|
|
|
|
type =
|
|
|
|
with types;
|
|
|
|
attrsOf (oneOf [
|
|
|
|
str
|
|
|
|
int
|
|
|
|
bool
|
|
|
|
]);
|
|
|
|
default = {
|
|
|
|
"pm" = "dynamic";
|
|
|
|
"pm.max_children" = 32;
|
|
|
|
"pm.start_servers" = 2;
|
|
|
|
"pm.min_spare_servers" = 2;
|
|
|
|
"pm.max_spare_servers" = 4;
|
|
|
|
"pm.max_requests" = 500;
|
|
|
|
};
|
2024-06-24 20:57:44 +00:00
|
|
|
description = ''
|
2023-11-10 18:48:06 +00:00
|
|
|
Options for the InvoicePlane PHP pool. See the documentation on `php-fpm.conf`
|
|
|
|
for details on configuration directives.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-06-24 20:57:44 +00:00
|
|
|
settings = mkOption {
|
|
|
|
type = types.attrsOf types.anything;
|
|
|
|
default = { };
|
|
|
|
description = ''
|
|
|
|
Structural InvoicePlane configuration. Refer to
|
2023-11-10 18:48:06 +00:00
|
|
|
<https://github.com/InvoicePlane/InvoicePlane/blob/master/ipconfig.php.example>
|
2024-06-24 20:57:44 +00:00
|
|
|
for details and supported values.
|
|
|
|
'';
|
|
|
|
example = literalExpression ''
|
|
|
|
{
|
|
|
|
SETUP_COMPLETED = true;
|
|
|
|
DISABLE_SETUP = true;
|
|
|
|
IP_URL = "https://invoice.example.com";
|
|
|
|
}
|
2023-11-10 18:48:06 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
cron = {
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2024-06-24 20:57:44 +00:00
|
|
|
description = ''
|
2023-11-10 18:48:06 +00:00
|
|
|
Enable cron service which periodically runs Invoiceplane tasks.
|
|
|
|
Requires key taken from the administration page. Refer to
|
|
|
|
<https://wiki.invoiceplane.com/en/1.0/modules/recurring-invoices>
|
|
|
|
on how to configure it.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
key = mkOption {
|
|
|
|
type = types.str;
|
2024-06-24 20:57:44 +00:00
|
|
|
description = "Cron key taken from the administration page.";
|
2023-11-10 18:48:06 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
in
|
|
|
|
{
|
|
|
|
disabledModules = [ "services/web-apps/invoiceplane.nix" ];
|
|
|
|
|
|
|
|
# interface
|
|
|
|
options = {
|
|
|
|
services.invoiceplane = mkOption {
|
|
|
|
type = types.submodule {
|
|
|
|
|
|
|
|
options.sites = mkOption {
|
|
|
|
type = types.attrsOf (types.submodule siteOpts);
|
|
|
|
default = { };
|
2024-06-24 20:57:44 +00:00
|
|
|
description = "Specification of one or more WordPress sites to serve";
|
2023-11-10 18:48:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
options.webserver = mkOption {
|
2024-06-16 17:45:30 +00:00
|
|
|
type = types.enum [
|
|
|
|
"caddy"
|
|
|
|
"nginx"
|
|
|
|
];
|
2023-11-10 18:48:06 +00:00
|
|
|
default = "caddy";
|
2024-06-24 20:57:44 +00:00
|
|
|
example = "nginx";
|
|
|
|
description = ''
|
|
|
|
Which webserver to use for virtual host management.
|
2023-11-10 18:48:06 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
default = { };
|
2024-06-24 20:57:44 +00:00
|
|
|
description = "InvoicePlane configuration.";
|
2023-11-10 18:48:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
# implementation
|
|
|
|
config = mkIf (eachSite != { }) (mkMerge [
|
2024-08-19 10:38:46 +00:00
|
|
|
{
|
2023-11-10 18:48:06 +00:00
|
|
|
|
2024-06-24 20:57:44 +00:00
|
|
|
assertions = flatten (
|
|
|
|
mapAttrsToList (hostName: cfg: [
|
|
|
|
{
|
|
|
|
assertion = cfg.database.createLocally -> cfg.database.user == user;
|
2023-11-10 18:48:06 +00:00
|
|
|
message = ''services.invoiceplane.sites."${hostName}".database.user must be ${user} if the database is to be automatically provisioned'';
|
|
|
|
}
|
|
|
|
{
|
|
|
|
assertion = cfg.database.createLocally -> cfg.database.passwordFile == null;
|
|
|
|
message = ''services.invoiceplane.sites."${hostName}".database.passwordFile cannot be specified if services.invoiceplane.sites."${hostName}".database.createLocally is set to true.'';
|
|
|
|
}
|
|
|
|
{
|
|
|
|
assertion = cfg.cron.enable -> cfg.cron.key != null;
|
|
|
|
message = ''services.invoiceplane.sites."${hostName}".cron.key must be set in order to use cron service.'';
|
|
|
|
}
|
|
|
|
]) eachSite
|
|
|
|
);
|
2024-08-19 10:38:46 +00:00
|
|
|
|
2023-11-10 18:48:06 +00:00
|
|
|
services.mysql = mkIf (any (v: v.database.createLocally) (attrValues eachSite)) {
|
|
|
|
enable = true;
|
|
|
|
package = mkDefault pkgs.mariadb;
|
|
|
|
ensureDatabases = mapAttrsToList (hostName: cfg: cfg.database.name) eachSite;
|
|
|
|
ensureUsers = mapAttrsToList (hostName: cfg: {
|
|
|
|
name = cfg.database.user;
|
|
|
|
ensurePermissions = {
|
|
|
|
"${cfg.database.name}.*" = "ALL PRIVILEGES";
|
|
|
|
};
|
|
|
|
}) eachSite;
|
|
|
|
};
|
|
|
|
|
|
|
|
services.phpfpm = {
|
|
|
|
phpPackage = pkgs.php81;
|
|
|
|
pools = mapAttrs' (
|
|
|
|
hostName: cfg:
|
|
|
|
(nameValuePair "invoiceplane-${hostName}" {
|
|
|
|
inherit user;
|
|
|
|
group = webserver.group;
|
|
|
|
settings = {
|
|
|
|
"listen.owner" = webserver.user;
|
|
|
|
"listen.group" = webserver.group;
|
|
|
|
} // cfg.poolConfig;
|
|
|
|
})
|
|
|
|
) eachSite;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
systemd.tmpfiles.rules = flatten (
|
|
|
|
mapAttrsToList (hostName: cfg: [
|
|
|
|
"d ${cfg.stateDir} 0750 ${user} ${webserver.group} - -"
|
|
|
|
"f ${cfg.stateDir}/ipconfig.php 0750 ${user} ${webserver.group} - -"
|
|
|
|
"d ${cfg.stateDir}/logs 0750 ${user} ${webserver.group} - -"
|
|
|
|
"d ${cfg.stateDir}/uploads 0750 ${user} ${webserver.group} - -"
|
|
|
|
"d ${cfg.stateDir}/uploads/archive 0750 ${user} ${webserver.group} - -"
|
|
|
|
"d ${cfg.stateDir}/uploads/customer_files 0750 ${user} ${webserver.group} - -"
|
|
|
|
"d ${cfg.stateDir}/uploads/temp 0750 ${user} ${webserver.group} - -"
|
|
|
|
"d ${cfg.stateDir}/uploads/temp/mpdf 0750 ${user} ${webserver.group} - -"
|
|
|
|
"d ${cfg.stateDir}/tmp 0750 ${user} ${webserver.group} - -"
|
|
|
|
]) eachSite
|
2024-08-19 10:38:46 +00:00
|
|
|
);
|
|
|
|
|
2023-11-10 18:48:06 +00:00
|
|
|
systemd.services.invoiceplane-config = {
|
|
|
|
serviceConfig.Type = "oneshot";
|
|
|
|
script = concatStrings (
|
|
|
|
mapAttrsToList (hostName: cfg: ''
|
|
|
|
mkdir -p ${cfg.stateDir}/logs \
|
|
|
|
${cfg.stateDir}/uploads
|
|
|
|
if ! grep -q IP_URL "${cfg.stateDir}/ipconfig.php"; then
|
|
|
|
cp "${invoiceplane-config hostName cfg}" "${cfg.stateDir}/ipconfig.php"
|
2024-08-19 10:38:46 +00:00
|
|
|
fi
|
2023-11-10 18:48:06 +00:00
|
|
|
'') eachSite
|
2024-08-19 10:38:46 +00:00
|
|
|
);
|
2023-11-10 18:48:06 +00:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
2024-08-19 10:38:46 +00:00
|
|
|
};
|
2023-11-10 18:48:06 +00:00
|
|
|
|
|
|
|
users.users.${user} = {
|
|
|
|
group = webserver.group;
|
|
|
|
isSystemUser = true;
|
2024-08-19 10:38:46 +00:00
|
|
|
};
|
2023-11-10 18:48:06 +00:00
|
|
|
|
|
|
|
}
|
2024-06-16 17:45:30 +00:00
|
|
|
{
|
|
|
|
|
2024-06-24 20:58:37 +00:00
|
|
|
# Cron service implementation
|
2024-08-19 10:38:46 +00:00
|
|
|
|
2024-06-24 20:58:37 +00:00
|
|
|
systemd.timers = mapAttrs' (
|
|
|
|
hostName: cfg:
|
|
|
|
(nameValuePair "invoiceplane-cron-${hostName}" (
|
|
|
|
mkIf cfg.cron.enable {
|
2024-06-16 17:45:30 +00:00
|
|
|
wantedBy = [ "timers.target" ];
|
|
|
|
timerConfig = {
|
|
|
|
OnBootSec = "5m";
|
|
|
|
OnUnitActiveSec = "5m";
|
|
|
|
Unit = "invoiceplane-cron-${hostName}.service";
|
|
|
|
};
|
2024-08-19 10:38:46 +00:00
|
|
|
}
|
|
|
|
))
|
2023-11-10 18:48:06 +00:00
|
|
|
) eachSite;
|
2024-08-19 10:38:46 +00:00
|
|
|
|
2023-11-10 18:48:06 +00:00
|
|
|
systemd.services = mapAttrs' (
|
|
|
|
hostName: cfg:
|
|
|
|
(nameValuePair "invoiceplane-cron-${hostName}" (
|
|
|
|
mkIf cfg.cron.enable {
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "oneshot";
|
|
|
|
User = user;
|
|
|
|
ExecStart = "${pkgs.curl}/bin/curl --header 'Host: ${hostName}' http://localhost/invoices/cron/recur/${cfg.cron.key}";
|
2024-06-16 17:45:30 +00:00
|
|
|
};
|
2024-08-19 10:38:46 +00:00
|
|
|
}
|
|
|
|
))
|
2023-11-10 18:48:06 +00:00
|
|
|
) eachSite;
|
2024-08-19 10:38:46 +00:00
|
|
|
|
2024-06-16 17:45:30 +00:00
|
|
|
}
|
2024-08-19 10:38:46 +00:00
|
|
|
|
2023-11-10 18:48:06 +00:00
|
|
|
(mkIf (cfg.webserver == "caddy") {
|
|
|
|
services.caddy = {
|
2024-06-16 17:45:30 +00:00
|
|
|
enable = true;
|
|
|
|
virtualHosts = mapAttrs' (
|
2023-11-10 18:48:06 +00:00
|
|
|
hostName: cfg:
|
|
|
|
(nameValuePair "http://${hostName}" {
|
2024-06-16 17:45:30 +00:00
|
|
|
extraConfig = ''
|
2023-11-10 18:48:06 +00:00
|
|
|
root * ${pkg hostName cfg}
|
|
|
|
file_server
|
|
|
|
php_fastcgi unix/${config.services.phpfpm.pools."invoiceplane-${hostName}".socket}
|
2024-08-19 10:38:46 +00:00
|
|
|
'';
|
|
|
|
})
|
2024-06-16 17:45:30 +00:00
|
|
|
) eachSite;
|
|
|
|
};
|
2024-08-19 10:38:46 +00:00
|
|
|
})
|
|
|
|
|
2024-06-16 17:45:30 +00:00
|
|
|
(mkIf (cfg.webserver == "nginx") {
|
|
|
|
services.nginx = {
|
|
|
|
enable = true;
|
|
|
|
virtualHosts = mapAttrs' (
|
2023-11-10 18:48:06 +00:00
|
|
|
hostName: cfg:
|
2024-06-24 20:57:44 +00:00
|
|
|
(nameValuePair hostName {
|
|
|
|
root = pkg hostName cfg;
|
2024-06-16 17:45:30 +00:00
|
|
|
extraConfig = ''
|
|
|
|
index index.php index.html index.htm;
|
2024-08-19 10:38:46 +00:00
|
|
|
|
2024-06-16 17:45:30 +00:00
|
|
|
if (!-e $request_filename){
|
|
|
|
rewrite ^(.*)$ /index.php break;
|
2024-08-19 10:38:46 +00:00
|
|
|
}
|
|
|
|
'';
|
|
|
|
|
2024-06-16 17:45:30 +00:00
|
|
|
locations = {
|
2024-06-24 20:58:37 +00:00
|
|
|
"/setup".extraConfig =
|
2024-08-19 10:38:46 +00:00
|
|
|
let
|
2024-06-24 20:58:37 +00:00
|
|
|
scheme = if config.services.nginx.virtualHosts.${hostName}.forceSSL then "https" else "http";
|
2024-08-19 10:38:46 +00:00
|
|
|
in
|
|
|
|
''
|
2024-06-24 20:58:37 +00:00
|
|
|
rewrite ^(.*)$ ${scheme}://${hostName}/ redirect;
|
2024-08-19 10:38:46 +00:00
|
|
|
'';
|
|
|
|
|
2024-06-16 17:45:30 +00:00
|
|
|
"~ .php$" = {
|
|
|
|
extraConfig = ''
|
|
|
|
fastcgi_split_path_info ^(.+\.php)(/.+)$;
|
|
|
|
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
|
2023-11-10 18:48:06 +00:00
|
|
|
fastcgi_pass unix:${config.services.phpfpm.pools."invoiceplane-${hostName}".socket};
|
2024-06-24 20:57:44 +00:00
|
|
|
include ${config.services.nginx.package}/conf/fastcgi_params;
|
|
|
|
include ${config.services.nginx.package}/conf/fastcgi.conf;
|
2024-08-19 10:38:46 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
2024-06-16 17:45:30 +00:00
|
|
|
})
|
2023-11-10 18:48:06 +00:00
|
|
|
) eachSite;
|
2024-08-19 10:38:46 +00:00
|
|
|
};
|
|
|
|
})
|
2024-06-16 17:45:30 +00:00
|
|
|
|
2023-11-10 18:48:06 +00:00
|
|
|
]);
|
|
|
|
}
|