about summary refs log tree commit diff
path: root/arunisaac/meetfree.scm
blob: 748164de0802205dcdb6de295dcfb75eda9578fd (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
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
(define-module (arunisaac meetfree)
  #:use-module ((forge nginx) #:select (forge-nginx-service-type))
  #:use-module ((gnu packages admin) #:select (shadow))
  #:use-module ((gnu packages check) #:select (python-pytest))
  #:use-module ((gnu packages nss) #:select (nss-certs))
  #:use-module ((gnu packages python) #:select (python))
  #:use-module ((gnu packages python-build)
                #:select (python-flit-core
                          python-hatch-vcs
                          python-hatchling
                          python-pypa-build
                          python-setuptools))
  #:use-module ((gnu packages python-web)
                #:select (python-bottle python-requests))
  #:use-module ((gnu packages python-xyz)
                #:select (python-flit python-markdown))
  #:use-module ((gnu packages time)
                #:select (python-dateutil python-tzdata))
  #:use-module ((gnu packages xml) #:select (python-lxml))
  #:use-module (gnu services)
  #:use-module ((gnu services web)
                #:select (gunicorn-app
                          gunicorn-service-type
                          nginx-server-configuration
                          nginx-location-configuration))
  #:use-module (gnu system accounts)
  #:use-module (gnu system file-systems)
  #:use-module ((gnu system shadow) #:select (account-service-type))
  #:use-module (guix build-system pyproject)
  #:use-module (guix build-system python)
  #:use-module (guix download)
  #:use-module (guix gexp)
  #:use-module (guix git-download)
  #:use-module ((guix licenses) #:prefix license:)
  #:use-module (guix packages)
  #:use-module (guix profiles)
  #:use-module (guix records)
  #:use-module (guix utils)
  #:export (meetfree-service-type

            meetfree-configuration
            meetfree-configuration-python-meetfree
            meetfree-configuration-server-name
            meetfree-configuration-allowed-groups))

