hermes.scm
1 | ;;; Tyreunom's system administration and configuration tools. |
2 | ;;; |
3 | ;;; Copyright © 2019 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 dns)) |
22 | (use-modules (gnu services networking)) |
23 | (use-modules (gnu services web)) |
24 | (use-modules (config certbot) (config dns) (config mail) (config network) (config os) |
25 | (config iptables) (config web)) |
26 | |
27 | |
28 | ;; NOTE: this config contains out-of band files. |
29 | ;; To (re-)generate /etc/mail/dkim/private.key, run: |
30 | ;; openssl genrsa -out /etc/mail/dkim/private.key 2048 |
31 | ;; openssl rsa -in /etc/mail/dkim/private.key -pubout -out /etc/mail/dkim/public.key |
32 | ;; chmod 440 /etc/mail/dkim/private.key |
33 | ;; |
34 | ;; To (re-)generate /etc/knot/secrets.conf, run: |
35 | ;; keymgt -t lepiller-key > /etc/knot/secrets.conf |
36 | |
37 | (define lepiller-policy |
38 | (append |
39 | web-base-policy |
40 | '("add_header Onion-Location 'http://c25o7knygjm3m67jy27yuynvv4pkfi25naucscmh4ubq2ggiig3v57ad.onion$request_uri';" |
41 | "# accept-language: en,en-US;q=0.8,ja;q=0.6" |
42 | "set $first_language '';" |
43 | "if ($http_accept_language ~* '(en|eo|fr)') {" |
44 | " set $first_language $1;" |
45 | "}" |
46 | "if ($first_language = '') {" |
47 | " set $first_language 'en';" |
48 | "}" |
49 | "set $my_uri $first_language/$uri;" |
50 | "location ~ ^/[^/]*$ {" |
51 | " return 301 /$first_language/$uri;" |
52 | "}" |
53 | ) |
54 | (web-html-policy |
55 | '(" add_header Onion-Location 'http://c25o7knygjm3m67jy27yuynvv4pkfi25naucscmh4ubq2ggiig3v57ad.onion$request_uri';" |
56 | " try_files $my_uri $uri $uri/ =404;")) |
57 | '("error_page 404 /404.html;"))) |
58 | |
59 | (operating-system |
60 | (inherit (tyreunom-os "hermes")) |
61 | (bootloader |
62 | (bootloader-configuration |
63 | (target "/dev/sda") |
64 | (bootloader grub-bootloader))) |
65 | (file-systems (cons (file-system |
66 | (mount-point "/") |
67 | (device (uuid "27798665-5606-4fde-8da8-cc371e603892")) |
68 | (type "ext4")) |
69 | %base-file-systems)) |
70 | (services |
71 | (append |
72 | (list |
73 | hermes-network-service |
74 | lepiller-iptables-service |
75 | (service tor-service-type) |
76 | (tor-hidden-service "lepiller" |
77 | '((22 "127.0.0.1:22") |
78 | (80 "127.0.0.1:80"))) |
79 | (tor-hidden-service "mail" |
80 | '((25 "127.0.0.1:25") |
81 | (143 "127.0.0.1:143") |
82 | (587 "127.0.0.1:587") |
83 | (993 "127.0.0.1:993"))) |
84 | (service nginx-service-type |
85 | (nginx-configuration |
86 | (server-names-hash-bucket-size 128))) |
87 | (service knot-service-type |
88 | (knot-configuration |
89 | (includes '("/etc/knot/secrets.conf")) |
90 | (acls (list slave-acl)) |
91 | (remotes (list ene)) |
92 | (zones (list lepiller-slave-zone |
93 | ipv4-reverse-master-zone |
94 | ipv6-reverse-master-zone)))) |
95 | (certbot-service `(("lepiller.eu" "www.lepiller.eu" "smtp.lepiller.eu"))) |
96 | (simple-service 'social-http-server nginx-service-type |
97 | (list (nginx-server-configuration |
98 | (ssl-certificate "/etc/letsencrypt/live/social.lepiller.eu/fullchain.pem") |
99 | (ssl-certificate-key "/etc/letsencrypt/live/social.lepiller.eu/privkey.pem") |
100 | (listen '("443 ssl http2" "[::]:443 ssl http2")) |
101 | (server-name '("social.lepiller.eu")) |
102 | (root "/srv/http/social/public") |
103 | (locations |
104 | (list |
105 | (nginx-location-configuration |
106 | (uri "/content/") |
107 | (body '("alias /var/lib/social/user-data/public/;"))) |
108 | (nginx-location-configuration |
109 | (uri "/") |
110 | (body '("proxy_pass http://localhost:8080;"))))) |
111 | (raw-content default-web-policy)))) |
112 | (simple-service 'tor-lepiller-http-server nginx-service-type |
113 | (list (nginx-server-configuration |
114 | (listen '("80" "[::]:80")) |
115 | (server-name '("c25o7knygjm3m67jy27yuynvv4pkfi25naucscmh4ubq2ggiig3v57ad.onion")) |
116 | (root "/srv/http/lepiller/public") |
117 | (index '("index.html")) |
118 | (try-files '("$uri" "$uri/" "=404")) |
119 | (raw-content lepiller-policy)))) |
120 | (simple-service 'lepiller-http-server nginx-service-type |
121 | (list (nginx-server-configuration |
122 | (ssl-certificate "/etc/letsencrypt/live/lepiller.eu/fullchain.pem") |
123 | (ssl-certificate-key "/etc/letsencrypt/live/lepiller.eu/privkey.pem") |
124 | (listen '("443 ssl http2" "[::]:443 ssl http2")) |
125 | (server-name '("lepiller.eu" "www.lepiller.eu")) |
126 | (root "/srv/http/lepiller/public") |
127 | (index '("index.html")) |
128 | (try-files '("$uri" "$uri/" "=404")) |
129 | (raw-content lepiller-policy)))) |
130 | (simple-service 'default-http-server nginx-service-type |
131 | (list (nginx-server-configuration |
132 | (ssl-certificate "/etc/letsencrypt/live/lepiller.eu/fullchain.pem") |
133 | (ssl-certificate-key "/etc/letsencrypt/live/lepiller.eu/privkey.pem") |
134 | (listen '("443 ssl http2" "[::]:443 ssl http2")) |
135 | (server-name '(default)) |
136 | (root "/srv/http/default") |
137 | (raw-content default-web-policy))))) |
138 | (lepiller-mail-services |
139 | #:interface "ens18" |
140 | #:domain "lepiller.eu") |
141 | (server-services "hermes")))) |
142 |