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 ;;; Guix
--- Nix package management from Guile.
-*- coding
: utf-8
-*-
15 ;;; Copyright
(C
) 2012 Ludovic Courtès
<ludo@gnu.org
>
17 ;;; This
file is part of Guix.
19 ;;; 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 ;;; 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 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"))
92 Report bugs to: ~a.~%") "@PACKAGE_BUGREPORT@"))
95 ;; Specification of the command-line options.
96 (list (option '(#\h "help") #f #f
100 (option
'(#\V "version") #f #f
102 (show-version-and-exit "guix-import")))))
109 (define (guix-import . args)
110 (define (parse-options)
111 ;; Return the alist of option values.
112 (args-fold args %options
113 (lambda (opt name arg result)
114 (leave (_ "~A: unrecognized option~%") name))
116 (alist-cons 'argument arg result
))
119 (setlocale LC_ALL
"")
121 (setvbuf
(current-output-port
) _IOLBF
)
122 (setvbuf
(current-error-port
) _IOLBF
)
124 (let* ((opts
(parse-options
))
125 (args
(filter-map
(match-lambda
132 (let-values (((expr loc)
133 (nixpkgs->guix-package nixpkgs attribute)))
134 (format #t ";; converted from ~a:~a~%~%"
135 (location-file loc) (location-line loc))
136 (pretty-print expr (newline-rewriting-port (current-output-port)))))
138 (leave (_ "wrong number of arguments~%"))))))