ssh.scm 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2016, 2017, 2018, 2019, 2020 Ludovic Courtès <ludo@gnu.org>
  3. ;;;
  4. ;;; This file is part of GNU Guix.
  5. ;;;
  6. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  7. ;;; under the terms of the GNU General Public License as published by
  8. ;;; the Free Software Foundation; either version 3 of the License, or (at
  9. ;;; your option) any later version.
  10. ;;;
  11. ;;; GNU Guix is distributed in the hope that it will be useful, but
  12. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;;; GNU General Public License for more details.
  15. ;;;
  16. ;;; You should have received a copy of the GNU General Public License
  17. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  18. (define-module (guix ssh)
  19. #:use-module (guix store)
  20. #:use-module (guix inferior)
  21. #:use-module (guix i18n)
  22. #:use-module ((guix diagnostics)
  23. #:select (info &fix-hint formatted-message))
  24. #:use-module ((guix progress)
  25. #:select (progress-bar
  26. erase-current-line current-terminal-columns))
  27. #:use-module (gcrypt pk-crypto)
  28. #:use-module (ssh session)
  29. #:use-module (ssh auth)
  30. #:use-module (ssh key)
  31. #:use-module (ssh channel)
  32. #:use-module (ssh popen)
  33. #:use-module (ssh session)
  34. #:use-module (srfi srfi-1)
  35. #:use-module (srfi srfi-11)
  36. #:use-module (srfi srfi-26)
  37. #:use-module (srfi srfi-34)
  38. #:use-module (srfi srfi-35)
  39. #:use-module (ice-9 match)
  40. #:use-module (ice-9 format)
  41. #:use-module (ice-9 binary-ports)
  42. #:use-module (ice-9 vlist)
  43. #:export (open-ssh-session
  44. authenticate-server*
  45. remote-inferior
  46. remote-daemon-channel
  47. connect-to-remote-daemon
  48. remote-system
  49. remote-authorize-signing-key
  50. send-files
  51. retrieve-files
  52. retrieve-files*
  53. remote-store-host
  54. report-guile-error
  55. report-module-error))
  56. ;;; Commentary:
  57. ;;;
  58. ;;; This module provides tools to support communication with remote stores
  59. ;;; over SSH, using Guile-SSH.
  60. ;;;
  61. ;;; Code:
  62. (define %compression
  63. "zlib@openssh.com,zlib")
  64. (define (host-key->type+key host-key)
  65. "Destructure HOST-KEY, an OpenSSH host key string, and return two values:
  66. its key type as a symbol, and the actual base64-encoded string."
  67. (define (type->symbol type)
  68. (and (string-prefix? "ssh-" type)
  69. (string->symbol (string-drop type 4))))
  70. (match (string-tokenize host-key)
  71. ((type key x)
  72. (values (type->symbol type) key))
  73. ((type key)
  74. (values (type->symbol type) key))))
  75. (define (authenticate-server* session key)
  76. "Make sure the server for SESSION has the given KEY, where KEY is a string
  77. such as \"ssh-ed25519 AAAAC3Nz… root@example.org\". Raise an exception if the
  78. actual key does not match."
  79. (let-values (((server) (get-server-public-key session))
  80. ((type key) (host-key->type+key key)))
  81. (unless (and (or (not (get-key-type server))
  82. (eq? (get-key-type server) type))
  83. (string=? (public-key->string server) key))
  84. ;; Key mismatch: something's wrong. XXX: It could be that the server
  85. ;; provided its Ed25519 key when we where expecting its RSA key. XXX:
  86. ;; Guile-SSH 0.10.1 doesn't know about ed25519 keys and 'get-key-type'
  87. ;; returns #f in that case.
  88. (raise (formatted-message (G_ "server at '~a' returned host key \
  89. '~a' of type '~a' instead of '~a' of type '~a'~%")
  90. (session-get session 'host)
  91. (public-key->string server)
  92. (get-key-type server)
  93. key type)))))
  94. (define* (open-ssh-session host #:key user port identity
  95. host-key
  96. (compression %compression)
  97. (timeout 3600))
  98. "Open an SSH session for HOST and return it. IDENTITY specifies the file
  99. name of a private key to use for authenticating with the host. When USER,
  100. PORT, or IDENTITY are #f, use default values or whatever '~/.ssh/config'
  101. specifies; otherwise use them.
  102. When HOST-KEY is true, it must be a string like \"ssh-ed25519 AAAAC3Nz…
  103. root@example.org\"; the server is authenticated and an error is raised if its
  104. host key is different from HOST-KEY.
  105. Install TIMEOUT as the maximum time in seconds after which a read or write
  106. operation on a channel of the returned session is considered as failing.
  107. Throw an error on failure."
  108. (let ((session (make-session #:user user
  109. #:identity identity
  110. #:host host
  111. #:port port
  112. #:timeout 10 ;seconds
  113. ;; #:log-verbosity 'protocol
  114. ;; Prevent libssh from reading
  115. ;; ~/.ssh/known_hosts when the caller provides
  116. ;; a HOST-KEY to match against.
  117. #:knownhosts (and host-key "/dev/null")
  118. ;; We need lightweight compression when
  119. ;; exchanging full archives.
  120. #:compression compression
  121. #:compression-level 3
  122. ;; Speed up RPCs by creating sockets with
  123. ;; TCP_NODELAY.
  124. #:nodelay #t)))
  125. ;; Honor ~/.ssh/config.
  126. (session-parse-config! session)
  127. (match (connect! session)
  128. ('ok
  129. (if host-key
  130. ;; Make sure the server's key is what we expect.
  131. (authenticate-server* session host-key)
  132. ;; Authenticate against ~/.ssh/known_hosts.
  133. (match (authenticate-server session)
  134. ('ok #f)
  135. (reason
  136. (raise (formatted-message (G_ "failed to authenticate \
  137. server at '~a': ~a")
  138. (session-get session 'host)
  139. reason)))))
  140. ;; Use public key authentication, via the SSH agent if it's available.
  141. (match (userauth-public-key/auto! session)
  142. ('success
  143. (session-set! session 'timeout timeout)
  144. session)
  145. (x
  146. (match (userauth-gssapi! session)
  147. ('success
  148. (session-set! session 'timeout timeout)
  149. session)
  150. (x
  151. (disconnect! session)
  152. (raise (condition
  153. (&message
  154. (message (format #f (G_ "SSH authentication failed for '~a': ~a~%")
  155. host (get-error session)))))))))))
  156. (x
  157. ;; Connection failed or timeout expired.
  158. (raise (formatted-message (G_ "SSH connection to '~a' failed: ~a~%")
  159. host (get-error session)))))))
  160. (define* (remote-inferior session #:optional become-command)
  161. "Return a remote inferior for the given SESSION. If BECOME-COMMAND is
  162. given, use that to invoke the remote Guile REPL."
  163. (let* ((repl-command (append (or become-command '())
  164. '("guix" "repl" "-t" "machine")))
  165. (pipe (apply open-remote-pipe* session OPEN_BOTH repl-command)))
  166. (when (eof-object? (peek-char pipe))
  167. (let ((status (channel-get-exit-status pipe)))
  168. (close-port pipe)
  169. (raise (formatted-message (G_ "remote command '~{~a~^ ~}' failed \
  170. with status ~a")
  171. repl-command status))))
  172. (port->inferior pipe)))
  173. (define* (inferior-remote-eval exp session #:optional become-command)
  174. "Evaluate EXP in a new inferior running in SESSION, and close the inferior
  175. right away. If BECOME-COMMAND is given, use that to invoke the remote Guile
  176. REPL."
  177. (let ((inferior (remote-inferior session become-command)))
  178. (dynamic-wind
  179. (const #t)
  180. (lambda ()
  181. (inferior-eval exp inferior))
  182. (lambda ()
  183. ;; Close INFERIOR right away to prevent finalization from happening in
  184. ;; another thread at the wrong time (see
  185. ;; <https://bugs.gnu.org/26976>.)
  186. (close-inferior inferior)))))
  187. (define* (remote-daemon-channel session
  188. #:optional
  189. (socket-name
  190. "/var/guix/daemon-socket/socket"))
  191. "Return an input/output port (an SSH channel) to the daemon at SESSION."
  192. (define redirect
  193. ;; Code run in SESSION to redirect the remote process' stdin/stdout to the
  194. ;; daemon's socket, à la socat. The SSH protocol supports forwarding to
  195. ;; Unix-domain sockets but libssh doesn't have an API for that, hence this
  196. ;; hack.
  197. `(begin
  198. (use-modules (ice-9 match) (rnrs io ports)
  199. (rnrs bytevectors))
  200. (let ((sock (socket AF_UNIX SOCK_STREAM 0))
  201. (stdin (current-input-port))
  202. (stdout (current-output-port))
  203. (select* (lambda (read write except)
  204. ;; This is a workaround for
  205. ;; <https://bugs.gnu.org/30365> in Guile < 2.2.4:
  206. ;; since 'select' sometimes returns non-empty sets for
  207. ;; no good reason, call 'select' a second time with a
  208. ;; zero timeout to filter out incorrect replies.
  209. (match (select read write except)
  210. ((read write except)
  211. (select read write except 0))))))
  212. (setvbuf stdout 'none)
  213. ;; Use buffered ports so that 'get-bytevector-some' returns up to the
  214. ;; whole buffer like read(2) would--see <https://bugs.gnu.org/30066>.
  215. (setvbuf stdin 'block 65536)
  216. (setvbuf sock 'block 65536)
  217. (connect sock AF_UNIX ,socket-name)
  218. (let loop ()
  219. (match (select* (list stdin sock) '() '())
  220. ((reads () ())
  221. (when (memq stdin reads)
  222. (match (get-bytevector-some stdin)
  223. ((? eof-object?)
  224. (primitive-exit 0))
  225. (bv
  226. (put-bytevector sock bv)
  227. (force-output sock))))
  228. (when (memq sock reads)
  229. (match (get-bytevector-some sock)
  230. ((? eof-object?)
  231. (primitive-exit 0))
  232. (bv
  233. (put-bytevector stdout bv))))
  234. (loop))
  235. (_
  236. (primitive-exit 1)))))))
  237. (open-remote-pipe* session OPEN_BOTH
  238. ;; Sort-of shell-quote REDIRECT.
  239. "guile" "-c"
  240. (object->string
  241. (object->string redirect))))
  242. (define* (connect-to-remote-daemon session
  243. #:optional
  244. (socket-name
  245. "/var/guix/daemon-socket/socket"))
  246. "Connect to the remote build daemon listening on SOCKET-NAME over SESSION,
  247. an SSH session. Return a <store-connection> object."
  248. (open-connection #:port (remote-daemon-channel session socket-name)))
  249. (define (store-import-channel session)
  250. "Return an output port to which archives to be exported to SESSION's store
  251. can be written."
  252. ;; Using the 'import-paths' RPC on a remote store would be slow because it
  253. ;; makes a round trip every time 32 KiB have been transferred. This
  254. ;; procedure instead opens a separate channel to use the remote
  255. ;; 'import-paths' procedure, which consumes all the data in a single round
  256. ;; trip. This optimizes the successful case at the expense of error
  257. ;; conditions: errors can only be reported once all the input has been
  258. ;; consumed.
  259. (define import
  260. `(begin
  261. (eval-when (load expand eval)
  262. (unless (resolve-module '(guix) #:ensure #f)
  263. (write `(module-error))
  264. (exit 7)))
  265. (use-modules (guix) (srfi srfi-34)
  266. (rnrs io ports) (rnrs bytevectors))
  267. (define (consume-input port)
  268. (let ((bv (make-bytevector 32768)))
  269. (let loop ()
  270. (let ((n (get-bytevector-n! port bv 0
  271. (bytevector-length bv))))
  272. (unless (eof-object? n)
  273. (loop))))))
  274. ;; Upon completion, write an sexp that denotes the status.
  275. (write
  276. (catch #t
  277. (lambda ()
  278. (guard (c ((nix-protocol-error? c)
  279. ;; Consume all the input since the only time we can
  280. ;; report the error is after everything has been
  281. ;; consumed.
  282. (consume-input (current-input-port))
  283. (list 'protocol-error (nix-protocol-error-message c))))
  284. (with-store store
  285. (write '(importing)) ;we're ready
  286. (force-output)
  287. (setvbuf (current-input-port) 'none)
  288. (import-paths store (current-input-port))
  289. '(success))))
  290. (lambda args
  291. (cons 'error args))))))
  292. (open-remote-pipe session
  293. (string-join
  294. `("guile" "-c"
  295. ,(object->string (object->string import))))
  296. OPEN_BOTH))
  297. (define* (store-export-channel session files
  298. #:key recursive?)
  299. "Return an input port from which an export of FILES from SESSION's store can
  300. be read. When RECURSIVE? is true, the closure of FILES is exported."
  301. ;; Same as above: this is more efficient than calling 'export-paths' on a
  302. ;; remote store.
  303. (define export
  304. `(begin
  305. (eval-when (load expand eval)
  306. (unless (resolve-module '(guix) #:ensure #f)
  307. (write `(module-error))
  308. (exit 7)))
  309. (use-modules (guix) (srfi srfi-1)
  310. (srfi srfi-26) (srfi srfi-34))
  311. (guard (c ((nix-connection-error? c)
  312. (write `(connection-error ,(nix-connection-error-file c)
  313. ,(nix-connection-error-code c))))
  314. ((nix-protocol-error? c)
  315. (write `(protocol-error ,(nix-protocol-error-status c)
  316. ,(nix-protocol-error-message c))))
  317. (else
  318. (write `(exception))))
  319. (with-store store
  320. (let* ((files ',files)
  321. (invalid (remove (cut valid-path? store <>)
  322. files)))
  323. (unless (null? invalid)
  324. (write `(invalid-items ,invalid))
  325. (exit 1))
  326. ;; TODO: When RECURSIVE? is true, we could send the list of store
  327. ;; items in the closure so that the other end can filter out
  328. ;; those it already has.
  329. (write '(exporting)) ;we're ready
  330. (force-output)
  331. (setvbuf (current-output-port) 'none)
  332. (export-paths store files (current-output-port)
  333. #:recursive? ,recursive?))))))
  334. (open-remote-input-pipe session
  335. (string-join
  336. `("guile" "-c"
  337. ,(object->string
  338. (object->string export))))))
  339. (define (remote-system session)
  340. "Return the system type as expected by Nix, usually ARCHITECTURE-KERNEL, of
  341. the machine on the other end of SESSION."
  342. (inferior-remote-eval '(begin (use-modules (guix utils)) (%current-system))
  343. session))
  344. (define* (remote-authorize-signing-key key session #:optional become-command)
  345. "Send KEY, a canonical sexp containing a public key, over SESSION and add it
  346. to the system ACL file if it has not yet been authorized."
  347. (inferior-remote-eval
  348. `(begin
  349. (use-modules (guix build utils)
  350. (guix pki)
  351. (guix utils)
  352. (gcrypt pk-crypto)
  353. (srfi srfi-26))
  354. (define acl (current-acl))
  355. (define key (string->canonical-sexp ,(canonical-sexp->string key)))
  356. (unless (authorized-key? key)
  357. (let ((acl (public-keys->acl (cons key (acl->public-keys acl)))))
  358. (mkdir-p (dirname %acl-file))
  359. (with-atomic-file-output %acl-file
  360. (cut write-acl acl <>)))))
  361. session
  362. become-command))
  363. (define (prepare-to-send store host log-port items)
  364. "Notify the user that we're about to send ITEMS to HOST. Return three
  365. values allowing 'notify-send-progress' to track the state of this transfer."
  366. (let* ((count (length items))
  367. (sizes (fold (lambda (item result)
  368. (vhash-cons item
  369. (path-info-nar-size
  370. (query-path-info store item))
  371. result))
  372. vlist-null
  373. items))
  374. (total (vlist-fold (lambda (pair result)
  375. (match pair
  376. ((_ . size) (+ size result))))
  377. 0
  378. sizes)))
  379. (info (N_ "sending ~a store item (~h MiB) to '~a'...~%"
  380. "sending ~a store items (~h MiB) to '~a'...~%" count)
  381. count
  382. (inexact->exact (round (/ total (expt 2. 20))))
  383. host)
  384. (values log-port sizes total 0)))
  385. (define (notify-transfer-progress item port sizes total sent)
  386. "Notify the user that we've already transferred SENT bytes out of TOTAL.
  387. Use SIZES to determine the size of ITEM, which is about to be sent."
  388. (define (display-bar %)
  389. (erase-current-line port)
  390. (format port "~3@a% ~a"
  391. (inexact->exact (round (* 100. (/ sent total))))
  392. (progress-bar % (- (max (current-terminal-columns) 5) 5)))
  393. (force-output port))
  394. (unless (zero? total)
  395. (let ((% (* 100. (/ sent total))))
  396. (match (vhash-assoc item sizes)
  397. (#f
  398. (display-bar %)
  399. (values port sizes total sent))
  400. ((_ . size)
  401. (display-bar %)
  402. (values port sizes total (+ sent size)))))))
  403. (define (notify-transfer-completion port . args)
  404. "Notify the user that the transfer has completed."
  405. (apply notify-transfer-progress "" port args) ;display the 100% progress bar
  406. (erase-current-line port)
  407. (force-output port))
  408. (define* (send-files local files remote
  409. #:key
  410. recursive?
  411. (log-port (current-error-port)))
  412. "Send the subset of FILES from LOCAL (a local store) that's missing to
  413. REMOTE, a remote store. When RECURSIVE? is true, send the closure of FILES.
  414. Return the list of store items actually sent."
  415. ;; Compute the subset of FILES missing on SESSION and send them.
  416. (let* ((files (if recursive? (requisites local files) files))
  417. (session (channel-get-session (store-connection-socket remote)))
  418. (missing (inferior-remote-eval
  419. `(begin
  420. (use-modules (guix)
  421. (srfi srfi-1) (srfi srfi-26))
  422. (with-store store
  423. (remove (cut valid-path? store <>)
  424. ',files)))
  425. session))
  426. (port (store-import-channel session))
  427. (host (session-get session 'host)))
  428. ;; Make sure everything alright on the remote side.
  429. (match (read port)
  430. (('importing)
  431. #t)
  432. (sexp
  433. (handle-import/export-channel-error sexp remote)))
  434. ;; Send MISSING in topological order.
  435. (let ((tty? (isatty? log-port)))
  436. (export-paths local missing port
  437. #:start (cut prepare-to-send local host log-port <>)
  438. #:progress (if tty? notify-transfer-progress (const #f))
  439. #:finish (if tty? notify-transfer-completion (const #f))))
  440. ;; Tell the remote process that we're done. (In theory the end-of-archive
  441. ;; mark of 'export-paths' would be enough, but in practice it's not.)
  442. (channel-send-eof port)
  443. ;; Wait for completion of the remote process and read the status sexp from
  444. ;; PORT. Wait for the exit status only when 'read' completed; otherwise,
  445. ;; we might wait forever if the other end is stuck.
  446. (let* ((result (false-if-exception (read port)))
  447. (status (and result
  448. (zero? (channel-get-exit-status port)))))
  449. (close-port port)
  450. (match result
  451. (('success . _)
  452. missing)
  453. (('protocol-error message)
  454. (raise (condition
  455. (&store-protocol-error (message message) (status 42)))))
  456. (('error key args ...)
  457. (raise (condition
  458. (&store-protocol-error
  459. (message (call-with-output-string
  460. (lambda (port)
  461. (print-exception port #f key args))))
  462. (status 43)))))
  463. (_
  464. (raise (condition
  465. (&store-protocol-error
  466. (message "unknown error while sending files over SSH")
  467. (status 44)))))))))
  468. (define (remote-store-session remote)
  469. "Return the SSH channel beneath REMOTE, a remote store as returned by
  470. 'connect-to-remote-daemon', or #f."
  471. (channel-get-session (store-connection-socket remote)))
  472. (define (remote-store-host remote)
  473. "Return the name of the host REMOTE is connected to, where REMOTE is a
  474. remote store as returned by 'connect-to-remote-daemon'."
  475. (match (remote-store-session remote)
  476. (#f #f)
  477. ((? session? session)
  478. (session-get session 'host))))
  479. (define* (file-retrieval-port files remote
  480. #:key recursive?)
  481. "Return an input port from which to retrieve FILES (a list of store items)
  482. from REMOTE, along with the number of items to retrieve (lower than or equal
  483. to the length of FILES.)"
  484. (values (store-export-channel (remote-store-session remote) files
  485. #:recursive? recursive?)
  486. (length files))) ;XXX: inaccurate when RECURSIVE? is true
  487. (define-syntax raise-error
  488. (syntax-rules (=>)
  489. ((_ fmt args ... (=> hint-fmt hint-args ...))
  490. (raise (condition
  491. (&message
  492. (message (format #f fmt args ...)))
  493. (&fix-hint
  494. (hint (format #f hint-fmt hint-args ...))))))
  495. ((_ fmt args ...)
  496. (raise (condition
  497. (&message
  498. (message (format #f fmt args ...))))))))
  499. (define (handle-import/export-channel-error sexp remote)
  500. "Report an error corresponding to SEXP, the EOF object or an sexp read from
  501. REMOTE."
  502. (match sexp
  503. ((? eof-object?)
  504. (report-guile-error (remote-store-host remote)))
  505. (('module-error . _)
  506. (report-module-error (remote-store-host remote)))
  507. (('connection-error file code . _)
  508. (raise-error (G_ "failed to connect to '~A' on remote host '~A': ~a")
  509. file (remote-store-host remote) (strerror code)))
  510. (('invalid-items items . _)
  511. (raise-error (N_ "no such item on remote host '~A':~{ ~a~}"
  512. "no such items on remote host '~A':~{ ~a~}"
  513. (length items))
  514. (remote-store-host remote) items))
  515. (('protocol-error status message . _)
  516. (raise-error (G_ "protocol error on remote host '~A': ~a")
  517. (remote-store-host remote) message))
  518. (_
  519. (raise-error (G_ "failed to retrieve store items from '~a'")
  520. (remote-store-host remote)))))
  521. (define* (retrieve-files* files remote
  522. #:key recursive? (log-port (current-error-port))
  523. (import (const #f)))
  524. "Pass IMPORT an input port from which to read the sequence of FILES coming
  525. from REMOTE. When RECURSIVE? is true, retrieve the closure of FILES."
  526. (let-values (((port count)
  527. (file-retrieval-port files remote
  528. #:recursive? recursive?)))
  529. (match (read port) ;read the initial status
  530. (('exporting)
  531. (format #t (N_ "retrieving ~a store item from '~a'...~%"
  532. "retrieving ~a store items from '~a'...~%" count)
  533. count (remote-store-host remote))
  534. (dynamic-wind
  535. (const #t)
  536. (lambda ()
  537. (import port))
  538. (lambda ()
  539. (close-port port))))
  540. (sexp
  541. (handle-import/export-channel-error sexp remote)))))
  542. (define* (retrieve-files local files remote
  543. #:key recursive? (log-port (current-error-port)))
  544. "Retrieve FILES from REMOTE and import them using the 'import-paths' RPC on
  545. LOCAL. When RECURSIVE? is true, retrieve the closure of FILES."
  546. (retrieve-files* (remove (cut valid-path? local <>) files)
  547. remote
  548. #:recursive? recursive?
  549. #:log-port log-port
  550. #:import (lambda (port)
  551. (import-paths local port))))
  552. ;;;
  553. ;;; Error reporting.
  554. ;;;
  555. (define (report-guile-error host)
  556. (raise-error (G_ "failed to start Guile on remote host '~A'") host
  557. (=> (G_ "Make sure @command{guile} can be found in
  558. @code{$PATH} on the remote host. Run @command{ssh ~A guile --version} to
  559. check.")
  560. host)))
  561. (define (report-module-error host)
  562. "Report an error about missing Guix modules on HOST."
  563. ;; TRANSLATORS: Leave "Guile" untranslated.
  564. (raise-error (G_ "Guile modules not found on remote host '~A'") host
  565. (=> (G_ "Make sure @code{GUILE_LOAD_PATH} includes Guix'
  566. own module directory. Run @command{ssh ~A env | grep GUILE_LOAD_PATH} to
  567. check.")
  568. host)))
  569. (define (report-inferior-exception exception host)
  570. "Report EXCEPTION, an &inferior-exception that occurred on HOST."
  571. (raise-error (G_ "exception occurred on remote host '~A': ~s")
  572. host (inferior-exception-arguments exception)))
  573. ;;; ssh.scm ends here