summaryrefslogtreecommitdiff
path: root/disfluid/maintainer/channel-code.scm
blob: d669194b826b5bedfa2022636024c1ead427f895 (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
;; disfluid, implementation of the Solid specification
;; Copyright (C) 2022  Vivien Kraus

;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU Affero General Public License as
;; published by the Free Software Foundation, either version 3 of the
;; License, or (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU Affero General Public License for more details.

;; You should have received a copy of the GNU Affero General Public License
;; along with this program.  If not, see <https://www.gnu.org/licenses/>.

(define-module (disfluid maintainer channel-code)
  #:use-module (disfluid maintainer bootstrap-guix)
  #:use-module (disfluid maintainer new-phases)
  #:use-module (guix gexp)
  #:use-module (gnu packages base)
  #:use-module (gnu packages guile-xyz)
  #:declarative? #t
  #:export (channel-code))

;; channel-code is a file-like object that contains all the code that
;; must go to the "guix" branch. It is based on the output from hall
;; distribution-system, with new phases added and new inputs that hall
;; does not know about.

(define (vkraus/packages/disfluid.scm scan)
  (define disfluid-commit
    (assq-ref scan 'commit))
  (define disfluid-translations-commit
    (assq-ref scan 'translations-commit))
  (define disfluid-hash
    (assq-ref scan 'hash))
  (define disfluid-translations-hash
    (assq-ref scan 'translations-hash))
  (computed-file
   "disfluid.scm"
   (with-imported-modules '((guix build utils))
     #~(begin
         (use-modules (guix build utils))
         (use-modules (srfi srfi-26))
         (use-modules (ice-9 pretty-print))
         (define kwasikwot (string->symbol "quasiquote"))
         (define unkwot (string->symbol "unquote"))
         (define (fix-use-modules modules)
           `(define-module (vkraus packages disfluid)
              ,@(apply append
                       (map (lambda (module)
                              `(#:use-module ,module))
                            `((gnu packages base)
                              (gnu packages bash)
                              (gnu packages emacs)
                              (gnu packages gettext)
                              (gnu packages glib)
                              (gnu packages gnupg)
                              (gnu packages gtk)
                              (guix git-download)
                              (guix monads)
                              (guix store)
                              (guix derivations)
                              (guix profiles)
                              (guix scripts pack)
                              (guix gexp)
                              (guix modules)
                              (guix utils)
                              (ice-9 match)
                              ,@modules)))))
         (define (fix-source _)
           `(source
             (computed-file
              "source-with-translations"
              (with-imported-modules
                  (source-module-closure '((guix build utils)))
                #~(begin
                    (use-modules (guix build utils))
                    (copy-recursively
                     (#$(string->symbol "ungexp")
                        (directory-union
                         "source-with-translations-linked"
                         (list
                          (origin
                            (method git-fetch)
                            (uri (git-reference
                                  (url "https://labo.planete-kraus.eu/disfluid.git")
                                  (commit #$disfluid-commit)))
                            (sha256 (base32 #$disfluid-hash)))
                          (origin
                            (method git-fetch)
                            (uri (git-reference
                                  (url "https://labo.planete-kraus.eu/disfluid.git")
                                  (commit #$disfluid-translations-commit)))
                            (sha256 (base32 #$disfluid-translations-hash))))))
                     (#$(string->symbol "ungexp") output)
                     #:follow-symlinks? #t))))))
         (define (fix-arguments args)
           `(arguments
             (,kwasikwot
              (,@args
               #:phases #$(new-phases scan)))))
         (define (fix-inputs kind inputs new-ones)
           `(,kind
             (,kwasikwot
              (,@(map cadr inputs)
               ,@(map (lambda (new)
                        `(,unkwot ,new))
                      new-ones)))))
         (define (fix-native-inputs inputs)
           (fix-inputs
            'native-inputs
            inputs
            '(guile-hall emacs gnu-gettext autoconf-archive
                         findutils tzdata-for-tests)))
         (define (fix-runtime-inputs inputs)
           (fix-inputs 'inputs inputs '(glib gtk-minimal bash-minimal)))
         (define (fix-propagated-inputs inputs)
           (fix-inputs 'propagated-inputs inputs '()))
         (define fix-field
           ((@ (ice-9 match) match-lambda)
            (`(source . ,source)
             (fix-source source))
            (`(arguments (,the-quote ,arguments))
             (begin
               (unless (eq? the-quote kwasikwot)
                 (error "Only quasiquote is supported."))
               (fix-arguments arguments)))
            (`(native-inputs (,the-quote ,inputs))
             (begin
               (unless (eq? the-quote kwasikwot)
                 (error "Only quasiquote is supported."))
               (fix-native-inputs inputs)))
            (`(inputs (,the-quote ,inputs))
             (begin
               (unless (eq? the-quote kwasikwot)
                 (error "Only quasiquote is supported."))
               (fix-runtime-inputs inputs)))
            (`(propagated-inputs (,the-quote ,inputs))
             (begin
               (unless (eq? the-quote kwasikwot)
                 (error "Only quasiquote is supported."))
               (fix-propagated-inputs inputs)))
            (field field)))
         (define (fix-package fields)
           `(define-public disfluid
              (package
                ,@(map fix-field fields))))
         (define fix-object
           ((@ (ice-9 match) match-lambda)
            (`(use-modules . ,modules)
             (fix-use-modules modules))
            (`(package . ,fields)
             (fix-package fields))))
         (define package-fixes
           `(define gtk-minimal
              (package
                (inherit gtk)
                (arguments
                 (substitute-keyword-arguments
                     (package-arguments gtk)
                   ((#:configure-flags configure-flags (,(string->symbol "gexp") list))
                    (,(string->symbol "gexp")
                     (append
                      (,(string->symbol "ungexp") configure-flags)
                      (list
                       "-Dmedia-gstreamer=disabled"
                       "-Dtracker=disabled"))))))
                (inputs
                 (filter
                  (match-lambda
                    (("gst-plugins-bad" . _) #f)
                    (("gst-plugins-base" . _) #f)
                    (("tracker" . _) #f)
                    (else #t))
                  (package-inputs gtk))))))
         (call-with-input-file
             #$(guix.scm scan)
             (lambda (base)
               (call-with-output-file #$output
                 (lambda (inherited)
                   (format inherited
                           ";; This file has been automatically generated.\n")
                   (let loop ()
                     (let ((next (read base)))
                       (unless (eof-object? next)
                         (begin
                           ((@ (ice-9 match) match) next
                            (('package . _)
                             ;; Also fix the packages
                             (pretty-print package-fixes inherited)
                             (newline inherited))
                            (else #t))
                           (pretty-print (fix-object next) inherited)
                           (newline inherited)
                           (loop)))))
                   (write 'disfluid inherited)
                   (newline inherited)))))))))

(define (vkraus/packages scan)
  (file-union
   "packages"
   `(("disfluid.scm" ,(vkraus/packages/disfluid.scm scan)))))

(define (vkraus scan)
  (file-union
   "vkraus"
   `(("packages" ,(vkraus/packages scan)))))

(define (channel-code scan)
  (file-union
   "channel-code"
   `(("vkraus" ,(vkraus scan)))))