Refactor cron jobs to use a common helper function

Julien LepillerSat Aug 22 00:38:06+0200 2020

d89c594

Refactor cron jobs to use a common helper function

systems/xana.scm

2222
(use-modules (gnu services networking))
2323
(use-modules (gnu services web))
2424
(use-modules (config certbot) (config cuirass) (config network) (config os))
25-
(use-modules (gnu packages base))
2625
(use-modules (guix gexp))
26+
(use-package-modules base compression gettext guile guile-xyz linux version-control
27+
		     wget)
28+
29+
(define (makefile-job directory target packages env)
30+
  #~(lambda ()
31+
      (define path
32+
        (string-join
33+
          (map (lambda (p) (string-append p "/bin")) (list #$@packages))
34+
          ":"))
35+
      (define (get-path dir)
36+
	(string-join
37+
	  (map (lambda (p) (string-append p "/" path) (list #$@packages)))
38+
	  ":"))
39+
      (setenv "PATH" path)
40+
      (setenv "GIT_SSL_CAINFO" "/etc/ssl/certs/ca-certificates.crt")
41+
      (setenv "SSL_CERT_DIR" "/etc/ssl/certs")
42+
      (setenv "SSL_CERT_FILE" "/etc/ssl/certs/ca-certificates.crt")
43+
      (setenv "LANG" "en_US.UTF-8")
44+
      (for-each
45+
	(lambda (env)
46+
	 (setenv (car env) (get-path (cdr env))))
47+
	(quote #$env))
48+
      (execl #$(file-append gnu-make "/bin/make") "make" "-C" #$directory #$target)))
2749
2850
(define i18n-download-job
2951
  #~(job '(next-minute-from (next-hour '(05)) '(51))
30-
         (lambda ()
31-
           (execl #$(file-append gnu-make "/bin/make")
32-
                  "-C" "/srv/http/i18n" "fdroid-update"))))
52+
         #$(makefile-job "/srv/http/i18n" "fdroid-update"
53+
                         (list gnu-make coreutils findutils git)
54+
			 '())))
3355
3456
(define i18n-compile-job
3557
  #~(job '(next-minute-from (next-hour '(06)) '(21))
36-
         (lambda ()
37-
           (execl #$(file-append gnu-make "/bin/make")
38-
                  "-C" "/srv/http/i18n"))))
58+
         #$(makefile-job "/srv/http/i18n" "all"
59+
                         (list gnu-make coreutils findutils git grep util-linux)
60+
			 '())))
3961
4062
(define nani-download-job
4163
  #~(job '(next-minute-from (next-hour-from (next-day (range 1 31 5)) '(02)) '(12))
42-
         (lambda ()
43-
           (execl #$(file-append gnu-make "/bin/make")
44-
                  "-C" "/srv/http/nani" "download"))))
64+
         #$(makefile-job "/srv/http/nani" "download"
65+
                         (list gnu-make coreutils findutils grep gzip libiconv
66+
			       sed tar unzip util-linux wget xz)
67+
			 '())))
4568
4669
(define nani-update-job
4770
  #~(job '(next-minute-from (next-hour-from (next-day (range 1 31 5)) '(03)) '(12))
48-
         (lambda ()
49-
           (execl #$(file-append gnu-make "/bin/make")
50-
                  "-C" "/srv/http/nani" "download"))))
71+
         #$(makefile-job "/srv/http/nani" "all"
72+
                         (list gnu-make coreutils findutils gnu-gettext grep guile-3.0
73+
			       haunt sed)
74+
			 '(("GUILE_LOAD_PATH" . "share/guile/site/3.0")
75+
			   ("GUILE_LOAD_COMPILED_PATH" . "share/guile/site/3.0")))))
5176
5277
(operating-system
5378
  (inherit (tyreunom-os "xana"))

6691
      (list
6792
        (service dhcp-client-service-type)
6893
        (service nginx-service-type)
69-
        (simple-service 'i18n-cron mcron-service-type
94+
        (simple-service 'website-cron mcron-service-type
7095
          (list i18n-download-job i18n-compile-job
7196
                nani-download-job nani-update-job))
7297
        (certbot-service `(("xana.lepiller.eu")
73-
                           ("nani.lepiller.eu")))
98+
                           ("nani.lepiller.eu")
99+
			   ("i18n.lepiller.eu")))
74100
        (simple-service 'nani-http-server nginx-service-type
75101
          (list (nginx-server-configuration
76102
                  (ssl-certificate

80106
                  (listen '("443 ssl http2" "[::]:443 ssl http2"))
81107
                  (server-name '("nani.lepiller.eu"))
82108
                  (root "/srv/http/nani/public"))))
109+
        (simple-service 'i18n-http-server nginx-service-type
110+
          (list (nginx-server-configuration
111+
                  (ssl-certificate
112+
                    "/etc/letsencrypt/live/i18n.lepiller.eu/fullchain.pem")
113+
                  (ssl-certificate-key
114+
                    "/etc/letsencrypt/live/i18n.lepiller.eu/privkey.pem")
115+
                  (listen '("443 ssl http2" "[::]:443 ssl http2"))
116+
                  (server-name '("i18n.lepiller.eu"))
117+
                  (root "/srv/http/i18n/public"))))
83118
        (simple-service 'default-http-server nginx-service-type
84119
          (list (nginx-server-configuration
85120
                  (ssl-certificate