1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2012, 2013, 2016 Ludovic Courtès <ludo@gnu.org>
3 ;;; Copyright © 2014 David Thompson <davet@gnu.org>
5 ;;; This file is part of GNU Guix.
7 ;;; GNU Guix is free software; you can redistribute it and/or modify it
8 ;;; under the terms of the GNU General Public License as published by
9 ;;; the Free Software Foundation; either version 3 of the License, or (at
10 ;;; your option) any later version.
12 ;;; GNU Guix is distributed in the hope that it will be useful, but
13 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;;; GNU General Public License for more details.
17 ;;; You should have received a copy of the GNU General Public License
18 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
20 (define-module (guix scripts import nix)
21 #:use-module (guix ui)
22 #:use-module (guix utils)
23 #:use-module (guix scripts)
24 #:use-module (guix import snix)
25 #:use-module (guix scripts import)
26 #:use-module (srfi srfi-1)
27 #:use-module (srfi srfi-11)
28 #:use-module (srfi srfi-37)
29 #:use-module (ice-9 match)
30 #:export (guix-import-nix))
34 ;;; Command-line options.
37 (define %default-options
41 (display (G_ "Usage: guix import nix NIXPKGS ATTRIBUTE
42 Import and convert the Nix expression ATTRIBUTE of NIXPKGS.\n"))
44 -h, --help display this help and exit"))
46 -V, --version display version information and exit"))
48 (show-bug-report-information))
51 ;; Specification of the command-line options.
52 (cons* (option '(#\h "help") #f #f
56 (option '(#\V "version") #f #f
58 (show-version-and-exit "guix import nix")))
59 %standard-import-options))
66 (define (guix-import-nix . args)
67 (define (parse-options)
68 ;; Return the alist of option values.
69 (args-fold* args %options
70 (lambda (opt name arg result)
71 (leave (G_ "~A: unrecognized option~%") name))
73 (alist-cons 'argument arg result))
76 (let* ((opts (parse-options))
77 (args (filter-map (match-lambda
84 (let-values (((expr loc)
85 (nixpkgs->guix-package nixpkgs attribute)))
86 (format #t ";; converted from ~a:~a~%~%"
87 (location-file loc) (location-line loc))
90 (leave (G_ "wrong number of arguments~%"))))))