aboutsummaryrefslogtreecommitdiff
path: root/container.scm
blob: f8a4113a39257df64d0e385b0174560ebd999d38 (plain)
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
;; SPDX-License-Identifier: CC0-1.0

;; Copyright (C) 2022 Wojtek Kosior <koszko@koszko.org>
;;
;; Available under the terms of Creative Commons Zero v1.0 Universal.

(use-modules (gnu))
(use-modules (koszko-org-website))
(use-package-modules web)
(use-service-modules web)
(use-service-modules shepherd)

(define %koszko-org-virtualhost
  (httpd-virtualhost
   "*:80"
   (list "\
         ServerName koszko.org
         ServerAlias www.koszko.org
         DocumentRoot /srv/http/koszko.org
         ServerAdmin koszko@koszko.org

         <If \"%{HTTP_HOST} != 'koszko.org'\">
             Redirect permanent / http://koszko.org/
         </If>

         Alias /sideload /srv/http/koszko.org

         WSGIScriptReloading On
         "
         #~(let* ((script-rel "/share/koszko-org-website/wsgi.py")
                  (wsgi-file (string-append #$koszko-org-website script-rel)))
             (format #f
                     "\
                     <Files ~s>
                         Require all granted
                     </Files>
                     WSGIScriptAlias / ~a
                     "
                     wsgi-file wsgi-file)))))

(define %koszkonutek-tmp-virtualhost
  (httpd-virtualhost
   "*:80"
   '("\
     ServerName koszkonutek-tmp.pl.eu.org
     ServerAlias www.koszkonutek-tmp.pl.eu.org

     Redirect permanent / http://koszko.org/
     ")))

(define %hydrillabugs-virtualhost
  (httpd-virtualhost
   "*:80"
   '("\
    ServerName hydrillabugs.koszko.org
    ServerAlias www.hydrillabugs.koszko.org
    ServerAdmin koszko@koszko.org

    <Proxy *>
        Redirect permanent /projects/hachette /projects/haketilo

        # I don't remember why I added the following line so I'm keeping it just
        # in case.
        RequestHeader unset Accept-Encoding
    </Proxy>

    ProxyPass /projects/haketilo http://10.207.87.1:21011/projects/hachette
    ProxyPassReverse /projects/haketilo http://10.207.87.1:21011/projects/hachette

    ProxyPass / http://10.207.87.1:21011/
    ProxyPassReverse / http://10.207.87.1:21011/
    ")))

(define %hachettebugs-virtualhost
  (httpd-virtualhost
   "*:80"
   '("\
     ServerName hachettebugs.koszko.org
     ServerAlias www.hachettebugs.koszko.org

     Redirect permanent / http://hydrillabugs.org/
     ")))

(define %wsgi-module
  (httpd-module
   (name "wsgi_module")
   (file (file-append mod-wsgi "/modules/mod_wsgi.so"))))

(define %proxy-http-modules
  (list (httpd-module
         (name "proxy_module")
         (file (file-append httpd "/modules/mod_proxy.so")))
        (httpd-module
         (name "proxy_http_module")
         (file (file-append httpd "/modules/mod_proxy_http.so")))))

;; logio is needed for the '%O' log format directive
(define %logio-module
  (httpd-module
   (name "logio_module")
   (file (file-append httpd "/modules/mod_logio.so"))))

(define %logformat-combined
  "\"%h %l %u %t \\\"%r\\\" %>s %O \\\"%{Referer}i\\\" \\\"%{User-Agent}i\\\"\"")

(define %koszko-httpd-service
  (service
   httpd-service-type
   (httpd-configuration
    (config
     (httpd-config-file
      (server-name "koszko.org")
      (error-log "/var/log/httpd/error.log")
      (modules `(,%wsgi-module
                 ,@%proxy-http-modules
                 ,%logio-module
                 ,@%default-httpd-modules))
      (extra-config
       (list
        (string-join `("LogFormat" ,%logformat-combined "combined")) "\n"
        "ErrorLog /var/log/httpd/error.log" "\n"
        "CustomLog /var/log/httpd/access.log combined" "\n"
        )))))))

(operating-system
  (host-name "koszko")
  (timezone "Europe/Warsaw")

  (file-systems (cons (file-system
                        (device (file-system-label "does-not-matter"))
                        (mount-point "/")
                        (type "ext4"))
                      %base-file-systems))
  (bootloader (bootloader-configuration
               (bootloader grub-bootloader)
               (targets '("/dev/sdDOES-NOT-MATTER"))))
  (services
   (cons* %koszko-httpd-service
          (simple-service 'koszko-org-website httpd-service-type
                          (list %koszko-org-virtualhost
                                %koszkonutek-tmp-virtualhost
                                %hydrillabugs-virtualhost
                                %hachettebugs-virtualhost))
          (service
           (shepherd-service-type
            'dummy-network
            (const
             (shepherd-service
              (documentation "Provide 'networking' without actually doing anything")
              (provision '(networking))
              (start #~(const #t))
              (stop #~(const #t))
              (respawn? #f)))
            (description "Make other services assume network is there."))
           #f)
          %base-services)))