aboutsummaryrefslogtreecommitdiff
path: root/sync/vps.scm
blob: e17ad49b85e94de23ffeef103bb6db9878d6cd35 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
(use-modules (gnu)
             (ice-9 textual-ports)
             (guix gexp))
(use-package-modules ssh
                     backup
                     version-control)
(use-service-modules networking
                     ssh
                     mcron
                     admin
                     mail
                     web
                     certbot
                     cgit)

(define user
  "andreh")

(define (slurp f)
  (string-trim-both
   (call-with-input-file f get-string-all)))

(define ssh-public-key
  (slurp "id_rsa.pub"))

(define sudoers "\
root ALL=(ALL) ALL
%wheel ALL=NOPASSWD: ALL\n")

(define tld
  (slurp "tld.txt"))

(define mail-domain-prefix "mail")
(define mail-domain
  (string-append mail-domain-prefix "." tld))

(define git-domain-prefix "git")
(define git-domain
  (string-append git-domain-prefix "." tld))

(define certbot-alias
  "certbot")

(define letsencrypt-prefix
  "/etc/letsencrypt/live/")

(define (tls-pub-for domain)
  (string-append letsencrypt-prefix domain "/fullchain.pem"))

(define (tls-priv-for domain)
  (string-append letsencrypt-prefix domain "/privkey.pem"))

(define opensmtpd-config
  (mixed-text-file "euandreh-smtpd.conf" "
listen on eth0
# File comes from mail-aliases-service-type
table aliases file:/etc/aliases
accept from any domain " mail-domain " alias <aliases> deliver to maildir
accept for local alias <aliases> deliver to maildir
accept for any relay

pki " mail-domain " cert \"" (tls-pub-for  mail-domain) "\"
pki " mail-domain " key  \"" (tls-priv-for mail-domain) "\""))

(define tls-prefixes
  (list "www"
        mail-domain-prefix
        "ci"
        git-domain-prefix
        "chat"
        "meet"))

(define tls-domains
  (cons tld
        (map (lambda (prefix)
               (string-append prefix "." tld))
             tls-prefixes)))

(operating-system
  (locale "fr_FR.UTF-8")
  (timezone "America/Sao_Paulo")
  (keyboard-layout (keyboard-layout "us"))
  (host-name "guix-pet-server")
  (users (cons* (user-account
                 (name user)
                 (group "users")
                 (home-directory (string-append "/home/" user))
                 (supplementary-groups '("wheel")))
                %base-user-accounts))
  (sudoers-file (plain-file "sudoers" sudoers))
  (packages
   (append (map (compose list specification->package+output symbol->string)
                '(git
                  nss-certs
                  rsync))
           %base-packages))
  (services
   (append
    (list (service openssh-service-type
                   (openssh-configuration
                    (openssh openssh-sans-x)
                    (password-authentication? #false)
                    (authorized-keys
                     `((,user ,(plain-file "id_rsa.pub" ssh-public-key))))))
          (service mcron-service-type
                   (mcron-configuration
                    (jobs (list))))
          (service unattended-upgrade-service-type)
          (service dhcp-client-service-type)
          (service opensmtpd-service-type
                   (opensmtpd-configuration
                    (config-file opensmtpd-config)))
          (service mail-aliases-service-type
                   `(("postmaster" "root")
                     ("webmaster" "root")
                     ("abuse" "root")
                     (,certbot-alias "root")))
          ;; (service nginx-service-type
          ;;          (nginx-configuration
          ;;           (server-blocks
          ;;            (list
          ;;             (nginx-server-configuration
          ;;              (server-name (list tld))
          ;;              (ssl-certificate     (tls-pub-for  tld))
          ;;              (ssl-certificate-key (tls-priv-for tld)))))))
          ;; (service certbot-service-type
          ;;          (certbot-configuration
          ;;           (email (string-append certbot-alias "@" tld))
          ;;           (certificates
          ;;            (list
          ;;             (certificate-configuration
          ;;              (domains tls-domains))))))
          (simple-service 'automatic-certbot-renewal
                          activation-service-type
                          (with-imported-modules '((gnu services herd))
                            #~(begin
                                (use-modules (gnu services herd))
                                ;; (execl "/var/lib/certbot/renew-certificates")
                                (restart-service 'nginx))))
          (service cgit-service-type
                   (cgit-configuration
                    (remove-suffix? #t)
                    (root-title "EuAndreh's repositories")
                    (root-desc "Patches welcome!")
                    (snapshots '("tar.gz" "zip"))
                    (clone-prefix (list (string-append "https://" git-domain)))
                    (source-filter (file-append cgit "/lib/cgit/filters/syntax-highlighting.py"))
                    (about-filter  (file-append cgit "/lib/cgit/filters/about-formatting.sh"))
                    ;; about-filter
                    ;;(clone-url "dunno")
                    (enable-commit-graph? #t)
                    (enable-follow-links? #t)
                    (enable-index-links? #t)
                    (enable-log-filecount? #t)
                    (enable-log-linecount? #t)
                    (max-repodesc-length 120)
                    (max-stats "year")
                    (nocache? #t)
                    (readme "README.md")
                    ;()
                    ;; (repositories
                    ;;  (list
                    ;;   (repository-cgit-configuration
                    ;;    ))
                    ;;   )
                     ;; (map (lambda (f)
                     ;;        (repository-cgit-configuration (readme f)))
                     ;;      '("README.md" "README" "README.rst" "README.org"))
                     ))
          (simple-service 'init-srv-directories
                          activation-service-type
                          #~(begin
                              (for-each (lambda (p)
                                          (mkdir-p p)
                                          (chmod p #o777))
                                        '("/srv/http"
                                          "/srv/git"
                                          "/srv/ci")))))
    %base-services))
  (bootloader
   (bootloader-configuration
    (bootloader grub-bootloader)
    (target "/dev/vda")
    (keyboard-layout keyboard-layout)))
  (swap-devices
   (list (uuid "79a91c82-f3e1-4ed7-8c4e-23569f1ae0ca")))
  (file-systems
   (cons* (file-system
            (mount-point "/")
            (device
             (uuid "fddb6a4c-8b8c-4f57-b274-5d6d33200f28"
                   'ext4))
            (type "ext4"))
          %base-file-systems)))