substitute.scm 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2014 Nikita Karetnikov <nikita@karetnikov.org>
  3. ;;; Copyright © 2014, 2015, 2017, 2018, 2019, 2021 Ludovic Courtès <ludo@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 (test-substitute)
  20. #:use-module (guix scripts substitute)
  21. #:use-module (guix narinfo)
  22. #:use-module (guix base64)
  23. #:use-module (gcrypt hash)
  24. #:use-module (guix serialization)
  25. #:use-module (gcrypt pk-crypto)
  26. #:use-module (guix pki)
  27. #:use-module (guix config)
  28. #:use-module (guix base32)
  29. #:use-module ((guix store) #:select (%store-prefix))
  30. #:use-module ((guix ui) #:select (guix-warning-port))
  31. #:use-module ((guix utils)
  32. #:select (call-with-temporary-directory
  33. call-with-compressed-output-port))
  34. #:use-module ((guix build utils)
  35. #:select (mkdir-p delete-file-recursively dump-port))
  36. #:use-module (guix tests http)
  37. #:use-module (rnrs bytevectors)
  38. #:use-module (rnrs io ports)
  39. #:use-module (web uri)
  40. #:use-module (ice-9 regex)
  41. #:use-module (srfi srfi-11)
  42. #:use-module (srfi srfi-26)
  43. #:use-module (srfi srfi-34)
  44. #:use-module (srfi srfi-35)
  45. #:use-module ((srfi srfi-64) #:hide (test-error)))
  46. (define-syntax-rule (test-quit name error-rx exp)
  47. "Emit a test that passes when EXP throws to 'quit' with value 1, and when
  48. it writes to GUIX-WARNING-PORT a messages that matches ERROR-RX."
  49. (test-equal name
  50. '(1 #t)
  51. (let ((error-output (open-output-string)))
  52. (parameterize ((current-error-port error-output)
  53. (guix-warning-port error-output))
  54. (catch 'quit
  55. (lambda ()
  56. exp
  57. #f)
  58. (lambda (key value)
  59. (list value
  60. (let ((message (get-output-string error-output)))
  61. (->bool (string-match error-rx message))))))))))
  62. (define (request-substitution item destination)
  63. "Run 'guix substitute --substitute' to fetch ITEM to DESTINATION."
  64. (parameterize ((guix-warning-port (current-error-port)))
  65. (with-input-from-string (string-append "substitute " item " "
  66. destination "\n")
  67. (lambda ()
  68. (guix-substitute "--substitute")))))
  69. (define %public-key
  70. ;; This key is known to be in the ACL by default.
  71. (call-with-input-file (string-append %config-directory "/signing-key.pub")
  72. (compose string->canonical-sexp get-string-all)))
  73. (define %private-key
  74. (call-with-input-file (string-append %config-directory "/signing-key.sec")
  75. (compose string->canonical-sexp get-string-all)))
  76. (define* (signature-body bv #:key (public-key %public-key))
  77. "Return the signature of BV as the base64-encoded body of a narinfo's
  78. 'Signature' field."
  79. (base64-encode
  80. (string->utf8
  81. (canonical-sexp->string
  82. (signature-sexp (bytevector->hash-data (sha256 bv)
  83. #:key-type 'rsa)
  84. %private-key
  85. public-key)))))
  86. (define %wrong-public-key
  87. (string->canonical-sexp "(public-key
  88. (rsa
  89. (n #00E05873AC2B168760343145918E954EE9AB73C026355693B192E01EE835261AA689E9EF46642E895BCD65C648524059FC450E4BA77A68F4C52D0E39EF0CC9359709AB6AAB153B63782201871325B0FDA19CB401CD99FD0C31A91CA9000AA90A77E82B89E036FB63BC1D3961207469B3B12468977148D376F8012BB12A4B11A8F1#)
  90. (e #010001#)
  91. )
  92. )"))
  93. (define* (signature-field bv-or-str
  94. #:key (version "1") (public-key %public-key))
  95. "Return the 'Signature' field value of bytevector/string BV-OR-STR, using
  96. PUBLIC-KEY as the signature's principal, and using VERSION as the signature
  97. version identifier.."
  98. (string-append version ";example.gnu.org;"
  99. (signature-body (if (string? bv-or-str)
  100. (string->utf8 bv-or-str)
  101. bv-or-str)
  102. #:public-key public-key)))
  103. (test-begin "substitute")
  104. (test-quit "not a number"
  105. "signature version"
  106. (narinfo-signature->canonical-sexp
  107. (signature-field "foo" #:version "not a number")))
  108. (test-quit "wrong version number"
  109. "unsupported.*version"
  110. (narinfo-signature->canonical-sexp
  111. (signature-field "foo" #:version "2")))
  112. (test-assert "valid narinfo-signature->canonical-sexp"
  113. (canonical-sexp? (narinfo-signature->canonical-sexp (signature-field "foo"))))
  114. (define %main-substitute-directory
  115. ;; The place where 'call-with-narinfo' stores its data by default.
  116. (uri-path (string->uri (getenv "GUIX_BINARY_SUBSTITUTE_URL"))))
  117. (define %alternate-substitute-directory
  118. ;; Another place.
  119. (string-append (dirname %main-substitute-directory)
  120. "/substituter-alt-data"))
  121. (define %narinfo
  122. ;; Skeleton of the narinfo used below.
  123. (string-append "StorePath: " (%store-prefix)
  124. "/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-foo
  125. URL: example.nar
  126. Compression: none
  127. NarHash: sha256:" (bytevector->nix-base32-string
  128. (sha256 (string->utf8 "Substitutable data."))) "
  129. NarSize: 42
  130. References: bar baz
  131. Deriver: " (%store-prefix) "/foo.drv
  132. System: mips64el-linux\n"))
  133. (define* (call-with-narinfo narinfo thunk
  134. #:optional
  135. (narinfo-directory %main-substitute-directory))
  136. "Call THUNK in a context where the directory at URL is populated with
  137. a file for NARINFO."
  138. (mkdir-p narinfo-directory)
  139. (let ((cache-directory (string-append (getenv "XDG_CACHE_HOME")
  140. "/guix/substitute/")))
  141. (dynamic-wind
  142. (lambda ()
  143. (when (file-exists? cache-directory)
  144. (delete-file-recursively cache-directory))
  145. (call-with-output-file (string-append narinfo-directory
  146. "/nix-cache-info")
  147. (lambda (port)
  148. (format port "StoreDir: ~a\nWantMassQuery: 0\n"
  149. (%store-prefix))))
  150. (call-with-output-file (string-append narinfo-directory "/"
  151. "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
  152. ".narinfo")
  153. (cut display narinfo <>))
  154. ;; Prepare the nar.
  155. (call-with-output-file
  156. (string-append narinfo-directory "/example.out")
  157. (cut display "Substitutable data." <>))
  158. (call-with-output-file
  159. (string-append narinfo-directory "/example.nar")
  160. (cute write-file
  161. (string-append narinfo-directory "/example.out") <>))
  162. (%allow-unauthenticated-substitutes? #f))
  163. thunk
  164. (lambda ()
  165. (when (file-exists? cache-directory)
  166. (delete-file-recursively cache-directory))))))
  167. (define-syntax-rule (with-narinfo narinfo body ...)
  168. (call-with-narinfo narinfo (lambda () body ...)))
  169. (define-syntax-rule (with-narinfo* narinfo directory body ...)
  170. (call-with-narinfo narinfo (lambda () body ...) directory))
  171. ;; Transmit these options to 'guix substitute'.
  172. (substitute-urls (list (getenv "GUIX_BINARY_SUBSTITUTE_URL")))
  173. ;; Never use file descriptor 4, unlike what happens when invoked by the
  174. ;; daemon.
  175. (%reply-file-descriptor #f)
  176. (test-equal "query narinfo without signature"
  177. "" ; not substitutable
  178. (with-narinfo %narinfo
  179. (string-trim-both
  180. (with-output-to-string
  181. (lambda ()
  182. (with-input-from-string (string-append "have " (%store-prefix)
  183. "/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-foo")
  184. (lambda ()
  185. (guix-substitute "--query"))))))))
  186. (test-equal "query narinfo with invalid hash"
  187. ;; The hash in the signature differs from the hash of %NARINFO.
  188. ""
  189. (with-narinfo (string-append %narinfo "Signature: "
  190. (signature-field "different body")
  191. "\n")
  192. (string-trim-both
  193. (with-output-to-string
  194. (lambda ()
  195. (with-input-from-string (string-append "have " (%store-prefix)
  196. "/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-foo")
  197. (lambda ()
  198. (guix-substitute "--query"))))))))
  199. (test-equal "query narinfo with signature over nothing"
  200. ;; The signature is computed over the empty string, not over the important
  201. ;; parts, so the narinfo must be ignored.
  202. ""
  203. (with-narinfo (string-append "Signature: " (signature-field "") "\n"
  204. %narinfo "\n")
  205. (string-trim-both
  206. (with-output-to-string
  207. (lambda ()
  208. (with-input-from-string (string-append "have " (%store-prefix)
  209. "/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-foo")
  210. (lambda ()
  211. (guix-substitute "--query"))))))))
  212. (test-equal "query narinfo with signature over irrelevant bits"
  213. ;; The signature is valid but it does not cover the
  214. ;; StorePath/NarHash/References tuple and is thus irrelevant; the narinfo
  215. ;; must be ignored.
  216. ""
  217. (let ((prefix (string-append "StorePath: " (%store-prefix)
  218. "/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-foo
  219. URL: example.nar
  220. Compression: none\n")))
  221. (with-narinfo (string-append prefix
  222. "Signature: " (signature-field prefix) "
  223. NarHash: sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
  224. NarSize: 42
  225. References: bar baz
  226. Deriver: " (%store-prefix) "/foo.drv
  227. System: mips64el-linux\n")
  228. (string-trim-both
  229. (with-output-to-string
  230. (lambda ()
  231. (with-input-from-string (string-append "have " (%store-prefix)
  232. "/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-foo")
  233. (lambda ()
  234. (guix-substitute "--query")))))))))
  235. (test-equal "query narinfo signed with authorized key"
  236. (string-append (%store-prefix) "/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-foo")
  237. (with-narinfo (string-append %narinfo "Signature: "
  238. (signature-field %narinfo)
  239. "\n")
  240. (string-trim-both
  241. (with-output-to-string
  242. (lambda ()
  243. (with-input-from-string (string-append "have " (%store-prefix)
  244. "/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-foo")
  245. (lambda ()
  246. (guix-substitute "--query"))))))))
  247. (test-equal "query narinfo signed with unauthorized key"
  248. "" ; not substitutable
  249. (with-narinfo (string-append %narinfo "Signature: "
  250. (signature-field
  251. %narinfo
  252. #:public-key %wrong-public-key)
  253. "\n")
  254. (string-trim-both
  255. (with-output-to-string
  256. (lambda ()
  257. (with-input-from-string (string-append "have " (%store-prefix)
  258. "/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-foo")
  259. (lambda ()
  260. (guix-substitute "--query"))))))))
  261. (test-quit "substitute, no signature"
  262. "no valid substitute"
  263. (with-narinfo %narinfo
  264. (with-input-from-string (string-append "substitute "
  265. (%store-prefix)
  266. "/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-foo"
  267. " foo\n")
  268. (lambda ()
  269. (guix-substitute "--substitute")))))
  270. (test-quit "substitute, invalid narinfo hash"
  271. "no valid substitute"
  272. ;; The hash in the signature differs from the hash of %NARINFO.
  273. (with-narinfo (string-append %narinfo "Signature: "
  274. (signature-field "different body")
  275. "\n")
  276. (with-input-from-string (string-append "substitute "
  277. (%store-prefix)
  278. "/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-foo"
  279. " foo\n")
  280. (lambda ()
  281. (guix-substitute "--substitute")))))
  282. (test-equal "substitute, invalid hash"
  283. (string-append "hash-mismatch sha256 "
  284. (bytevector->nix-base32-string (sha256 #vu8())) " "
  285. (let-values (((port get-hash)
  286. (open-hash-port (hash-algorithm sha256)))
  287. ((content)
  288. "Substitutable data."))
  289. (write-file-tree "foo" port
  290. #:file-type+size
  291. (lambda _
  292. (values 'regular
  293. (string-length content)))
  294. #:file-port
  295. (lambda _
  296. (open-input-string content)))
  297. (close-port port)
  298. (bytevector->nix-base32-string (get-hash)))
  299. "\n")
  300. ;; Arrange so the actual data hash does not match the 'NarHash' field in the
  301. ;; narinfo.
  302. (with-output-to-string
  303. (lambda ()
  304. (let ((narinfo (string-append "StorePath: " (%store-prefix)
  305. "/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-wrong-hash
  306. URL: example.nar
  307. Compression: none
  308. NarHash: sha256:" (bytevector->nix-base32-string (sha256 #vu8())) "
  309. NarSize: 42
  310. References:
  311. Deriver: " (%store-prefix) "/foo.drv
  312. System: mips64el-linux\n")))
  313. (with-narinfo (string-append narinfo "Signature: "
  314. (signature-field narinfo) "\n")
  315. (call-with-temporary-directory
  316. (lambda (directory)
  317. (with-input-from-string (string-append
  318. "substitute " (%store-prefix)
  319. "/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-wrong-hash "
  320. directory "/wrong-hash\n")
  321. (lambda ()
  322. (guix-substitute "--substitute"))))))))))
  323. (test-quit "substitute, unauthorized key"
  324. "no valid substitute"
  325. (with-narinfo (string-append %narinfo "Signature: "
  326. (signature-field
  327. %narinfo
  328. #:public-key %wrong-public-key)
  329. "\n")
  330. (with-input-from-string (string-append "substitute "
  331. (%store-prefix)
  332. "/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-foo"
  333. " foo\n")
  334. (lambda ()
  335. (guix-substitute "--substitute")))))
  336. (test-equal "substitute, authorized key"
  337. '("Substitutable data." 1 #o444)
  338. (with-narinfo (string-append %narinfo "Signature: "
  339. (signature-field %narinfo))
  340. (dynamic-wind
  341. (const #t)
  342. (lambda ()
  343. (request-substitution (string-append (%store-prefix)
  344. "/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-foo")
  345. "substitute-retrieved")
  346. (list (call-with-input-file "substitute-retrieved" get-string-all)
  347. (stat:mtime (lstat "substitute-retrieved"))
  348. (stat:perms (lstat "substitute-retrieved"))))
  349. (lambda ()
  350. (false-if-exception (delete-file "substitute-retrieved"))))))
  351. (test-equal "substitute, unauthorized narinfo comes first"
  352. "Substitutable data."
  353. (with-narinfo*
  354. (string-append %narinfo "Signature: "
  355. (signature-field
  356. %narinfo
  357. #:public-key %wrong-public-key))
  358. %alternate-substitute-directory
  359. (with-narinfo* (string-append %narinfo "Signature: "
  360. (signature-field %narinfo))
  361. %main-substitute-directory
  362. (dynamic-wind
  363. (const #t)
  364. (lambda ()
  365. ;; Remove this file so that the substitute can only be retrieved
  366. ;; from %ALTERNATE-SUBSTITUTE-DIRECTORY.
  367. (delete-file (string-append %main-substitute-directory
  368. "/example.nar"))
  369. (parameterize ((substitute-urls
  370. (map (cut string-append "file://" <>)
  371. (list %alternate-substitute-directory
  372. %main-substitute-directory))))
  373. (request-substitution (string-append (%store-prefix)
  374. "/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-foo")
  375. "substitute-retrieved"))
  376. (call-with-input-file "substitute-retrieved" get-string-all))
  377. (lambda ()
  378. (false-if-exception (delete-file "substitute-retrieved")))))))
  379. (test-equal "substitute, unsigned narinfo comes first"
  380. "Substitutable data."
  381. (with-narinfo* %narinfo ;not signed!
  382. %alternate-substitute-directory
  383. (with-narinfo* (string-append %narinfo "Signature: "
  384. (signature-field %narinfo))
  385. %main-substitute-directory
  386. (dynamic-wind
  387. (const #t)
  388. (lambda ()
  389. ;; Remove this file so that the substitute can only be retrieved
  390. ;; from %ALTERNATE-SUBSTITUTE-DIRECTORY.
  391. (delete-file (string-append %main-substitute-directory
  392. "/example.nar"))
  393. (parameterize ((substitute-urls
  394. (map (cut string-append "file://" <>)
  395. (list %alternate-substitute-directory
  396. %main-substitute-directory))))
  397. (request-substitution (string-append (%store-prefix)
  398. "/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-foo")
  399. "substitute-retrieved"))
  400. (call-with-input-file "substitute-retrieved" get-string-all))
  401. (lambda ()
  402. (false-if-exception (delete-file "substitute-retrieved")))))))
  403. (test-equal "substitute, first narinfo is unsigned and has wrong hash"
  404. "Substitutable data."
  405. (with-narinfo* (regexp-substitute #f
  406. (string-match "NarHash: [[:graph:]]+"
  407. %narinfo)
  408. 'pre
  409. "NarHash: sha256:"
  410. (bytevector->nix-base32-string
  411. (make-bytevector 32))
  412. 'post)
  413. %alternate-substitute-directory
  414. (with-narinfo* (string-append %narinfo "Signature: "
  415. (signature-field %narinfo))
  416. %main-substitute-directory
  417. (dynamic-wind
  418. (const #t)
  419. (lambda ()
  420. ;; This time remove the file so that the substitute can only be
  421. ;; retrieved from %MAIN-SUBSTITUTE-DIRECTORY.
  422. (delete-file (string-append %alternate-substitute-directory
  423. "/example.nar"))
  424. (parameterize ((substitute-urls
  425. (map (cut string-append "file://" <>)
  426. (list %alternate-substitute-directory
  427. %main-substitute-directory))))
  428. (request-substitution (string-append (%store-prefix)
  429. "/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-foo")
  430. "substitute-retrieved"))
  431. (call-with-input-file "substitute-retrieved" get-string-all))
  432. (lambda ()
  433. (false-if-exception (delete-file "substitute-retrieved")))))))
  434. (test-equal "substitute, first narinfo is unsigned and has wrong refs"
  435. "Substitutable data."
  436. (with-narinfo* (regexp-substitute #f
  437. (string-match "References: ([^\n]+)\n"
  438. %narinfo)
  439. 'pre "References: " 1
  440. " wrong set of references\n"
  441. 'post)
  442. %alternate-substitute-directory
  443. (with-narinfo* (string-append %narinfo "Signature: "
  444. (signature-field %narinfo))
  445. %main-substitute-directory
  446. (dynamic-wind
  447. (const #t)
  448. (lambda ()
  449. ;; This time remove the file so that the substitute can only be
  450. ;; retrieved from %MAIN-SUBSTITUTE-DIRECTORY.
  451. (delete-file (string-append %alternate-substitute-directory
  452. "/example.nar"))
  453. (parameterize ((substitute-urls
  454. (map (cut string-append "file://" <>)
  455. (list %alternate-substitute-directory
  456. %main-substitute-directory))))
  457. (request-substitution (string-append (%store-prefix)
  458. "/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-foo")
  459. "substitute-retrieved"))
  460. (call-with-input-file "substitute-retrieved" get-string-all))
  461. (lambda ()
  462. (false-if-exception (delete-file "substitute-retrieved")))))))
  463. (test-quit "substitute, two invalid narinfos"
  464. "no valid substitute"
  465. (with-narinfo* %narinfo ;not signed
  466. %alternate-substitute-directory
  467. (with-narinfo* (string-append %narinfo "Signature: " ;unauthorized
  468. (signature-field
  469. %narinfo
  470. #:public-key %wrong-public-key))
  471. %main-substitute-directory
  472. (with-input-from-string (string-append "substitute "
  473. (%store-prefix)
  474. "/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-foo"
  475. " substitute-retrieved\n")
  476. (lambda ()
  477. (guix-substitute "--substitute"))))))
  478. (test-equal "substitute, narinfo with several URLs"
  479. "Substitutable data."
  480. (let ((narinfo (string-append "StorePath: " (%store-prefix)
  481. "/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-foo
  482. URL: example.nar.gz
  483. Compression: gzip
  484. URL: example.nar.lz
  485. Compression: lzip
  486. URL: example.nar
  487. Compression: none
  488. NarHash: sha256:" (bytevector->nix-base32-string
  489. (sha256 (string->utf8 "Substitutable data."))) "
  490. NarSize: 42
  491. References: bar baz
  492. Deriver: " (%store-prefix) "/foo.drv
  493. System: mips64el-linux\n")))
  494. (with-narinfo (string-append narinfo "Signature: "
  495. (signature-field narinfo))
  496. (dynamic-wind
  497. (const #t)
  498. (lambda ()
  499. (define (compress input output compression)
  500. (call-with-output-file output
  501. (lambda (port)
  502. (call-with-compressed-output-port compression port
  503. (lambda (port)
  504. (call-with-input-file input
  505. (lambda (input)
  506. (dump-port input port))))))))
  507. (let ((nar (string-append %main-substitute-directory
  508. "/example.nar")))
  509. (compress nar (string-append nar ".gz") 'gzip)
  510. (compress nar (string-append nar ".lz") 'lzip))
  511. (parameterize ((substitute-urls
  512. (list (string-append "file://"
  513. %main-substitute-directory))))
  514. (request-substitution (string-append (%store-prefix)
  515. "/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-foo")
  516. "substitute-retrieved"))
  517. (call-with-input-file "substitute-retrieved" get-string-all))
  518. (lambda ()
  519. (false-if-exception (delete-file "substitute-retrieved")))))))
  520. (test-end "substitute")
  521. ;;; Local Variables:
  522. ;;; eval: (put 'with-narinfo 'scheme-indent-function 1)
  523. ;;; eval: (put 'with-narinfo* 'scheme-indent-function 2)
  524. ;;; eval: (put 'test-quit 'scheme-indent-function 2)
  525. ;;; End: