nix.scm 2.9 KB

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