gnunet-download.scm 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2018 Pierre Neidhardt <mail@ambrevar.xyz>
  3. ;;; Copyright © 2020 Maxime Devos <maxime.devos@student.kuleuven.be>
  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 gnunet-download)
  20. #:use-module (guix packages)
  21. #:use-module (guix store)
  22. #:use-module (guix monads)
  23. #:use-module (guix gexp)
  24. #:use-module (ice-9 popen)
  25. #:use-module (ice-9 rdelim)
  26. #:export (gnunet-fetch))
  27. ;;; An <origin> method that uses gnunet-download to fetch a specific hash
  28. ;;; the GNUnet file-sharing system. The hash is specified as a GNUnet chk-URI
  29. ;;; string. The code has been derived from (guix gx-download).
  30. ;;;
  31. ;;; Code:
  32. (define (gnunet-package)
  33. "Return the default GNUnet package."
  34. (let ((distro (resolve-interface '(gnu packages gnunet))))
  35. (module-ref distro 'gnunet)))
  36. (define* (gnunet-configuration #:key (gnunet (gnunet-package)))
  37. "Make a configuration file allowing the build process to talk
  38. with the GNUnet FS daemon."
  39. ;; TODO: is it acceptable to assume
  40. ;; the existence of gnunet-config in PATH?
  41. ;; If not, can @var{gnunet} be compiled?
  42. ;; Alternatively, parse .config/gnunet.conf manually.
  43. ;;
  44. ;; TODO: by default, GNUnet uses Unix sockets
  45. ;; instead of IP for IPC. Can we poke a hole
  46. ;; in the build process isolation allowing this
  47. ;; setup?
  48. (let* ((p (open-pipe* OPEN_READ "gnunet-config" "--section" "fs" "-o" "PORT"))
  49. (port (read-line p)))
  50. (close-pipe p)
  51. (values (format #f "[fs]~%PORT = ~a\n" port)
  52. port)))
  53. (define* (gnunet-fetch uri hash-algo hash
  54. #:optional name
  55. #:key (system (%current-system)) (guile (default-guile))
  56. (gnunet (gnunet-package)))
  57. "Return a fixed-output derivation that fetches @var{uri}, a GNUnet chk-URI
  58. string. The output is expected to have hash @var{hash} of type
  59. @var{hash-algo}. Use @var{name} as the file name, or a generic name if #f."
  60. (define build
  61. (with-imported-modules '((guix build gnunet)
  62. (guix build utils))
  63. #~(begin
  64. (use-modules (guix build gnunet))
  65. (or (gnunet-fetch '#$uri
  66. #$output
  67. #:gnunet-download-command
  68. (string-append #+gnunet "/bin/gnunet-download"))))))
  69. (define env-vars
  70. (call-with-values (lambda () (gnunet-configuration #:gnunet gnunet))
  71. (lambda (configuration port)
  72. `(("gnunet configuration" . ,configuration)
  73. ("gnunet port" . ,port)))))
  74. (mlet %store-monad ((guile (package->derivation guile system)))
  75. (gexp->derivation (or name "gnunet-chk") build
  76. #:system system
  77. #:local-build? #t ;; don't offload downloads
  78. #:hash-algo hash-algo
  79. #:hash hash
  80. #:recursive? #f
  81. #:leaked-env-vars '("GNUNET_ANONYMITY")
  82. #:env-vars env-vars
  83. #:guile-for-build guile)))
  84. ;;; gnunet-download.scm ends here