all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
blob 86d960e767886730965445cf2919b2fce76a576b 5174 bytes (raw)
name: guix/import/hex.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
 
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2017 Federico Beffa <nee-git@hidamari.blue>
;;;
;;; 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/>.

(define-module (guix import hex)
  #:use-module (ice-9 match)
  #:use-module (ice-9 regex)
  #:use-module (srfi srfi-1)
  #:use-module (srfi srfi-26)
  #:use-module (srfi srfi-34)
  #:use-module (srfi srfi-35)
  #:use-module (guix import json)
  #:use-module (guix import hackage)
  #:use-module (guix memoization)
  #:use-module (guix packages)
  #:use-module (guix upstream)
  #:use-module (guix store)
  #:use-module (guix base32)
  #:use-module (guix hash)
  #:use-module (guix import utils)
  #:use-module ((guix download) #:select (download-to-store url-fetch))
  #:export (hex-fetch))

(define %packages-url "https://hex.pm/api/packages/")
(define %tarball-url "https://repo.hex.pm/tarballs/")
(define %package-name-prefix "hex-")

(define (hex-name->guix-name name)
  (if (string-prefix? %package-name-prefix name)
      (snake-case name)
      (string-append %package-name-prefix (snake-case name))))

(define (make-input-entry name)
  (list name (list 'unquote (string->symbol name))))

(define (as-list item/s)
  (if (list? item/s)
      item/s
      (list item/s)))

(define (list-or-single item/s)
  (if (null? (cdr item/s))
      (car item/s)
      items))

;;; TODO take version as second arg
(define (hex-fetch package-name)
  (define url (string-append %packages-url package-name))
  (define json (json-fetch url))
  (define meta (assoc-ref json "meta"))
  (define latest-release (car (assoc-ref json "releases")))
  (define latest-release-info-url (assoc-ref latest-release "url"))
  (define latest-release-version (assoc-ref latest-release "version"))
  (define release-json (json-fetch latest-release-info-url))
  (define release-meta (assoc-ref release-json "meta"))
  ;; TODO maybe also check the versions and optional
  (define inputs (map car (assoc-ref release-json "requirements")))
  (define tarball-name (string-append package-name "-" latest-release-version ".tar"))
  (define source-url (string-append %tarball-url tarball-name))
  (define tarball (with-store store
                    (download-to-store store source-url)))
  `(package
     (name ,(hex-name->guix-name package-name))
     (version ,latest-release-version)
     (source (origin
               (method url-fetch/hex.pm)
               (uri (string-append ,@(list (string-append %tarball-url package-name "-")
                                           'version ".tar")))
               (sha256
                (base32
                 ,(if tarball
                      (bytevector->nix-base32-string (file-sha256 tarball))
                      "failed to download tar archive")))))
     (build-system hex-build-system)
     (inputs ,(list 'quasiquote
                    (map (lambda (input-hex)
                           (define input-guix (hex-name->guix-name input-hex))
                           (make-input-entry input-guix))
                         inputs)))
     (native-inputs ,(list 'quasiquote
                           (map (lambda (input-hex)
                                  (define input-guix (match input-hex
                                                       ("rebar3" "rebar3")
                                                       ("mix" "elixir")
                                                       (input (hex-name->guix-name input))))
                                  (make-input-entry input-guix))
                                (match (assoc-ref release-meta "build_tools")
                                  (#f '())
                                  ((? list? lst) lst)
                                  (single-tool (list single-tool))))))
     (home-page "")
     (synopsis "")
     (description ,(assoc-ref meta "description"))
     (license ,(list-or-single
                (map string->license
                     (as-list (or (assoc-ref meta "licenses") '())))))))

(define string->license
  ;; copied from the hackage importer, slightly edited some names
  ;; TODO: find a complete list of licences on hex.pm
  (match-lambda
   ("GPL-2" 'gpl2)
   ("GPL-3" 'gpl3)
   ("GPL" "'gpl??")
   ("AGPL-3" 'agpl3)
   ("AGPL" "'agpl??")
   ("LGPL-2.1" 'lgpl2.1)
   ("LGPL-3" 'lgpl3)
   ("LGPL" "'lgpl??")
   ("BSD2" 'bsd-2)
   ("BSD3" 'bsd-3)
   ("MIT" 'expat)
   ("ISC" 'isc)
   ("MPL" 'mpl2.0)
   ("CC0-1.0" 'cc0)
   ("Apache 2.0" 'asl2.0)
   ((x) (string->license x))
   ((lst ...) `(list ,@(map string->license lst)))
   (_ #f)))

debug log:

solving 86d960e76 ...
found 86d960e76 in https://yhetil.org/guix/24fd2ea2-03d6-0b64-ac73-9949b85ee0f3@cock.li/

applying [1/1] https://yhetil.org/guix/24fd2ea2-03d6-0b64-ac73-9949b85ee0f3@cock.li/
diff --git a/guix/import/hex.scm b/guix/import/hex.scm
new file mode 100644
index 000000000..86d960e76

Checking patch guix/import/hex.scm...
Applied patch guix/import/hex.scm cleanly.

index at:
100644 86d960e767886730965445cf2919b2fce76a576b	guix/import/hex.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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.