You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

90 lines
2.8 KiB

  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2012, 2013 Ludovic Courtès <ludo@gnu.org>
  3. ;;; Copyright © 2014 David Thompson <davet@gnu.org>
  4. ;;;
  5. ;;; This file is part of GNU Guix.
  6. ;;;
  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.
  11. ;;;
  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.
  16. ;;;
  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/>.
  19. (define-module (guix scripts import nix)
  20. #:use-module (guix ui)
  21. #:use-module (guix utils)
  22. #:use-module (guix import snix)
  23. #:use-module (guix scripts import)
  24. #:use-module (srfi srfi-1)
  25. #:use-module (srfi srfi-11)
  26. #:use-module (srfi srfi-37)
  27. #:use-module (ice-9 match)
  28. #:export (guix-import-nix))
  29. ;;;
  30. ;;; Command-line options.
  31. ;;;
  32. (define %default-options
  33. '())
  34. (define (show-help)
  35. (display (_ "Usage: guix import nix NIXPKGS ATTRIBUTE
  36. Import and convert the Nix expression ATTRIBUTE of NIXPKGS.\n"))
  37. (display (_ "
  38. -h, --help display this help and exit"))
  39. (display (_ "
  40. -V, --version display version information and exit"))
  41. (newline)
  42. (show-bug-report-information))
  43. (define %options
  44. ;; Specification of the command-line options.
  45. (cons* (option '(#\h "help") #f #f
  46. (lambda args
  47. (show-help)
  48. (exit 0)))
  49. (option '(#\V "version") #f #f
  50. (lambda args
  51. (show-version-and-exit "guix import nix")))
  52. %standard-import-options))
  53. ;;;
  54. ;;; Entry point.
  55. ;;;
  56. (define (guix-import-nix . args)
  57. (define (parse-options)
  58. ;; Return the alist of option values.
  59. (args-fold* args %options
  60. (lambda (opt name arg result)
  61. (leave (_ "~A: unrecognized option~%") name))
  62. (lambda (arg result)
  63. (alist-cons 'argument arg result))
  64. %default-options))
  65. (let* ((opts (parse-options))
  66. (args (filter-map (match-lambda
  67. (('argument . value)
  68. value)
  69. (_ #f))
  70. (reverse opts))))
  71. (match args
  72. ((nixpkgs attribute)
  73. (let-values (((expr loc)
  74. (nixpkgs->guix-package nixpkgs attribute)))
  75. (format #t ";; converted from ~a:~a~%~%"
  76. (location-file loc) (location-line loc))
  77. expr))
  78. (_
  79. (leave (_ "wrong number of arguments~%"))))))