summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorstuebinm2023-04-01 02:54:35 +0200
committerstuebinm2023-04-01 02:54:35 +0200
commitf4f3f7d0ad49cfb9d73061997523f69c31716739 (patch)
tree25fb76ce0d043e59100c46860425791aedbcd3ef /modules
parent15c29107417f4c82e534c757a69d36101c506a2a (diff)
add module for crs-tracker, for fun
please no one like, actually use this. unless you volunteer to at least add a script to run database migrations, since currently these need to be run by hand …
Diffstat (limited to 'modules')
-rw-r--r--modules/crs-tools.nix132
1 files changed, 132 insertions, 0 deletions
diff --git a/modules/crs-tools.nix b/modules/crs-tools.nix
new file mode 100644
index 0000000..fb43136
--- /dev/null
+++ b/modules/crs-tools.nix
@@ -0,0 +1,132 @@
+{ config, lib, pkgs, modulesPath, ... }:
+
+with lib;
+
+let
+ cfg = config.services.crs-tracker;
+ configFile = pkgs.writeText "crs-tracker-config.php" ''
+ <?php
+ Log::setPath(ROOT . '../log/application.log');
+ Log::setLevel(Log::INFO);
+ Log::colorize(true);
+
+ Database_PostgreSQL::init(
+ '${cfg.dbHost}',
+ '${cfg.dbUsername}',
+ '${cfg.dbPassword}',
+ '${cfg.dbDatabase}'
+ );
+
+ // TODO: make timezone a user setting or get it from browser
+ Database::$Instance->query(
+ 'SET timezone = ' . Database::$Instance->quote(date_default_timezone_get())
+ );
+
+ requires('Cache/Adapter/APC');
+ Cache::setAdapter(new Cache_Adapter_APC());
+
+ session_set_cookie_params(0, '/', null, false, true);
+
+ libxml_disable_entity_loader(true);
+ ?>
+ '';
+ tracker = pkgs.stdenv.mkDerivation {
+ src = pkgs.crs-tools.tracker;
+ name = "tracker-with-config";
+ buildPhase = ''
+ mkdir $out
+ cp -r $src/* $out
+ chmod +w $out/src/Config/
+ ln -s ${configFile} $out/src/Config/Config.php
+ '';
+ phases = [ "buildPhase" ];
+ };
+in {
+ options.services.crs-tracker = {
+ enable = mkOption {
+ type = types.bool;
+ default = false;
+ description = "tracker fahren.";
+ };
+
+ dbHost = mkOption {
+ type = types.str;
+ default = "localhost";
+ description =
+ "domain the database runs on. This must be a postgres < 12.";
+ };
+
+ dbUsername = mkOption {
+ type = types.str;
+ default = "crstracker";
+ };
+
+ dbPassword = mkOption {
+ type = types.str;
+ default = "";
+ };
+
+ dbDatabase = mkOption {
+ type = types.str;
+ default = "crstracker";
+ };
+
+ nginxVirtualHostConfig = mkOption {
+ type = types.submodule (import "${modulesPath}/services/web-servers/nginx/vhost-options.nix" {
+ inherit config lib;
+ });
+ default = {};
+ };
+ };
+
+ config = mkIf cfg.enable {
+
+ services.phpfpm = {
+ pools.crs-tracker = {
+ phpPackage = pkgs.crs-tools.php;
+ user = "crs-tools";
+ group = "crs-tools";
+ settings = {
+ "listen.owner" = config.services.nginx.user;
+ "listen.group" = config.services.nginx.group;
+ "pm" = "dynamic";
+ "pm.max_children" = "32";
+ "pm.start_servers" = "2";
+ "pm.min_spare_servers" = "2";
+ "pm.max_spare_servers" = "4";
+ "pm.max_requests" = "500";
+ "access.log" = "/var/log/$pool.access.log";
+ };
+ };
+ };
+ users.users.crs-tools = {
+ group = "crs-tools";
+ isSystemUser = true;
+ home = tracker.outPath;
+ };
+ users.groups.crs-tools.members = [ "crs-tools" ];
+
+ services.nginx = {
+ enable = mkDefault true;
+
+ virtualHosts."crs-tools" = cfg.nginxVirtualHostConfig // {
+ root = "${tracker}/src/Public";
+ locations."~ ^/(downloads|css|images|thumbnails|javascript|fahrplan)/".priority = 900;
+ locations."/" = {
+ extraConfig = ''
+ # include ${config.services.nginx.package}/conf/fastcgi.conf;
+ include ${config.services.nginx.package}/conf/fastcgi_params;
+ fastcgi_split_path_info ^(.+?)(\\/.*)$;
+ fastcgi_param PATH_INFO $fastcgi_path_info;
+ fastcgi_param SCRIPT_FILENAME $document_root/index.php;
+ fastcgi_index index.php;
+ fastcgi_pass unix:${config.services.phpfpm.pools.crs-tracker.socket};
+ # remove trailing slash
+ rewrite ^(.+)/$ $1 permanent;
+ rewrite ^(.*)$ /index.php$1 break;
+ '';
+ };
+ };
+ };
+ };
+}