;; SPDX-License-Identifier: CC0-1.0 ;; Copyright (C) 2022 Wojtek Kosior ;; ;; Available under the terms of Creative Commons Zero v1.0 Universal. (use-modules (gnu) (koszko-org-website) (hydrilla-website) (hydrilla-json-schemas) (hydrilla) ;; The following 4 are needed to construct GUIX_PYTHONPATH for ;; Hydrilla WSGI scripts. (guix build-system python) (guix packages) (guix search-paths) (guix modules)) (use-package-modules web) (use-package-modules python) (use-service-modules web) (use-service-modules shepherd) (define %here (getcwd)) (define* (simple-wsgi-alias-gexp package wsgi-path #:key (aliased-path "/")) #~(let* ((wsgi-file (string-append #$package #$wsgi-path))) (format #f "\ Require all granted WSGIScriptAlias ~a ~a " wsgi-file #$aliased-path wsgi-file))) (define %koszko-org-virtualhost (httpd-virtualhost "*:80" (list "\ ServerName koszko.org ServerAlias www.koszko.org DocumentRoot /srv/http/koszko.org ServerAdmin koszko@koszko.org Redirect permanent / http://koszko.org/ Alias /sideload /srv/http/koszko.org WSGIScriptReloading On " (simple-wsgi-alias-gexp koszko-org-website "/share/koszko-org-website/wsgi.py")))) (define %koszkonutek-tmp-virtualhost (httpd-virtualhost "*:80" '("\ ServerName koszkonutek-tmp.pl.eu.org ServerAlias www.koszkonutek-tmp.pl.eu.org Redirect permanent / http://koszko.org/ "))) (define %hydrillabugs-virtualhost (httpd-virtualhost "*:80" '("\ ServerName hydrillabugs.koszko.org ServerAlias www.hydrillabugs.koszko.org ServerAdmin koszko@koszko.org Redirect permanent /projects/hachette /projects/haketilo # I don't remember why I added the following line so I'm keeping it just # in case. RequestHeader unset Accept-Encoding ProxyPass /projects/haketilo http://10.207.87.1:21011/projects/hachette ProxyPassReverse /projects/haketilo http://10.207.87.1:21011/projects/hachette ProxyPass / http://10.207.87.1:21011/ ProxyPassReverse / http://10.207.87.1:21011/ "))) (define %hachettebugs-virtualhost (httpd-virtualhost "*:80" '("\ ServerName hachettebugs.koszko.org ServerAlias www.hachettebugs.koszko.org Redirect permanent / http://hydrillabugs.org/ "))) (define %haketilo-virtualhost (httpd-virtualhost "*:80" (list "\ ServerName haketilo.koszko.org ServerAlias www.haketilo.koszko.org ServerAdmin koszko@koszko.org Redirect permanent / http://haketilo.koszko.org/ WSGIScriptReloading On " (simple-wsgi-alias-gexp hydrilla-website "/share/hydrilla-website/wsgi.py")))) (define %python-path-spec-sexp (search-path-specification->sexp (guix-pythonpath-search-path (package-version (default-python))))) (define %hydrilla-pythonpath-inputs (cons hydrilla (map cadr (package-transitive-target-inputs hydrilla)))) (define %hydrilla-pythonpath-gexp (with-imported-modules (source-module-closure '((guix search-paths))) #~(begin (use-modules (guix search-paths)) (let ((evaluated-list (evaluate-search-paths (list (sexp->search-path-specification '#$%python-path-spec-sexp)) '#$%hydrilla-pythonpath-inputs))) (cdar evaluated-list))))) (define %hydrilla-wsgi-regex "^/api_v[^/]+/((resource|mapping)/[^/]+[.]json|query|list_all)$") (define %hydrilla-virtualhost (httpd-virtualhost "*:80" (list "\ ServerName hydrilla.koszko.org ServerAlias www.hydrilla.koszko.org ServerAdmin koszko@koszko.org Redirect permanent / http://hydrilla.koszko.org/ " #~(format #f "Alias /schemas ~a\n" (string-append #$hydrilla-json-schemas "/share/hydrilla-json-schemas")) "\ DocumentRoot /var/lib/hydrilla/malcontent_dirs ForceType application/json WSGIScriptReloading On " (format #f "SetEnvIf Request_URI ~s MALCONENT_DIR=~a\n" "^/(api_v[0-9]+)/" "/var/lib/hydrilla/malcontent_dirs/$1") #~(format #f "SetEnvIf Request_URI ~s HYDRILLA_GUIX_PYTHONPATH=~a\n" "^/api_v[0-9]+/" #$%hydrilla-pythonpath-gexp) #~(format #f "WSGIScriptAliasMatch ~s ~a\n" #$%hydrilla-wsgi-regex (string-append #$(local-file (string-append %here "/hydrilla-wsgi.py")) "/$1"))))) (define %wsgi-module (httpd-module (name "wsgi_module") (file (file-append mod-wsgi "/modules/mod_wsgi.so")))) (define %proxy-http-modules (list (httpd-module (name "proxy_module") (file (file-append httpd "/modules/mod_proxy.so"))) (httpd-module (name "proxy_http_module") (file (file-append httpd "/modules/mod_proxy_http.so"))))) ;; logio is needed for the '%O' log format directive (define %logio-module (httpd-module (name "logio_module") (file (file-append httpd "/modules/mod_logio.so")))) (define %logformat-combined "\"%h %l %u %t \\\"%r\\\" %>s %O \\\"%{Referer}i\\\" \\\"%{User-Agent}i\\\"\"") (define %koszko-httpd-service (service httpd-service-type (httpd-configuration (config (httpd-config-file (server-name "koszko.org") (error-log "/var/log/httpd/error.log") (modules `(,%wsgi-module ,@%proxy-http-modules ,%logio-module ,@%default-httpd-modules)) (extra-config (list (string-join `("LogFormat" ,%logformat-combined "combined")) "\n" "CustomLog /var/log/httpd/access.log combined" "\n" ))))))) (operating-system (host-name "koszko") (timezone "Europe/Warsaw") (groups (cons* (user-group ;; The `httpd` group must have an explicit id so that the host ;; can provide files that are readable by Apache and not ;; readable by the world. (name "httpd") (id 133) (system? #t)) %base-groups)) (file-systems (cons (file-system (device (file-system-label "does-not-matter")) (mount-point "/") (type "ext4")) %base-file-systems)) (bootloader (bootloader-configuration (bootloader grub-bootloader) (targets '("/dev/sdDOES-NOT-MATTER")))) (services (cons* %koszko-httpd-service (simple-service 'koszko-org-website httpd-service-type (list %koszko-org-virtualhost %koszkonutek-tmp-virtualhost %hydrillabugs-virtualhost %hachettebugs-virtualhost %haketilo-virtualhost %hydrilla-virtualhost)) (service (shepherd-service-type 'dummy-network (const (shepherd-service (documentation "Provide 'networking' without actually doing anything") (provision '(networking)) (start #~(const #t)) (stop #~(const #t)) (respawn? #f))) (description "Make other services assume network is there.")) #f) %base-services)))