system-configuration/systems/xana.scm

xana.scm

1
;;; Tyreunom's system administration and configuration tools.
2
;;;
3
;;; Copyright © 2020 Julien Lepiller <julien@lepiller.eu>
4
;;;
5
;;; This program is free software: you can redistribute it and/or modify
6
;;; it under the terms of the GNU General Public License as published by
7
;;; the Free Software Foundation, either version 3 of the License, or
8
;;; (at your option) any later version.
9
;;;
10
;;; This program is distributed in the hope that it will be useful,
11
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
;;; GNU General Public License for more details.
14
;;;
15
;;; You should have received a copy of the GNU General Public License
16
;;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18
(use-modules (gnu))
19
(use-modules (gnu system))
20
(use-modules (gnu bootloader) (gnu bootloader grub))
21
(use-modules (gnu services mcron))
22
(use-modules (gnu services networking))
23
(use-modules (gnu services web))
24
(use-modules (config certbot) (config cuirass) (config network) (config os))
25
(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)))
49
50
(define i18n-download-job
51
  #~(job '(next-minute-from (next-hour '(05)) '(51))
52
         #$(makefile-job "/srv/http/i18n" "fdroid-update"
53
                         (list gnu-make coreutils findutils git)
54
			 '())))
55
56
(define i18n-compile-job
57
  #~(job '(next-minute-from (next-hour '(06)) '(21))
58
         #$(makefile-job "/srv/http/i18n" "all"
59
                         (list gnu-make coreutils findutils git grep util-linux)
60
			 '())))
61
62
(define nani-download-job
63
  #~(job '(next-minute-from (next-hour-from (next-day (range 1 31 5)) '(02)) '(12))
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
			 '())))
68
69
(define nani-update-job
70
  #~(job '(next-minute-from (next-hour-from (next-day (range 1 31 5)) '(03)) '(12))
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")))))
76
77
(operating-system
78
  (inherit (tyreunom-os "xana"))
79
  (bootloader
80
    (bootloader-configuration
81
      (target "/dev/sda")
82
      (bootloader grub-bootloader)))
83
  (file-systems (cons (file-system
84
                        (mount-point "/")
85
                        (device (uuid "27207be8-f30a-4ac6-a5ec-41859e90ee94"))
86
                        (type "ext4"))
87
                      %base-file-systems))
88
  (swap-devices '("/dev/sda1"))
89
  (services
90
    (append
91
      (list
92
        (service dhcp-client-service-type)
93
        (service nginx-service-type)
94
        (simple-service 'website-cron mcron-service-type
95
          (list i18n-download-job i18n-compile-job
96
                nani-download-job nani-update-job))
97
        (certbot-service `(("xana.lepiller.eu")
98
                           ("nani.lepiller.eu")
99
			   ("i18n.lepiller.eu")))
100
        (simple-service 'nani-http-server nginx-service-type
101
          (list (nginx-server-configuration
102
                  (ssl-certificate
103
                    "/etc/letsencrypt/live/nani.lepiller.eu/fullchain.pem")
104
                  (ssl-certificate-key
105
                    "/etc/letsencrypt/live/nani.lepiller.eu/privkey.pem")
106
                  (listen '("443 ssl http2" "[::]:443 ssl http2"))
107
                  (server-name '("nani.lepiller.eu"))
108
                  (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"))))
118
        (simple-service 'default-http-server nginx-service-type
119
          (list (nginx-server-configuration
120
                  (ssl-certificate
121
                    "/etc/letsencrypt/live/xana.lepiller.eu/fullchain.pem")
122
                  (ssl-certificate-key
123
                    "/etc/letsencrypt/live/xana.lepiller.eu/privkey.pem")
124
                  (listen '("443 ssl http2" "[::]:443 ssl http2"))
125
                  (server-name '(default "xana.lepiller.eu"))
126
                  (root "/srv/http/default")))))
127
      (modify-services (server-services "xana")
128
        (guix-service-type config =>
129
          (guix-configuration
130
            (inherit config)
131
            (substitute-urls '("https://guix.lepiller.eu" "https://ci.guix.gnu.org"))))))))
132