aboutsummaryrefslogtreecommitdiff
path: root/gn/services/bnw-container.scm
blob: 2e5e52108cd436c24fab4604fd6ce7cc64aac9c6 (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
(define-module (gn services bnw-container))

(use-modules (gnu)
             (gn packages bnw)
             (guix records)
             (ice-9 match))
(use-service-modules networking web)

(define-record-type* <bnw-configuration>
  bnw-configuration
  make-bnw-configuration
  bnw-configuration?
  (package          bnw-configuration-package       ; package
                    (default bnw))
  (deploy-directory bnw-deploy-directory            ; string
                    (default "/home/bnw/server"))
  (port             bnw-configuration-port          ; list of strings
                    (default '("8880"))))

(define bnw-activation
  (match-lambda
    (($ <bnw-configuration> package deploy-directory port)
     #~(begin
         (use-modules (guix build utils))
         (when (directory-exists? #$deploy-directory)
           (delete-file-recusively #$deploy-directory))
         (mkdir-p #$deploy-directory)
         (copy-recursively #$package #$deploy-directory)
         (system* #$(file-append coreutils "/bin/chmod") "a+w"
                  (string-append #$deploy-directory "/sourcecodes/data"))))))

(define bnw-nginx-config
  (match-lambda
    (($ <bnw-configuration> package deploy-directory port)
     (list
       (nginx-server-configuration
         (server-name '("Bayesian Network"))
         (listen port)
         ;(root package)
         (root "/srv/http")
         (locations
           (list
             (nginx-php-location)
             ;(nginx-location-configuration
             ;  (uri "/sourcecodes/data/")
             ;  (body (list "alias /tmp/bnw/;")))
             )))))))

(define bnw-service-type
  (service-type
    (name 'bnw)
    (extensions
      (list
        (service-extension activation-service-type
                           bnw-activation)
        (service-extension nginx-service-type
                           bnw-nginx-config)
        ;; Make sure BNW doesn't get garbage collected.
        (service-extension profile-service-type
                           (compose list bnw-configuration-package))
        ;; Make sure php-fpm is instantiated.
        (service-extension php-fpm-service-type
                           (const #t))))
    (default-value (bnw-configuration))
    (description
     "Run a Bayesian Network Webserver.")))

(operating-system
  (host-name "bnw")
  (timezone "Etc/UTC")
  (locale "en_US.utf8")

  (bootloader (bootloader-configuration
               (bootloader grub-bootloader)
               (target "does-not-matter")))
  (file-systems %base-file-systems)
  ;; No firmware for VMs
  (firmware '())

  (services (list (service dhcp-client-service-type)
                  (service bnw-service-type
                           ;; The following is for testing:
                           ;(bnw-configuration
                           ;  (deploy-directory "/home/efraimf/bnw")
                           ;  (port '("8888")))
                           ))))