Update website and bootloader

Julien LepillerMon Sep 27 14:15:48+0200 2021

777e0c2

Update website and bootloader

modules/config/web.scm

1818
(define-module (config web)
1919
  #:export (web-base-policy
2020
            web-html-policy
21-
	    default-web-policy))
21+
	    default-web-policy
22+
        accept-languages))
23+
24+
(define (accept-languages language-lists)
25+
  "Returns nginx configuration code to set up the $lang variable
26+
according to the Accept-Language header in the HTTP request.  The
27+
requesting user agent will be served the files at /$lang/some/url.
28+
Each list in LANGUAGE-LISTS starts with the $lang and is followed by
29+
synonymous IETF language tags that should be mapped to the same $lang."
30+
  (define (language-mappings language-list)
31+
    (define (language-mapping language)
32+
      (string-join (list "    "  language (car language-list) ";")))
33+
    (string-join (map language-mapping language-list) "\n"))
34+
35+
  (let ((directives
36+
         `(,(string-join
37+
             `("set_from_accept_language $lang_unmapped"
38+
               ,@(map string-join language-lists)
39+
               ";"))
40+
           "map $lang_unmapped $lang {"
41+
           ,@(map language-mappings language-lists)
42+
           "}")))
43+
    directives))
2244
2345
(define web-base-policy
2446
  '("add_header Strict-Transport-Security \"max-age=31536000; includeSubDomains\" always;"

systems/xana.scm

2424
(use-modules (config certbot) (config cuirass) (config network) (config os) (config web))
2525
(use-modules (guix gexp))
2626
(use-package-modules base compression gettext guile guile-xyz linux version-control
27-
                     wget)
27+
                     web wget)
2828
2929
(define lepiller-policy
3030
  (append
3131
    web-base-policy
32-
    '("# accept-language: en,en-US;q=0.8,ja;q=0.6"
33-
      "set $first_language '';"
34-
      "if ($http_accept_language ~* '(en|eo|fr)') {"
35-
      "  set $first_language $1;"
36-
      "}"
37-
      "if ($first_language = '') {"
38-
      "  set $first_language 'en';"
39-
      "}"
40-
      "set $my_uri $first_language/$uri;"
41-
      "location ~ ^/[^/]*$ {"
42-
      "  return 301 /$first_language/$uri;"
43-
      "}"
44-
      )
4532
    (web-html-policy
46-
      '("    try_files $my_uri $uri $uri/ =404;"))
47-
    '("error_page 404 /404.html;")))
33+
      '("    try_files $uri /$lang/$uri /$lang/$uri/index.html =404;"))
34+
    '("error_page 404 /$lang/404.html;")))
4835
4936
(define (makefile-job directory target packages env)
5037
  #~(lambda ()

9885
  (inherit (tyreunom-os "xana"))
9986
  (bootloader
10087
    (bootloader-configuration
101-
      (target "/dev/sda")
88+
      (targets '("/dev/sda"))
10289
      (bootloader grub-bootloader)))
10390
  (file-systems (cons (file-system
10491
                        (mount-point "/")

11097
    (append
11198
      (list
11299
        (service dhcp-client-service-type)
113-
        (service nginx-service-type)
100+
        (service nginx-service-type
101+
                 (nginx-configuration
102+
                   (modules
103+
                     (list
104+
                       (file-append nginx-accept-language-module
105+
                                    "/etc/nginx/modules/ngx_http_accept_language_module.so")))
106+
                   (extra-content
107+
                     (accept-languages
108+
                       '(("en")
109+
                         ("fr")
110+
                         ("uk")
111+
                         ("zh_CN" "zh-CN" "zh" "zh-Hans" "zh-Hans-CN"))))))
114112
        (simple-service 'website-cron mcron-service-type
115113
          (list i18n-download-job i18n-compile-job
116114
                nani-download-job nani-update-job))