2 # aside from this initial boilerplate, this is actually -*- scheme -*- code
5 datarootdir
="@datarootdir@"
7 GUILE_LOAD_COMPILED_PATH
="@guilemoduledir@:$GUILE_LOAD_COMPILED_PATH"
8 export GUILE_LOAD_COMPILED_PATH
10 main
='(module-ref (resolve-interface '\''(guix-import)) '\'guix-import
')'
11 exec ${GUILE-@GUILE@} -L "@guilemoduledir@" -l "$0" \
12 -c "(apply $main (cdr (command-line)))" "$@"
14 ;;; GNU Guix
--- Functional package management
for GNU
15 ;;; Copyright ©
2012, 2013 Ludovic Courtès
<ludo@gnu.org
>
17 ;;; This
file is part of GNU Guix.
19 ;;; GNU Guix is free software
; you can redistribute it and
/or modify it
20 ;;; under the terms of the GNU General Public License as published by
21 ;;; the Free Software Foundation
; either version
3 of the License
, or
(at
22 ;;; your option
) any later version.
24 ;;; GNU Guix is distributed
in the hope that it will be useful
, but
25 ;;; WITHOUT ANY WARRANTY
; without even the implied warranty of
26 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 ;;; GNU General Public License
for more details.
29 ;;; You should have received a copy of the GNU General Public License
30 ;;; along with GNU Guix. If not
, see
<http
://www.gnu.org
/licenses
/>.
32 (define-module
(guix-import
)
33 #:use-module (guix ui)
34 #:use-module (guix snix)
35 #:use-module (guix utils)
36 #:use-module (srfi srfi-1)
37 #:use-module (srfi srfi-11)
38 #:use-module (srfi srfi-26)
39 #:use-module (srfi srfi-37)
40 #:use-module (ice-9 match)
41 #:use-module (ice-9 pretty-print)
42 #:export (guix-import))
49 (define
(newline-rewriting-port output
)
50 "Return an output port that rewrites strings containing the \\n escape
51 to an actual newline. This works around the behavior of `pretty-print'
52 and `write', which output these as \\n instead of actual newlines,
53 whereas we want the `description' field to contain actual newlines
55 (define
(write-string str
)
56 (let loop
((chars
(string-
>list str
)))
64 (write-char chr output
)
67 (make-soft-port
(vector
(cut write-char
<>)
77 ;;; Command-line options.
80 (define
%default-options
84 (display (_ "Usage: guix-import NIXPKGS ATTRIBUTE
85 Import and convert the Nix expression ATTRIBUTE of NIXPKGS.\n"))
87 -h, --help display this help and exit"))
89 -V, --version display version information and exit"))
91 (show-bug-report-information))
94 ;; Specification of the command-line options.
95 (list (option '(#\h "help") #f #f
99 (option
'(#\V "version") #f #f
101 (show-version-and-exit "guix-import")))))
108 (define (guix-import . args)
109 (define (parse-options)
110 ;; Return the alist of option values.
111 (args-fold args %options
112 (lambda (opt name arg result)
113 (leave (_ "~A: unrecognized option~%") name))
115 (alist-cons 'argument arg result
))
118 (setlocale LC_ALL
"")
120 (setvbuf
(current-output-port
) _IOLBF
)
121 (setvbuf
(current-error-port
) _IOLBF
)
123 (let* ((opts
(parse-options
))
124 (args
(filter-map
(match-lambda
131 (let-values (((expr loc)
132 (nixpkgs->guix-package nixpkgs attribute)))
133 (format #t ";; converted from ~a:~a~%~%"
134 (location-file loc) (location-line loc))
135 (pretty-print expr (newline-rewriting-port (current-output-port)))))
137 (leave (_ "wrong number of arguments~%"))))))