From d6442ddc72568998dc9cf7a513b5e3c350ae64f6 Mon Sep 17 00:00:00 2001 From: jdlugosz963 Date: Fri, 22 Dec 2023 22:19:21 +0100 Subject: Add basic functionality to hwp builder. --- hipis.scm | 17 +++------ hipis/packages/source/hwp/hwp.scm | 21 +++++++---- hipis/packages/source/hwp/hwp/download.scm | 20 ++++++++++ hipis/services/web.scm | 59 +++++++++++++++++++++++------- 4 files changed, 85 insertions(+), 32 deletions(-) create mode 100644 hipis/packages/source/hwp/hwp/download.scm diff --git a/hipis.scm b/hipis.scm index 411f839..e3f4b93 100755 --- a/hipis.scm +++ b/hipis.scm @@ -146,22 +146,15 @@ (ssl-certificate (letsencrypt-certificate "jdlugosz.com")) (ssl-certificate-key (letsencrypt-key "jdlugosz.com"))))))) - (service nginx-service-type - (nginx-configuration - (server-blocks - (list - (nginx-server-configuration - (server-name '("jdlugosz.com")) - (listen '("443 ssl")) - (ssl-certificate (letsencrypt-certificate "jdlugosz.com")) - (ssl-certificate-key (letsencrypt-key "jdlugosz.com")) - (root "/srv/http/jdlugosz.com")))))) - (service quassel-service-type) (service hwp-service-type (hwp-site-configuration - (name "hwp-base"))) + (name "hwp-base") + (domains '("jdlugosz.com")) + (source-url "https://git.jdlugosz.com/hipis/hipis-website/snapshot/hipis-website-master.tar.gz") + (ssl-certificate (letsencrypt-certificate "jdlugosz.com")) + (ssl-certificate-key (letsencrypt-key "jdlugosz.com")))) (modify-services %base-services (delete static-networking-service-type)))) diff --git a/hipis/packages/source/hwp/hwp.scm b/hipis/packages/source/hwp/hwp.scm index 6770b5b..c497538 100644 --- a/hipis/packages/source/hwp/hwp.scm +++ b/hipis/packages/source/hwp/hwp.scm @@ -1,13 +1,20 @@ (define-module (hwp) #:use-module (hwp site) + #:use-module (hwp download) #:use-module (hwp ui) #:use-module (ice-9 match) - #:export (hwp-run)) + #:export (hwp-build + hwp-run)) + + +(define (hwp-build url dest) + (define website-source-dir (download-curl url "/tmp")) + (hipis-site website-source-dir dest)) (define (hwp-run args) - (match args - ((cmd) - (display "To create site: hwp-build [input-path] [output-path]") - (newline)) - ((cmd in out) - (hipis-site in out)))) + (match args + ((cmd) + (display "To create site: hwp-build [input-path] [output-path]") + (newline)) + ((cmd in out) + (hipis-site in out)))) diff --git a/hipis/packages/source/hwp/hwp/download.scm b/hipis/packages/source/hwp/hwp/download.scm new file mode 100644 index 0000000..be4f292 --- /dev/null +++ b/hipis/packages/source/hwp/hwp/download.scm @@ -0,0 +1,20 @@ +(define-module (hwp download) + #:export (download-curl)) + + +(define (download-curl url dest) + (define file-name (basename url)) + (define compressed-file (string-append "/tmp/" file-name)) + + (when (not (= (system* "curl" url "-o" compressed-file) 0)) + (error (string-append "Error: cannot download file: " url))) + + (cond + ((or (string-suffix? "tar.gz" file-name) + (string-suffix? "tar.xz" file-name)) + (if (not (= (system* "tar" "-C" dest "-x" "-f" compressed-file) 0)) + (error (format #f "Error: when trying to decompress file: ~a in destination: ~a" + compressed-file dest)) + (string-append dest "/" (string-drop-right file-name 7)))) + (#t (error (string-append "Error: file with unspuported format: " dest))))) + diff --git a/hipis/services/web.scm b/hipis/services/web.scm index 52cc6db..e7d2ce5 100644 --- a/hipis/services/web.scm +++ b/hipis/services/web.scm @@ -18,6 +18,7 @@ #:use-module (gnu packages guile) #:use-module (guix git-download) #:use-module (gnu services) + #:use-module (gnu services web) #:use-module (gnu services guix) #:use-module (hipis packages web) @@ -26,24 +27,51 @@ hwp-site-configuration)) +;; (define %hwp-configuration-nginx +;; (nginx-server-configuration)) + (define-record-type* hwp-theme-configuration make-hwp-theme-configuration hwp-theme-configuration-configuration? (primary-color hwp-theme-configuration-primary-color - (default "#000"))) + (default "#000")) + (secondary-color hwp-theme-configuration-primary-color + (default "#000"))) (define-record-type* hwp-site-configuration make-hwp-theme-configuration hwp-site-configuration-configuration? - (name hwp-site-configuration-name) - (theme hwp-site-configuration-theme - (default #nil))) + (name hwp-site-configuration-name) + (domains hwp-site-configuration-domain) + (source-url hwp-site-configuration-source-url) + (ssl-certificate hwp-site-configuration-nginx + (default #f)) + (ssl-certificate-key hwp-site-configuration-nginx + (default #f)) + (theme hwp-site-configuration-theme + (default #nil))) + +(define hwp-directory "/var/lib/hwp/") +(define (hwp-site-configuration->site-build-dir config) + (string-append hwp-directory "www/" (hwp-site-configuration-name config))) +(define (hwp-nginx-server-configurations config) + (match-record config + (name domains ssl-certificate ssl-certificate-key) + (list + (nginx-server-configuration + (server-name domains) + (listen '("443 ssl")) + (ssl-certificate ssl-certificate) + (ssl-certificate-key ssl-certificate-key) + (root (hwp-site-configuration->site-build-dir config)) + )))) (define (make-hwp-start-script config) (match-record config - (name) - (program-file (string-append "hwp-" name) + (name domains) + (program-file + (string-append "build-" name) (with-extensions (cons hipis-web-site (map cadr @@ -51,26 +79,31 @@ (package-propagated-inputs hipis-web-site)))) #~(begin (use-modules (hwp)) - (hwp-run '(_ "/tmp/in" "/tmp/out"))))))) + (hwp-build #$(hwp-site-configuration-source-url config) + #$(hwp-site-configuration->site-build-dir config))))))) (define (hwp-activation config) (match-record config - (name theme) - (let* ((hwp-directory "/var/lib/hwp") - (hwp-site-script (string-append hwp-directory "/hwp-" name)) - (message (string-append "Script for building websites is generated in: " + (name) + (let* ((hwp-site-script (string-append hwp-directory "/hwp-" name)) + (message (string-append "Script for building website is generated: " hwp-site-script))) (with-imported-modules '((guix build utils)) #~(begin (use-modules (guix build utils)) (mkdir-p #$hwp-directory) - (copy-file #$(make-hwp-start-script config) #$hwp-site-script) + (mkdir-p #$(hwp-site-configuration->site-build-dir config)) + (copy-file #$(make-hwp-start-script config) + #$hwp-site-script) (display #$message)))))) + (define hwp-service-type (service-type (name 'hwp) (extensions - (list (service-extension activation-service-type + (list (service-extension nginx-service-type + hwp-nginx-server-configurations) + (service-extension activation-service-type hwp-activation))) (description "hipis-web-page: Automatically build guile haunt pages."))) -- cgit v1.2.3