system-configuration/systems/ene.scm

ene.scm

1
;;; Tyreunom's system administration and configuration tools.
2
;;;
3
;;; Copyright © 2019, 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 bootloader))
20
(use-modules (gnu bootloader u-boot))
21
(use-modules (gnu packages bootloaders))
22
(use-modules (gnu services dns))
23
(use-modules (gnu services mail))
24
(use-modules (gnu services networking))
25
(use-modules (gnu services version-control))
26
(use-modules (gnu services web))
27
(use-modules (gnu system))
28
29
(use-modules (gnu packages libunwind))
30
(use-modules (gnu packages mail))
31
(use-modules (gnu packages web))
32
(use-modules (guix packages))
33
(use-modules (guix utils))
34
35
(use-modules (config certbot) (config dns) (config iptables)
36
             (config mail) (config os) (config static-web)
37
	     (config web)
38
	     (services gitile) (packages gitile))
39
40
;; Copy from (gnu bootloader u-boot)
41
(define install-allwinner-u-boot
42
  #~(lambda (bootloader device mount-point)
43
      (let ((u-boot (string-append bootloader
44
                                   "/libexec/u-boot-sunxi-with-spl.bin")))
45
        (write-file-on-device u-boot (stat:size (stat u-boot))
46
                              device (* 8 1024)))))
47
48
(define u-boot-cubietruck-bootloader
49
  (bootloader
50
    (inherit u-boot-bootloader)
51
    (package u-boot-cubietruck)
52
    (installer install-allwinner-u-boot)))
