1(define-module (nmeum services web)2 #:use-module (guix gexp)3 #:use-module (gnu packages admin)4 #:use-module (gnu packages web)5 #:use-module (gnu services)6 #:use-module (gnu services base)7 #:use-module (gnu services configuration)8 #:use-module (gnu services shepherd)9 #:use-module (gnu system accounts)10 #:use-module (gnu system shadow)11 #:use-module (srfi srfi-1)12 #:use-module (srfi srfi-26)13 #:export (sogogi-service-type14 sogogi-configuration15 sogogi-config-file16 sogogi-configuration-fields17 sogogi-configuration?18 sogogi-user19 sogogi-user?20 sogogi-location21 sogogi-location?))2223(define (sosogi-serialize-section section-name value fields)24 (let ((first-field (car fields)))25 #~(format #f "~a ~a {~%~a}~%"26 #$(object->string section-name)27 #$((configuration-field-getter first-field) value)28 #$(serialize-configuration value (cdr fields)))))2930(define (sogogi-serialize-field field-name value)31 (let ((field (object->string field-name)))32 #~(format #f "~a ~a~%" #$field #$value)))3334(define sogogi-serialize-string sogogi-serialize-field)35(define (sogogi-serialize-list-of-strings field-name value)36 #~(string-append37 #$@(map (cut sogogi-serialize-string field-name <>)38 value)))3940(define-maybe string (prefix sogogi-))41(define-maybe list-of-strings (prefix sogogi-))4243(define-configuration sogogi-user44 (name45 maybe-string46 "Name of the user.")4748 (password49 maybe-string50 "Password of the user.")5152 (prefix sogogi-))5354(define (sogogi-serialize-sogogi-user field-name value)55 (sosogi-serialize-section field-name value sogogi-user-fields))5657(define-configuration sogogi-location58 (path59 string60 "HTTP path at which the directory will be exposed.")6162 (dir63 string64 "Path to local directory to serve.")6566 (grant67 maybe-list-of-strings68 "Grant remote users access to the directory.")6970 (prefix sogogi-))7172(define (sogogi-serialize-sogogi-location field-name value)73 (sosogi-serialize-section field-name value sogogi-location-fields))7475(define (sogogi-serialize-list-of-sogogi-location field-name value)76 #~(string-append #$@(map (cut sogogi-serialize-sogogi-location field-name <>) value)))7778(define (sogogi-serialize-list-of-sogogi-user field-name value)79 #~(string-append #$@(map (cut sogogi-serialize-sogogi-user field-name <>) value)))8081(define list-of-sogogi-user? (list-of sogogi-user?))82(define list-of-sogogi-location? (list-of sogogi-location?))8384(define-configuration sogogi-configuration85 (listen86 (string "localhost:8080")87 "Listening address.")8889 (location90 (list-of-sogogi-location '())91 "Local directories to expose via a HTTP path")9293 (user94 (list-of-sogogi-user '())95 "Users with access to the location.")9697 (prefix sogogi-))9899(define (sogogi-config-file config)100 (mixed-text-file "sogogi.conf"101 (serialize-configuration102 config103 sogogi-configuration-fields)))104105(define (sogogi-shepherd-service config)106 (let ((config-file (sogogi-config-file config)))107 (list (shepherd-service108 (documentation "Sogogi daemon.")109 (provision '(sogogi))110 ;; sogogi may be bound to a particular IP address, hence111 ;; only start it after the networking service has started.112 (requirement '(user-processes networking))113 (actions (list (shepherd-configuration-action config-file)))114 (start #~(make-forkexec-constructor115 (list (string-append #$sogogi "/bin/sogogi")116 "-config" #$config-file)))117 (stop #~(make-kill-destructor))))))118119(define sogogi-account-service120 (list (user-group (name "sogogi") (system? #t))121 (user-account122 (name "sogogi")123 (group "sogogi")124 (system? #t)125 (comment "Sogogi daemon user")126 (home-directory "/var/empty")127 (shell (file-append shadow "/sbin/nologin")))))128129(define sogogi-service-type130 (service-type (name 'sogogi)131 (description "Run the sogogi WebDAV server.")132 (extensions133 (list (service-extension account-service-type134 (const sogogi-account-service))135 (service-extension shepherd-root-service-type136 sogogi-shepherd-service)))137 (compose concatenate)138 (default-value (sogogi-configuration))))139140;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;141142(define (go-webdav-shepherd-service args)143 (list (shepherd-service144 (documentation "go-webdav daemon.")145 (provision '(go-webdav))146 ;; go-webdav may be bound to a particular IP address, hence147 ;; only start it after the networking service has started.148 (requirement '(user-processes networking))149 (start #~(make-forkexec-constructor150 (list (string-append #$go-webdav "/bin/webdav-server")151 #$@args)))152 (stop #~(make-kill-destructor)))))153154(define go-webdav-account-service155 (list (user-group (name "go-webdav") (system? #t))156 (user-account157 (name "go-webdav")158 (group "go-webdav")159 (system? #t)160 (comment "go-webdav daemon user")161 (home-directory "/var/empty")162 (shell (file-append shadow "/sbin/nologin")))))163164(define-public go-webdav-service-type165 (service-type (name 'go-webdav)166 (description "Run the go-webdav WebDAV server.")167 (extensions168 (list (service-extension account-service-type169 (const go-webdav-account-service))170 (service-extension shepherd-root-service-type171 go-webdav-shepherd-service)))172 (compose concatenate)173 (default-value '("-addr" "127.0.0.1:8080"))))