From f4f3f7d0ad49cfb9d73061997523f69c31716739 Mon Sep 17 00:00:00 2001 From: stuebinm Date: Sat, 1 Apr 2023 02:54:35 +0200 Subject: 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 … --- modules/crs-tools.nix | 132 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 modules/crs-tools.nix (limited to 'modules/crs-tools.nix') 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" '' + 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; + ''; + }; + }; + }; + }; +} -- cgit v1.2.3