53
54
(operating-system
55
  (inherit (tyreunom-os "ene"))
56
  (bootloader
57
    (bootloader-configuration
58
      (target "/dev/mmcblk0")
59
      (bootloader u-boot-cubietruck-bootloader)))
60
  (initrd-modules (cons* "sunxi-mmc" "sd_mod" "ahci_sunxi" %base-initrd-modules))
61
  (file-systems (cons (file-system
62
                        (mount-point "/")
63
                        (device "/dev/sda1")
64
                        (type "ext4"))
65
                      %base-file-systems))
66
  (services
67
    (append
68
      (list
69
        (service dhcp-client-service-type)
70
        lepiller-iptables-service
71
        (agetty-service
72
          (agetty-configuration
73
            (extra-options '("-L"))
74
            (baud-rate "115200")
75
            (term "vt100")
76
            (tty "ttyS0")))
77
        (service tor-service-type)
78
        (tor-hidden-service "mail"
79
                            '((25 "127.0.0.1:25")
80
                              (143 "127.0.0.1:143")
81
                              (587 "127.0.0.1:587")
82
                              (993 "127.0.0.1:993")))
83
        (service knot-service-type
84
                 (knot-configuration
85
                   (includes '("/etc/knot/secrets.conf"))
86
                   (acls (list master-acl))
87
                   (remotes (list hermes))
88
                   (zones (list lepiller-master-zone
89
                                ipv4-reverse-master-zone
90
                                ipv6-reverse-master-zone))))
91
        (certbot-service `(("courriel.lepiller.eu" "imap.lepiller.eu")
92
                           ("ene.lepiller.eu" "rennes.lepiller.eu")
93
                           ("avatar.lepiller.eu")
94
                           ("git.lepiller.eu")
95
			   ("social.lepiller.eu")))
96
        (service nginx-service-type)
97
        (service php-fpm-service-type)
98
        (service fcgiwrap-service-type
99
                 (fcgiwrap-configuration
100
                   (group "git")))
101
        (cat-avatar-generator-service
102
          #:configuration
103
          (nginx-server-configuration
104
            (server-name '("avatar.lepiller.eu"))
105
            (ssl-certificate
106
              "/etc/letsencrypt/live/avatar.lepiller.eu/fullchain.pem")
107
            (ssl-certificate-key
108
              "/etc/letsencrypt/live/avatar.lepiller.eu/privkey.pem")
109
            (listen '("443 ssl http2" "[::]:443 ssl http2"))))
110
        (simple-service 'default-http-server nginx-service-type
111
          (list (nginx-server-configuration
112
                  (ssl-certificate
113
                    "/etc/letsencrypt/live/ene.lepiller.eu/fullchain.pem")
114
                  (ssl-certificate-key
115
                    "/etc/letsencrypt/live/ene.lepiller.eu/privkey.pem")
116
                  (listen '("443 ssl http2" "[::]:443 ssl http2"))
117
                  (server-name '(default))(root "/srv/http/default"))))
118
        (simple-service 'social-http-server nginx-service-type
119
          (list (nginx-server-configuration
120
                  (ssl-certificate "/etc/letsencrypt/live/social.lepiller.eu/fullchain.pem")
121
                  (ssl-certificate-key "/etc/letsencrypt/live/social.lepiller.eu/privkey.pem")
122
                  (listen '("443 ssl http2" "[::]:443 ssl http2"))
123
                  (server-name '("social.lepiller.eu"))
124
                  (root "/srv/http/social/public")
125
                  (locations
126
                    (list
127
		      (nginx-location-configuration
128
			(uri "/content/")
129
			(body '("alias /var/lib/social/user-data/public/;")))
130
                      (nginx-location-configuration
131
                        (uri "/")
132
                        (body '("proxy_pass http://localhost:8081;")))))
133
                  (raw-content default-web-policy))))
134
	(service gitile-service-type)
135
        (simple-service 'git-server nginx-service-type
136
          (list (nginx-server-configuration
137
                  (ssl-certificate
138
                    "/etc/letsencrypt/live/git.lepiller.eu/fullchain.pem")
139
                  (ssl-certificate-key
140
                    "/etc/letsencrypt/live/git.lepiller.eu/privkey.pem")
141
                  (listen '("443 ssl http2" "[::]:443 ssl http2"))
142
                  (server-name '("git.lepiller.eu"))
143
                  (root "/srv/http/git/public")
144
                  (locations
145
                    (append
146
                      (list
147
                        (git-http-nginx-location-configuration
148
                          (git-http-configuration
149
                            (uri-path "/git/")
150
                            (git-root "/var/lib/gitolite/repositories")))
151
                        (nginx-location-configuration
152
                          (uri "/")
153
                          (body
154
                            (list
155
                              "proxy_pass http://127.0.0.1:8080/;"))))
156
                      (map
157
                        (lambda (loc)
158
                          (nginx-location-configuration
159
                            (uri loc)
160
                            (body
161
                              (list
162
                                "root /srv/http/git/public;"))))
163
                        '("/css" "/images" "~* .*/manual/.*" "= /"
164
                          "= /index.html")))))))
165
        (service static-web-site-service-type
166
                 (static-web-site-configuration
167
                  (git-url "https://git.lepiller.eu/git/guile-netlink")
168
                  (git-ref '(branch . "master"))
169
                  (directory "/srv/http/git/guile-netlink-manual")
170
                  (build-file "doc/build.scm")))
171
        ;; on activation, gitolite chmods its home directory to #o700, disabling
172
        ;; access to git-http-backend.  Re-enable that access.
173
        (simple-service 'gitolite-home-permissions
174
                        activation-service-type
175
                        #~(chmod "/var/lib/gitolite" #o750))
176
        (service gitolite-service-type
177
          (gitolite-configuration
178
            (admin-pubkey (local-file "../keys/tyreunom.pub"))
179
            (rc-file
180
              (gitolite-rc-file
181
                (umask #o0027)
182
                (git-config-keys ".*"))))))
183
      (modify-services
184
        (lepiller-mail-services
185
          #:interface "eth0"
186
          #:domain "courriel.lepiller.eu")
187
        (dovecot-service-type config =>
188
         (dovecot-configuration
189
           (inherit config)
190
           (dovecot (package
191
                      (inherit dovecot)
192
                      (arguments
193
                        `(#:tests? #f
194
                          ,@(package-arguments dovecot))))))))
195
      (server-services "ene"))))
196