(define-public python-feedgen
  (package
    (name "python-feedgen")
    (version "1.0.0")
    (source
     (origin
       (method url-fetch)
       (uri (pypi-uri "feedgen" version))
       (sha256
        (base32 "0sjljdip5ffkwphqh49irhprywic9n671hwq56js4mp9np1m3gfr"))))
    (build-system pyproject-build-system)
    (propagated-inputs
     (list python-dateutil
           python-lxml))
    (native-inputs
     (list python-pytest
           python-setuptools))
    (home-page "https://lkiesow.github.io/python-feedgen")
    (synopsis "Feed Generator (ATOM, RSS, Podcasts)")
    (description
     "This module can be used to generate web feeds in both Atom and RSS
format.  It supports extensions.  For example, it comes with an
extension to produce podcasts.")
    (license (list license:bsd-2
                   license:lgpl3+))))

(define-public python-icalendar
  (package
    (name "python-icalendar")
    (version "7.0.3")
    (source
     (origin
       (method url-fetch)
       (uri (pypi-uri "icalendar" version))
       (sha256
        (base32 "1plgdlhnij79awxqvlfdfhgq4xaqy9hkgw35sy273f3s1377w0lm"))))
    (build-system pyproject-build-system)
    (arguments
     (list #:phases
           #~(modify-phases %standard-phases
               (add-after 'unpack 'relax-tzdata-dependency
                 (lambda _
                   ;; Relax tzdata dependency to latest available in
                   ;; Guix at the moment.
                   (substitute* "pyproject.toml"
                     (("\"tzdata>=2025.3\"")
                      "\"tzdata>=2025.1\"")))))))
    (propagated-inputs (list python-dateutil
                             python-tzdata))
    (native-inputs (list python-hatch-vcs
                         python-hatchling))
    (home-page "https://icalendar.readthedocs.io/en/stable/")
    (synopsis "iCalendar parser and generator")
    (description "The icalendar package is an RFC 5545 compatible
parser and generator of iCalendar files.  icalendar can create,
inspect, and modify calendaring information with Python.  icalendar
supports multiple timezone implementations, including zoneinfo,
dateutil.tz, and pytz.")
    (license license:bsd-3)))

(define-public python-justhtml
  (package
    (name "python-justhtml")
    (version "1.12.0")
    (source
     (origin
       (method git-fetch)
       (uri (git-reference
              (url "https://github.com/emilstenstrom/justhtml")
              (commit (string-append "v" version))))
       (file-name (git-file-name name version))
       (sha256
        (base32 "065iqikxrhwn6f5svlsv3fzpdri49h74ng8gfpsd4hgjknwrwqgn"))))
    (build-system pyproject-build-system)
    (native-inputs (list python-pypa-build
                         python-hatchling))
    (home-page "https://github.com/emilstenstrom/justhtml")
    (synopsis "Pure Python HTML5 parser")
    (description
     "JustHTML is a pure Python HTML5 parser.  It has a simple API and
does not require C extensions or system dependencies.")
    (license license:expat)))

(define-public python-meetfree
  (let ((commit "c263cba1c784ba8d776e655d3f56b8d583b503c5")
        (revision "0"))
    (package
      (name "meetfree")
      (version (git-version "0.1.0" revision commit))
      (source (origin
                (method git-fetch)
                (uri (git-reference
                       (url "https://git.systemreboot.net/meetfree")
                       (commit commit)))
                (file-name (git-file-name name version))
                (sha256
                 (base32
                  "1ai72gc2dk26a7g1fkm7l74mgxvqx8bjd14g4y7c381jm0xrwn9j"))))
      (build-system pyproject-build-system)
      (propagated-inputs
       (list python-bottle
             python-feedgen
             python-icalendar
             python-justhtml
             python-markdown
             python-requests
             ;; FIXME: nss-certs shouldn't be here. But, we add it
             ;; because the gunicorn service is unable to pick up
             ;; dependencies in environment variables. Fix that
             ;; instead.
             nss-certs))
      (native-inputs
       (list python-flit-core))
      (home-page "https://forge.systemreboot.net/meetfree")
      (synopsis "iCalendar and Atom feeds for meetup.com")
      (description "meetfree is a bottle web app that serves iCalendar
and Atom feeds for meetup.com groups.  meetfree fetches data from
meetup.com using its GraphQL API.  The GraphQL API does not require any
authentication.")
      (license license:unlicense))))

(define-record-type* <meetfree-configuration>
  meetfree-configuration make-meetfree-configuration
  meetfree-configuration?
  (python-meetfree meetfree-configuration-python-meetfree
                   (default python-meetfree))
  (server-name meetfree-configuration-server-name)
  (allowed-groups meetfree-configuration-allowed-groups
                  (default #f))) ; list of group slugs or #f

(define %meetfree-accounts
  (list (user-account
         (name "meetfree")
         (group "meetfree")
         (system? #t)
         (comment "meetfree user")
         (home-directory "/var/empty")
         (shell (file-append shadow "/sbin/nologin")))
        (user-group
         (name "meetfree")
         (system? #t))))

(define meetfree-gunicorn-apps
  (match-record-lambda <meetfree-configuration>
    (python-meetfree server-name allowed-groups)
    (list (gunicorn-app
           (name "meetfree")
           (package python-meetfree)
           (wsgi-app-module "meetfree:app")
           (user "meetfree")
           (group "meetfree")
           (environment-variables
            `(("SSL_CERT_FILE"
               . ,(file-append (profile
                                 (content (packages->manifest
                                           (list python python-meetfree))))
                               "/etc/ssl/certs/ca-certificates.crt"))
              ("MEETFREE_BASE_URL" . ,(string-append "https://" server-name))
              ,@(if allowed-groups
                    `(("MEETFREE_ALLOWED_GROUPS" . ,(string-join allowed-groups)))
                    '())))
           (extra-cli-arguments
            (list "--capture-output"))))))

(define meetfree-nginx-server-blocks
  (match-record-lambda <meetfree-configuration>
    (server-name)
    (list (nginx-server-configuration
           (server-name (list server-name))
           (locations
            (list (nginx-location-configuration
                   (uri "/")
                   (body
                    (list "proxy_pass http://unix:/var/run/gunicorn/meetfree/socket:;")))))))))

(define meetfree-service-type
  (service-type
   (name 'meetfree)
   (description "Run meetfree.")
   (extensions (list (service-extension account-service-type
                                        (const %meetfree-accounts))
                     (service-extension gunicorn-service-type
                                        meetfree-gunicorn-apps)
                     (service-extension forge-nginx-service-type
                                        meetfree-nginx-server-blocks)))))