unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
blob 8201b7150488e393d297508843be95ece7fec3e9 6091 bytes (raw)
name: guix/build-system/mix.scm 	 # note: path name is non-authoritative(*)

  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
 
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2023 Pierre-Henry Fröhring <phfrohring@deeplinks.com>
;;;
;;; This file is part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix 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 General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

;; Commentary:
;;
;; Standard build procedure for Elixir packages using 'mix'.  This is
;; implemented as an extension of 'gnu-build-system'.
;;
;; Code:

(define-module (guix build-system mix)
  #:use-module (gnu packages base)
  #:use-module (gnu packages elixir)
  #:use-module (guix build mix-build-system)
  #:use-module (guix build-system gnu)
  #:use-module (guix build-system)
  #:use-module (guix search-paths)
  #:use-module (guix monads)
  #:use-module (guix packages)
  #:use-module (guix store)
  #:use-module (guix gexp)
  #:use-module (guix utils)
  #:export (mix-build-system hexpm-uri))

;;
;; hexpm
;;

(define (hexpm-uri name version)
  "Return the URI where to fetch the sources of a Hex package NAME at VERSION.

See: https://github.com/hexpm/specifications/blob/main/endpoints.md"
  (string-append "https://repo.hex.pm/tarballs/"
                 (string-replace-substring (strip-elixir-prefix name) "-" "_")
                 "-" version ".tar"))

;;
;; utils
;;

(define utils-locales
  (make-glibc-utf8-locales glibc
                           #:locales (list "en_US")
                           #:name "glibc-utf8-locales"))

(define (utils-elixir-default)
  "Return the default Elixir package."
  ;; Lazily resolve the binding to avoid a circular dependency.
  (let ((elixir (resolve-interface '(gnu packages elixir))))
    (module-ref elixir
                'elixir)))

(define utils-imported-modules
  `((guix build mix-build-system)
    ,@%gnu-build-system-modules))

(define utils-modules
  '((guix build mix-build-system)
    (guix build utils)))

;;
;; mix
;;

(define* (mix-build name
                    inputs
                    #:key source
                    (tests? #t)
                    (phases '%standard-phases)
                    (outputs '("out"))
                    (search-paths '())
                    (system (%current-system))
                    (guile #f)
                    (imported-modules utils-imported-modules)
                    (modules utils-modules))
  "Build SOURCE using Elixir, and with INPUTS."

  (define builder
    (with-imported-modules imported-modules
      #~(begin

          (use-modules #$@(sexp->gexp modules))

          #$(with-build-variables inputs outputs
              #~(mix-build #:name #$name
                           #:source #+source
                           #:system #$system
                           #:tests? #$tests?
                           #:phases #$(if (pair?
                                           phases)
                                          (sexp->gexp
                                           phases)
                                          phases)
                           #:outputs %outputs
                           #:search-paths '#$(sexp->gexp
                                              (map
                                               search-path-specification->sexp
                                               search-paths))
                           #:inputs
                           %build-inputs)))))

  (mlet %store-monad
      ((guile (package->derivation (or guile
                                       (default-guile)) system
                                       #:graft? #f)))
    (gexp->derivation name
                      builder
                      #:system system
                      #:graft? #f ;consistent with 'gnu-build'
                      #:target #f
                      #:guile-for-build guile)))

(define* (mix-lower name
                    #:key source
                    inputs
                    native-inputs
                    outputs
                    system
                    target
                    (elixir (utils-elixir-default))
                    #:allow-other-keys #:rest arguments)
  "Return a bag for NAME."

  ;; The value associated to these keywords are used in the bag below and are
  ;; not to be used in the arguments.
  (define private-keywords
    '(#:inputs #:native-inputs #:outputs #:system #:target #:elixir))

  ;; All that is necessary to complete the build.
  (define build-inputs
    ;; If these packages are not present, then Elixir emits these errors:
    ;; dirname: command not found
    ;; basename: command not found
    `(,@(standard-packages)

      ;; If no UTF-8 is present, then Elixir emits this warning:
      ;;
      ;; warning: the VM is running with native name encoding of latin1
      ;; which may cause Elixir to malfunction as it expects utf8. Please
      ;; ensure your locale is set to UTF-8 (which can be verified by
      ;; running "locale" in your shell)
      ("glibc-utf8-locales" ,utils-locales)

      ("elixir" ,elixir)

      ;; If Hex is not present, mix cannot build packages.
      ("mix-hex" ,mix-hex)

      ,@native-inputs

      ,@inputs))

  (define host-inputs
    (if target inputs
        '()))

  (bag (name name)
       (system system)
       (build-inputs build-inputs)
       (host-inputs host-inputs)
       (outputs outputs)
       (build mix-build)
       (arguments (strip-keyword-arguments private-keywords arguments))))

(define mix-build-system
  (build-system (name 'mix)
                (description "The standard Mix build system")
                (lower mix-lower)))

;;; mix.scm ends here

debug log:

solving 8201b715 ...
found 8201b715 in https://yhetil.org/guix-patches/68117eb2b3e0e6adcc7449d878e602c7b831ffee.1698524350.git.phfrohring@deeplinks.com/

applying [1/1] https://yhetil.org/guix-patches/68117eb2b3e0e6adcc7449d878e602c7b831ffee.1698524350.git.phfrohring@deeplinks.com/
diff --git a/guix/build-system/mix.scm b/guix/build-system/mix.scm
new file mode 100644
index 00000000..8201b715

Checking patch guix/build-system/mix.scm...
Applied patch guix/build-system/mix.scm cleanly.

index at:
100644 8201b7150488e393d297508843be95ece7fec3e9	guix/build-system/mix.scm

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).