mob next [ci-skip] [ci skip] [skip ci]

lastFile:tests/tests/think-gtcm.nix
This commit is contained in:
2025-11-25 13:50:09 +07:00
parent 3e95cd0310
commit 81dc138e69
3 changed files with 184 additions and 98 deletions

View File

@@ -13,8 +13,8 @@ let
php = pkgs.php83;
artisan = pkgs.writeShellScript "gtcm" ''
#! #{pkgs.runtimeShell}
artisan = pkgs.writeScriptBin "gtcm" ''
#! ${pkgs.runtimeShell}
cd ${think-gtcm}
sudo() {
if [[ "$USER" != ${cfg.user} ]]; then
@@ -23,11 +23,11 @@ let
exec "$@"
fi
}
sudo ${php} artisan "$@"
sudo ${lib.getExe php} artisan "$@"
'';
artisan-be = pkgs.writeShellScript "gtcm-be" ''
#! #{pkgs.runtimeShell}
cd ${think-gtcm}
artisan-be = pkgs.writeScriptBin "gtcm-be" ''
#! ${pkgs.runtimeShell}
cd ${think-backend-gtcm}
sudo() {
if [[ "$USER" != ${cfg.user} ]]; then
exec /run/wrappers/bin/sudo -u ${cfg.user} "$@"
@@ -35,7 +35,7 @@ let
exec "$@"
fi
}
sudo ${php} artisan "$@"
sudo ${lib.getExe php} artisan "$@"
'';
in
@@ -83,7 +83,7 @@ in
};
settings = lib.mkOption {
lib.type =
type =
with lib.types;
attrsOf (
nullOr (
@@ -133,70 +133,6 @@ in
DB_PASSWORD = "";
}
'';
type = lib.types.submodule {
freeformType = lib.types.attrsOf (
lib.types.oneOf [
lib.types.str
lib.types.int
lib.types.bool
]
);
options = {
DB_CONNECTION = lib.mkOption {
type = lib.types.enum [
"mysql"
];
default = "mysql";
example = "mysql";
description = ''
The type of database you wish to use. only "mysql".
'';
};
DB_HOST = lib.mkOption {
type = lib.types.str;
default = if cfg.settings.DB_CONNECTION == "pgsql" then "/run/postgresql" else "localhost";
defaultText = ''
"localhost" if DB_CONNECTION is "sqlite" or "mysql", "/run/postgresql" if "pgsql".
'';
description = ''
The machine which hosts your database. This is left at the
default value for "mysql" because we use the "DB_SOCKET" option
to connect to a unix socket instead. "pgsql" requires that the
unix socket location be specified here instead of at "DB_SOCKET".
This option does not affect "sqlite".
'';
};
DB_PORT = lib.mkOption {
type = lib.types.nullOr lib.types.int;
default =
if cfg.settings.DB_CONNECTION == "pgsql" then
5432
else if cfg.settings.DB_CONNECTION == "mysql" then
3306
else
null;
defaultText = ''
`null` if DB_CONNECTION is "sqlite", `3306` if "mysql", `5432` if "pgsql"
'';
description = ''
The port your database is listening at. sqlite does not require
this value to be filled.
'';
};
DB_DATABASE = lib.mkOption {
type = lib.types.str;
default = "thinkgreatercm";
};
DB_USERNAME = lib.mkOption {
type = lib.types.str;
default = "thinkgreatercm";
};
DB_PASSWORD = lib.mkOption {
type = lib.types.str;
default = "thinkgreatercm";
};
};
};
};
};
@@ -214,8 +150,8 @@ in
inherit (cfg) user group;
phpPackage = php;
settings = {
"listen.owner" = cfg.user;
"listen.group" = cfg.group;
"listen.owner" = config.services.nginx.user;
"listen.group" = config.services.nginx.group;
"listen.mode" = "0600";
"pm" = lib.mkDefault "dynamic";
"pm.max_children" = lib.mkDefault 10;
@@ -230,6 +166,11 @@ in
'';
};
environment.systemPackages = [
artisan
artisan-be
];
systemd.services.think-gtcm-setup = {
description = "think.greaterchiangmai installation";
requiredBy = [ "phpfpm-think-gtcm.service" ];
@@ -268,7 +209,7 @@ in
throw "unsupported type ${typeOf v}: ${(lib.generators.toPretty { }) v}";
};
};
secretPaths = lib.mapAttrsToList (_: v: v._secret) (lib.filterAttrs (_: isSecret) cfg.config);
secretPaths = lib.mapAttrsToList (_: v: v._secret) (lib.filterAttrs (_: isSecret) cfg.settings);
mkSecretReplacement = file: ''
replace-secret ${
lib.escapeShellArgs [
@@ -300,9 +241,9 @@ in
fi
# migrate & seed db
${php} artisan key:generate --force
${php} artisan migrate --force
${php} artisan config:cache
${lib.getExe php} artisan key:generate --force
${lib.getExe php} artisan migrate --force
${lib.getExe php} artisan config:cache
'';
};
@@ -329,7 +270,7 @@ in
recommendedBrotliSettings = true;
recommendedProxySettings = true;
virtualHosts."${cfg.domain}" = {
root = "${cfg.package}/share/php/think-gtcm/public";
root = "${think-gtcm}/public";
locations = {
"/" = {
index = "index.php";