profiles.scm 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2013-2022 Ludovic Courtès <ludo@gnu.org>
  3. ;;; Copyright © 2014 Alex Kost <alezost@gmail.com>
  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-profiles)
  20. #:use-module (guix tests)
  21. #:use-module (guix profiles)
  22. #:use-module (guix gexp)
  23. #:use-module (guix store)
  24. #:use-module (guix monads)
  25. #:use-module (guix packages)
  26. #:use-module (guix derivations)
  27. #:use-module (guix build-system trivial)
  28. #:use-module (gnu packages bootstrap)
  29. #:use-module ((gnu packages base) #:prefix packages:)
  30. #:use-module ((gnu packages guile) #:prefix packages:)
  31. #:use-module (ice-9 match)
  32. #:use-module (ice-9 regex)
  33. #:use-module (ice-9 popen)
  34. #:use-module (rnrs io ports)
  35. #:use-module (srfi srfi-1)
  36. #:use-module (srfi srfi-11)
  37. #:use-module (srfi srfi-34)
  38. #:use-module (srfi srfi-64))
  39. ;; Test the (guix profiles) module.
  40. (define %store
  41. (open-connection-for-tests))
  42. ;; Globally disable grafts because they can trigger early builds.
  43. (%graft? #f)
  44. ;; Example manifest entries.
  45. (define guile-1.8.8
  46. (manifest-entry
  47. (name "guile")
  48. (version "1.8.8")
  49. (item "/gnu/store/...")
  50. (output "out")))
  51. (define guile-2.0.9
  52. (manifest-entry
  53. (name "guile")
  54. (version "2.0.9")
  55. (item "/gnu/store/...")
  56. (output "out")))
  57. (define guile-2.0.9:debug
  58. (manifest-entry (inherit guile-2.0.9)
  59. (output "debug")))
  60. (define glibc
  61. (manifest-entry
  62. (name "glibc")
  63. (version "2.19")
  64. (item "/gnu/store/...")
  65. (output "out")))
  66. (test-begin "profiles")
  67. (test-assert "manifest-installed?"
  68. (let ((m (manifest (list guile-2.0.9 guile-2.0.9:debug))))
  69. (and (manifest-installed? m (manifest-pattern (name "guile")))
  70. (manifest-installed? m (manifest-pattern
  71. (name "guile") (output "debug")))
  72. (manifest-installed? m (manifest-pattern
  73. (name "guile") (output "out")
  74. (version "2.0.9")))
  75. (not (manifest-installed?
  76. m (manifest-pattern (name "guile") (version "1.8.8"))))
  77. (not (manifest-installed?
  78. m (manifest-pattern (name "guile") (output "foobar")))))))
  79. (test-assert "manifest-matching-entries"
  80. (let* ((e (list guile-2.0.9 guile-2.0.9:debug))
  81. (m (manifest e)))
  82. (and (equal? e
  83. (manifest-matching-entries m
  84. (list (manifest-pattern
  85. (name "guile")
  86. (output #f)))))
  87. (equal? (list guile-2.0.9)
  88. (manifest-matching-entries m
  89. (list (manifest-pattern
  90. (name "guile")
  91. (version "2.0.9"))))))))
  92. (test-assert "manifest-matching-entries, no match"
  93. (let ((m (manifest (list guile-2.0.9)))
  94. (p (manifest-pattern (name "python"))))
  95. (guard (c ((unmatched-pattern-error? c)
  96. (and (eq? p (unmatched-pattern-error-pattern c))
  97. (eq? m (unmatched-pattern-error-manifest c)))))
  98. (manifest-matching-entries m (list p))
  99. #f)))
  100. (test-equal "concatenate-manifests"
  101. (manifest (list guile-2.0.9 glibc))
  102. (concatenate-manifests (list (manifest (list guile-2.0.9))
  103. (manifest (list glibc)))))
  104. (test-assert "manifest-remove"
  105. (let* ((m0 (manifest (list guile-2.0.9 guile-2.0.9:debug)))
  106. (m1 (manifest-remove m0
  107. (list (manifest-pattern (name "guile")))))
  108. (m2 (manifest-remove m1
  109. (list (manifest-pattern (name "guile"))))) ; same
  110. (m3 (manifest-remove m2
  111. (list (manifest-pattern
  112. (name "guile") (output "debug")))))
  113. (m4 (manifest-remove m3
  114. (list (manifest-pattern (name "guile"))))))
  115. (match (manifest-entries m2)
  116. ((($ <manifest-entry> "guile" "2.0.9" "debug"))
  117. (and (equal? m1 m2)
  118. (null? (manifest-entries m3))
  119. (null? (manifest-entries m4)))))))
  120. (test-assert "manifest-add"
  121. (let* ((m0 (manifest '()))
  122. (m1 (manifest-add m0 (list guile-1.8.8)))
  123. (m2 (manifest-add m1 (list guile-2.0.9)))
  124. (m3 (manifest-add m2 (list guile-2.0.9:debug)))
  125. (m4 (manifest-add m3 (list guile-2.0.9:debug))))
  126. (and (match (manifest-entries m1)
  127. ((($ <manifest-entry> "guile" "1.8.8" "out")) #t)
  128. (_ #f))
  129. (match (manifest-entries m2)
  130. ((($ <manifest-entry> "guile" "2.0.9" "out")) #t)
  131. (_ #f))
  132. (equal? m3 m4))))
  133. (test-equal "manifest-add removes duplicates" ;<https://bugs.gnu.org/30569>
  134. (list guile-2.0.9)
  135. (manifest-entries (manifest-add (manifest '())
  136. (list guile-2.0.9 guile-2.0.9))))
  137. (test-equal "manifest->code, simple"
  138. '(begin
  139. (specifications->manifest (list "guile" "guile:debug" "glibc")))
  140. (manifest->code (manifest (list guile-2.0.9 guile-2.0.9:debug glibc))))
  141. (test-equal "manifest->code, simple, versions"
  142. '(begin
  143. (specifications->manifest (list "guile@2.0.9" "guile@2.0.9:debug"
  144. "glibc@2.19")))
  145. (manifest->code (manifest (list guile-2.0.9 guile-2.0.9:debug glibc))
  146. #:entry-package-version manifest-entry-version))
  147. (test-equal "manifest->code, transformations"
  148. '(begin
  149. (use-modules (guix transformations))
  150. (define transform1
  151. (options->transformation '((foo . "bar"))))
  152. (packages->manifest
  153. (list (transform1 (specification->package "guile"))
  154. (specification->package "glibc"))))
  155. (manifest->code (manifest (list (manifest-entry
  156. (inherit guile-2.0.9)
  157. (properties `((transformations
  158. . ((foo . "bar"))))))
  159. glibc))))
  160. (test-assert "manifest-perform-transaction"
  161. (let* ((m0 (manifest (list guile-2.0.9 guile-2.0.9:debug)))
  162. (t1 (manifest-transaction
  163. (install (list guile-1.8.8))
  164. (remove (list (manifest-pattern (name "guile")
  165. (output "debug"))))))
  166. (t2 (manifest-transaction
  167. (remove (list (manifest-pattern (name "guile")
  168. (version "2.0.9")
  169. (output #f))))))
  170. (m1 (manifest-perform-transaction m0 t1))
  171. (m2 (manifest-perform-transaction m1 t2))
  172. (m3 (manifest-perform-transaction m0 t2)))
  173. (and (match (manifest-entries m1)
  174. ((($ <manifest-entry> "guile" "1.8.8" "out")) #t)
  175. (_ #f))
  176. (equal? m1 m2)
  177. (null? (manifest-entries m3)))))
  178. (test-assert "manifest-transaction-effects"
  179. (let* ((m0 (manifest (list guile-1.8.8)))
  180. (t (manifest-transaction
  181. (install (list guile-2.0.9 glibc)))))
  182. (let-values (((remove install upgrade downgrade)
  183. (manifest-transaction-effects m0 t)))
  184. (and (null? remove) (null? downgrade)
  185. (equal? (list glibc) install)
  186. (equal? (list (cons guile-1.8.8 guile-2.0.9)) upgrade)))))
  187. (test-assert "manifest-transaction-effects no double install or upgrades"
  188. (let* ((m0 (manifest (list guile-1.8.8)))
  189. (t (manifest-transaction
  190. (install (list guile-2.0.9 glibc glibc)))))
  191. (let-values (((remove install upgrade downgrade)
  192. (manifest-transaction-effects m0 t)))
  193. (and (null? remove) (null? downgrade)
  194. (equal? (list glibc) install)
  195. (equal? (list (cons guile-1.8.8 guile-2.0.9)) upgrade)))))
  196. (test-assert "manifest-transaction-effects and downgrades"
  197. (let* ((m0 (manifest (list guile-2.0.9)))
  198. (t (manifest-transaction (install (list guile-1.8.8)))))
  199. (let-values (((remove install upgrade downgrade)
  200. (manifest-transaction-effects m0 t)))
  201. (and (null? remove) (null? install) (null? upgrade)
  202. (equal? (list (cons guile-2.0.9 guile-1.8.8)) downgrade)))))
  203. (test-assert "manifest-transaction-effects no double downgrade"
  204. (let* ((m0 (manifest (list guile-2.0.9)))
  205. (t (manifest-transaction (install (list guile-1.8.8 guile-1.8.8)))))
  206. (let-values (((remove install upgrade downgrade)
  207. (manifest-transaction-effects m0 t)))
  208. (and (null? remove) (null? install) (null? upgrade)
  209. (equal? (list (cons guile-2.0.9 guile-1.8.8)) downgrade)))))
  210. (test-assert "manifest-transaction-effects and pseudo-upgrades"
  211. (let* ((m0 (manifest (list guile-2.0.9)))
  212. (t (manifest-transaction (install (list guile-2.0.9)))))
  213. (let-values (((remove install upgrade downgrade)
  214. (manifest-transaction-effects m0 t)))
  215. (and (null? remove) (null? install) (null? downgrade)
  216. (equal? (list (cons guile-2.0.9 guile-2.0.9)) upgrade)))))
  217. (test-assert "manifest-transaction-null?"
  218. (manifest-transaction-null? (manifest-transaction)))
  219. (test-assert "manifest-transaction-removal-candidate?"
  220. (let ((m (manifest (list guile-2.0.9)))
  221. (t (manifest-transaction
  222. (remove (list (manifest-pattern (name "guile")))))))
  223. (and (manifest-transaction-removal-candidate? guile-2.0.9 t)
  224. (not (manifest-transaction-removal-candidate? glibc t)))))
  225. (test-assert "manifest-transaction-effects no double removal"
  226. (let* ((m0 (manifest (list guile-2.0.9)))
  227. (t (manifest-transaction
  228. (remove (list (manifest-pattern (name "guile")))))))
  229. (let-values (((remove install upgrade downgrade)
  230. (manifest-transaction-effects m0 t)))
  231. (and (= 1 (length remove))
  232. (manifest-transaction-removal-candidate? guile-2.0.9 t)
  233. (null? install) (null? downgrade) (null? upgrade)))))
  234. (test-assert "package->development-manifest"
  235. (let ((manifest (package->development-manifest packages:hello)))
  236. (every (lambda (name)
  237. (manifest-installed? manifest
  238. (manifest-pattern (name name))))
  239. '("gcc" "binutils" "glibc" "coreutils" "grep" "sed"))))
  240. (test-assertm "profile-derivation"
  241. (mlet* %store-monad
  242. ((entry -> (package->manifest-entry %bootstrap-guile))
  243. (guile (package->derivation %bootstrap-guile))
  244. (drv (profile-derivation (manifest (list entry))
  245. #:hooks '()
  246. #:locales? #f))
  247. (profile -> (derivation->output-path drv))
  248. (bindir -> (string-append profile "/bin"))
  249. (_ (built-derivations (list drv))))
  250. (return (and (file-exists? (string-append bindir "/guile"))
  251. (string=? (dirname (readlink bindir))
  252. (derivation->output-path guile))))))
  253. (test-assertm "profile-derivation format version 3"
  254. ;; Make sure we can create and read a version 3 manifest.
  255. (mlet* %store-monad
  256. ((entry -> (package->manifest-entry %bootstrap-guile
  257. #:properties '((answer . 42))))
  258. (manifest -> (manifest (list entry)))
  259. (drv1 (profile-derivation manifest
  260. #:format-version 3 ;old version
  261. #:hooks '()
  262. #:locales? #f))
  263. (drv2 (profile-derivation manifest
  264. #:hooks '()
  265. #:locales? #f))
  266. (profile1 -> (derivation->output-path drv1))
  267. (profile2 -> (derivation->output-path drv2))
  268. (_ (built-derivations (list drv1 drv2))))
  269. (return (let ((manifest1 (profile-manifest profile1))
  270. (manifest2 (profile-manifest profile2)))
  271. (match (manifest-entries manifest1)
  272. ((entry1)
  273. (match (manifest-entries manifest2)
  274. ((entry2)
  275. (and (manifest-entry=? entry1 entry2)
  276. (equal? (manifest-entry-properties entry1)
  277. '((answer . 42)))
  278. (equal? (manifest-entry-properties entry2)
  279. '((answer . 42))))))))))))
  280. (test-assertm "profile-derivation, ordering & collisions"
  281. ;; ENTRY1 and ENTRY2 both provide 'bin/guile'--a collision. Make sure
  282. ;; ENTRY1 "wins" over ENTRY2. See <https://bugs.gnu.org/49102>.
  283. (mlet* %store-monad
  284. ((entry1 -> (package->manifest-entry %bootstrap-guile))
  285. (entry2 -> (manifest-entry
  286. (name "fake-guile")
  287. (version "0")
  288. (item (computed-file
  289. "fake-guile"
  290. #~(begin
  291. (mkdir #$output)
  292. (mkdir (string-append #$output "/bin"))
  293. (call-with-output-file
  294. (string-append #$output "/bin/guile")
  295. (lambda (port)
  296. (display "Fake!\n" port))))
  297. #:guile %bootstrap-guile))))
  298. (guile (package->derivation %bootstrap-guile))
  299. (drv (profile-derivation (manifest (list entry1 entry2))
  300. #:hooks '()
  301. #:locales? #f))
  302. (profile -> (derivation->output-path drv))
  303. (bindir -> (string-append profile "/bin"))
  304. (file -> (string-append bindir "/guile"))
  305. (_ (built-derivations (list drv))))
  306. (return (string=? (readlink file)
  307. (string-append
  308. (derivation->output-path guile)
  309. "/bin/guile")))))
  310. (test-assertm "load-profile"
  311. (mlet* %store-monad
  312. ((entry -> (package->manifest-entry %bootstrap-guile))
  313. (guile (package->derivation %bootstrap-guile))
  314. (drv (profile-derivation (manifest (list entry))
  315. #:hooks '()
  316. #:locales? #f))
  317. (profile -> (derivation->output-path drv))
  318. (bindir -> (string-append profile "/bin"))
  319. (_ (built-derivations (list drv))))
  320. (define-syntax-rule (with-environment-excursion exp ...)
  321. (let ((env (environ)))
  322. (dynamic-wind
  323. (const #t)
  324. (lambda () exp ...)
  325. (lambda () (environ env)))))
  326. (return (and (with-environment-excursion
  327. (load-profile profile)
  328. (and (string-prefix? (string-append bindir ":")
  329. (getenv "PATH"))
  330. (getenv "GUILE_LOAD_PATH")))
  331. (with-environment-excursion
  332. (load-profile profile #:pure? #t #:white-list '())
  333. (equal? (list (string-append "PATH=" bindir))
  334. (environ)))))))
  335. (test-assertm "<profile>"
  336. (mlet* %store-monad
  337. ((entry -> (package->manifest-entry %bootstrap-guile))
  338. (profile -> (profile (hooks '()) (locales? #f)
  339. (content (manifest (list entry)))))
  340. (drv (lower-object profile))
  341. (profile -> (derivation->output-path drv))
  342. (bindir -> (string-append profile "/bin"))
  343. (_ (built-derivations (list drv))))
  344. (return (file-exists? (string-append bindir "/guile")))))
  345. (test-assertm "profile-derivation relative symlinks, one entry"
  346. (mlet* %store-monad
  347. ((entry -> (package->manifest-entry %bootstrap-guile))
  348. (guile (package->derivation %bootstrap-guile))
  349. (drv (profile-derivation (manifest (list entry))
  350. #:relative-symlinks? #t
  351. #:hooks '()
  352. #:locales? #f))
  353. (profile -> (derivation->output-path drv))
  354. (bindir -> (string-append profile "/bin"))
  355. (_ (built-derivations (list drv))))
  356. (return (and (file-exists? (string-append bindir "/guile"))
  357. (string=? (readlink bindir)
  358. (string-append "../"
  359. (basename
  360. (derivation->output-path guile))
  361. "/bin"))))))
  362. (unless (network-reachable?) (test-skip 1))
  363. (test-assertm "profile-derivation relative symlinks, two entries"
  364. (mlet* %store-monad
  365. ((manifest -> (packages->manifest
  366. (list %bootstrap-guile gnu-make-for-tests)))
  367. (guile (package->derivation %bootstrap-guile))
  368. (make (package->derivation gnu-make-for-tests))
  369. (drv (profile-derivation manifest
  370. #:relative-symlinks? #t
  371. #:hooks '()
  372. #:locales? #f))
  373. (profile -> (derivation->output-path drv))
  374. (bindir -> (string-append profile "/bin"))
  375. (_ (built-derivations (list drv))))
  376. (return (and (file-exists? (string-append bindir "/guile"))
  377. (file-exists? (string-append bindir "/make"))
  378. (string=? (readlink (string-append bindir "/guile"))
  379. (string-append "../../"
  380. (basename
  381. (derivation->output-path guile))
  382. "/bin/guile"))
  383. (string=? (readlink (string-append bindir "/make"))
  384. (string-append "../../"
  385. (basename
  386. (derivation->output-path make))
  387. "/bin/make"))))))
  388. (test-assertm "profile-derivation, inputs"
  389. (mlet* %store-monad
  390. ((entry -> (package->manifest-entry packages:glibc "debug"))
  391. (drv (profile-derivation (manifest (list entry))
  392. #:hooks '()
  393. #:locales? #f)))
  394. (return (derivation-inputs drv))))
  395. (test-assertm "profile-derivation, cross-compilation"
  396. (mlet* %store-monad
  397. ((manifest -> (packages->manifest (list packages:sed packages:grep)))
  398. (target -> "arm-linux-gnueabihf")
  399. (grep (package->cross-derivation packages:grep target))
  400. (sed (package->cross-derivation packages:sed target))
  401. (locales (package->derivation packages:glibc-utf8-locales))
  402. (drv (profile-derivation manifest
  403. #:hooks '()
  404. #:locales? #t
  405. #:target target)))
  406. (define (find-input package)
  407. (let ((name (string-append (package-full-name package "-") ".drv")))
  408. (any (lambda (input)
  409. (let ((input (derivation-input-path input)))
  410. (and (string-suffix? name input) input)))
  411. (derivation-inputs drv))))
  412. ;; The inputs for grep and sed should be cross-build derivations, but that
  413. ;; for the glibc-utf8-locales should be a native build.
  414. (return (and (string=? (derivation-system drv) (%current-system))
  415. (string=? (find-input packages:grep)
  416. (derivation-file-name grep))
  417. (string=? (find-input packages:sed)
  418. (derivation-file-name sed))
  419. (string=? (find-input packages:glibc-utf8-locales)
  420. (derivation-file-name locales))))))
  421. (test-assert "package->manifest-entry defaults to \"out\""
  422. (let ((outputs (package-outputs packages:glibc)))
  423. (equal? (manifest-entry-output
  424. (package->manifest-entry (package
  425. (inherit packages:glibc)
  426. (outputs (reverse outputs)))))
  427. (manifest-entry-output
  428. (package->manifest-entry packages:glibc))
  429. "out")))
  430. (test-assertm "profile-manifest, search-paths"
  431. (mlet* %store-monad
  432. ((guile -> (package
  433. (inherit %bootstrap-guile)
  434. (native-search-paths
  435. (package-native-search-paths packages:guile-2.0))))
  436. (entry -> (package->manifest-entry guile))
  437. (drv (profile-derivation (manifest (list entry))
  438. #:hooks '()
  439. #:locales? #f))
  440. (profile -> (derivation->output-path drv)))
  441. (mbegin %store-monad
  442. (built-derivations (list drv))
  443. ;; Read the manifest back and make sure search paths are preserved.
  444. (let ((manifest (profile-manifest profile)))
  445. (match (manifest-entries manifest)
  446. ((result)
  447. (return (equal? (manifest-entry-search-paths result)
  448. (manifest-entry-search-paths entry)
  449. (package-native-search-paths
  450. packages:guile-2.0)))))))))
  451. (test-assert "package->manifest-entry, search paths"
  452. ;; See <http://bugs.gnu.org/22073>.
  453. (let ((mpl (@ (gnu packages python-xyz) python-matplotlib)))
  454. (lset= eq?
  455. (package-transitive-native-search-paths mpl)
  456. (manifest-entry-search-paths
  457. (package->manifest-entry mpl)))))
  458. (test-assert "packages->manifest, no duplicates"
  459. (let ((expected
  460. (manifest
  461. (list
  462. (package->manifest-entry packages:guile-2.2))))
  463. (manifest (packages->manifest
  464. (list packages:guile-2.2 packages:guile-2.2))))
  465. (every manifest-entry=? (manifest-entries expected)
  466. (manifest-entries manifest))))
  467. (test-equal "packages->manifest, propagated inputs"
  468. (map (match-lambda
  469. ((label package)
  470. (list (package-name package) (package-version package)
  471. package)))
  472. (package-propagated-inputs packages:guile-2.2))
  473. (map (lambda (entry)
  474. (list (manifest-entry-name entry)
  475. (manifest-entry-version entry)
  476. (manifest-entry-item entry)))
  477. (manifest-entry-dependencies
  478. (package->manifest-entry packages:guile-2.2))))
  479. (test-assert "manifest-entry-parent"
  480. (let ((entry (package->manifest-entry packages:guile-2.2)))
  481. (match (manifest-entry-dependencies entry)
  482. ((dependencies ..1)
  483. (and (every (lambda (parent)
  484. (eq? entry (force parent)))
  485. (map manifest-entry-parent dependencies))
  486. (not (force (manifest-entry-parent entry))))))))
  487. (test-assertm "read-manifest"
  488. (mlet* %store-monad ((manifest -> (packages->manifest
  489. (list (package
  490. (inherit %bootstrap-guile)
  491. (native-search-paths
  492. (package-native-search-paths
  493. packages:guile-2.0))))))
  494. (drv (profile-derivation manifest
  495. #:hooks '()
  496. #:locales? #f))
  497. (out -> (derivation->output-path drv)))
  498. (define (entry->sexp entry)
  499. (list (manifest-entry-name entry)
  500. (manifest-entry-version entry)
  501. (manifest-entry-search-paths entry)
  502. (manifest-entry-dependencies entry)
  503. (force (manifest-entry-parent entry))))
  504. (mbegin %store-monad
  505. (built-derivations (list drv))
  506. (let ((manifest2 (profile-manifest out)))
  507. (return (equal? (map entry->sexp (manifest-entries manifest))
  508. (map entry->sexp (manifest-entries manifest2))))))))
  509. (test-equal "collision"
  510. '(("guile-bootstrap" "2.0") ("guile-bootstrap" "42"))
  511. (guard (c ((profile-collision-error? c)
  512. (let ((entry1 (profile-collision-error-entry c))
  513. (entry2 (profile-collision-error-conflict c)))
  514. (list (list (manifest-entry-name entry1)
  515. (manifest-entry-version entry1))
  516. (list (manifest-entry-name entry2)
  517. (manifest-entry-version entry2))))))
  518. (run-with-store %store
  519. (mlet* %store-monad ((p0 -> (package
  520. (inherit %bootstrap-guile)
  521. (version "42")))
  522. (p1 -> (dummy-package "p1"
  523. (propagated-inputs `(("p0" ,p0)))))
  524. (manifest -> (packages->manifest
  525. (list %bootstrap-guile p1)))
  526. (drv (profile-derivation manifest
  527. #:hooks '()
  528. #:locales? #f)))
  529. (return #f)))))
  530. (test-equal "collision of propagated inputs"
  531. '(("guile-bootstrap" "2.0") "p1"
  532. <> ("guile-bootstrap" "42") "p2")
  533. (guard (c ((profile-collision-error? c)
  534. (let ((entry1 (profile-collision-error-entry c))
  535. (entry2 (profile-collision-error-conflict c)))
  536. (list (list (manifest-entry-name entry1)
  537. (manifest-entry-version entry1))
  538. (manifest-entry-name
  539. (force (manifest-entry-parent entry1)))
  540. '<>
  541. (list (manifest-entry-name entry2)
  542. (manifest-entry-version entry2))
  543. (manifest-entry-name
  544. (force (manifest-entry-parent entry2)))))))
  545. (run-with-store %store
  546. (mlet* %store-monad ((p0 -> (package
  547. (inherit %bootstrap-guile)
  548. (version "42")))
  549. (p1 -> (dummy-package "p1"
  550. (propagated-inputs
  551. `(("guile" ,%bootstrap-guile)))))
  552. (p2 -> (dummy-package "p2"
  553. (propagated-inputs
  554. `(("guile" ,p0)))))
  555. (manifest -> (packages->manifest (list p1 p2)))
  556. (drv (profile-derivation manifest
  557. #:hooks '()
  558. #:locales? #f)))
  559. (return #f)))))
  560. (test-assertm "deduplication of repeated entries"
  561. ;; Make sure the 'manifest' file does not duplicate identical entries.
  562. ;; See <https://issues.guix.gnu.org/55499>.
  563. (mlet* %store-monad ((p0 -> (dummy-package "p0"
  564. (build-system trivial-build-system)
  565. (arguments
  566. `(#:guile ,%bootstrap-guile
  567. #:builder (mkdir (assoc-ref %outputs "out"))))
  568. (propagated-inputs
  569. `(("guile" ,%bootstrap-guile)))))
  570. (p1 -> (package
  571. (inherit p0)
  572. (name "p1")))
  573. (drv (profile-derivation (packages->manifest
  574. (list p0 p1))
  575. #:hooks '()
  576. #:locales? #f)))
  577. (mbegin %store-monad
  578. (built-derivations (list drv))
  579. (let ((file (string-append (derivation->output-path drv)
  580. "/manifest"))
  581. (manifest (profile-manifest (derivation->output-path drv))))
  582. (define (contains-repeated? sexp)
  583. (match sexp
  584. (('repeated _ ...) #t)
  585. ((lst ...) (any contains-repeated? sexp))
  586. (_ #f)))
  587. (return (and (contains-repeated? (call-with-input-file file read))
  588. ;; MANIFEST has two entries for %BOOTSTRAP-GUILE since
  589. ;; it's propagated both from P0 and from P1. When
  590. ;; reading a 'repeated' node, 'read-manifest' should
  591. ;; reuse the previously-read entry so the two
  592. ;; %BOOTSTRAP-GUILE entries must be 'eq?'.
  593. (match (manifest-entries manifest)
  594. (((= manifest-entry-dependencies (dep0))
  595. (= manifest-entry-dependencies (dep1)))
  596. (and (string=? (manifest-entry-name dep0)
  597. (package-name %bootstrap-guile))
  598. (eq? dep0 dep1))))))))))
  599. (test-assertm "no collision"
  600. ;; Here we have an entry that is "lowered" (its 'item' field is a store file
  601. ;; name) and another entry (its 'item' field is a package) that is
  602. ;; equivalent.
  603. (mlet* %store-monad ((p -> (dummy-package "p"
  604. (propagated-inputs
  605. `(("guile" ,%bootstrap-guile)))))
  606. (guile (package->derivation %bootstrap-guile))
  607. (entry -> (manifest-entry
  608. (inherit (package->manifest-entry
  609. %bootstrap-guile))
  610. (item (derivation->output-path guile))))
  611. (manifest -> (manifest
  612. (list entry
  613. (package->manifest-entry p))))
  614. (drv (profile-derivation manifest)))
  615. (return (->bool drv))))
  616. (test-assertm "etc/profile"
  617. ;; Make sure we get an 'etc/profile' file that at least defines $PATH.
  618. (mlet* %store-monad
  619. ((guile -> (package
  620. (inherit %bootstrap-guile)
  621. (native-search-paths
  622. (package-native-search-paths packages:guile-2.0))))
  623. (entry -> (package->manifest-entry guile))
  624. (drv (profile-derivation (manifest (list entry))
  625. #:hooks '()
  626. #:locales? #f))
  627. (profile -> (derivation->output-path drv)))
  628. (mbegin %store-monad
  629. (built-derivations (list drv))
  630. (let* ((pipe (open-input-pipe
  631. (string-append "unset GUIX_PROFILE; "
  632. ;; 'source' is a Bashism; use '.' (dot).
  633. ". " profile "/etc/profile; "
  634. ;; Don't try to parse set(1) output because
  635. ;; it differs among shells; just use echo.
  636. "echo $PATH")))
  637. (path (get-string-all pipe)))
  638. (return
  639. (and (zero? (close-pipe pipe))
  640. (string-contains path (string-append profile "/bin"))))))))
  641. (test-assertm "etc/profile when etc/ already exists"
  642. ;; Here 'union-build' makes the profile's etc/ a symlink to the package's
  643. ;; etc/ directory, which makes it read-only. Make sure the profile build
  644. ;; handles that.
  645. (mlet* %store-monad
  646. ((thing -> (dummy-package "dummy"
  647. (build-system trivial-build-system)
  648. (arguments
  649. `(#:guile ,%bootstrap-guile
  650. #:builder
  651. (let ((out (assoc-ref %outputs "out")))
  652. (mkdir out)
  653. (mkdir (string-append out "/etc"))
  654. (call-with-output-file (string-append out "/etc/foo")
  655. (lambda (port)
  656. (display "foo!" port)))
  657. #t)))))
  658. (entry -> (package->manifest-entry thing))
  659. (drv (profile-derivation (manifest (list entry))
  660. #:hooks '()
  661. #:locales? #f))
  662. (profile -> (derivation->output-path drv)))
  663. (mbegin %store-monad
  664. (built-derivations (list drv))
  665. (return (and (file-exists? (string-append profile "/etc/profile"))
  666. (string=? (call-with-input-file
  667. (string-append profile "/etc/foo")
  668. get-string-all)
  669. "foo!"))))))
  670. (test-assertm "etc/profile when etc/ is a symlink"
  671. ;; When etc/ is a symlink, the unsymlink code in 0.8.2 would fail
  672. ;; gracelessly because 'scandir' would return #f.
  673. (mlet* %store-monad
  674. ((thing -> (dummy-package "dummy"
  675. (build-system trivial-build-system)
  676. (arguments
  677. `(#:guile ,%bootstrap-guile
  678. #:builder
  679. (let ((out (assoc-ref %outputs "out")))
  680. (mkdir out)
  681. (mkdir (string-append out "/foo"))
  682. (symlink "foo" (string-append out "/etc"))
  683. (call-with-output-file (string-append out "/etc/bar")
  684. (lambda (port)
  685. (display "foo!" port)))
  686. #t)))))
  687. (entry -> (package->manifest-entry thing))
  688. (drv (profile-derivation (manifest (list entry))
  689. #:hooks '()
  690. #:locales? #f))
  691. (profile -> (derivation->output-path drv)))
  692. (mbegin %store-monad
  693. (built-derivations (list drv))
  694. (return (and (file-exists? (string-append profile "/etc/profile"))
  695. (string=? (call-with-input-file
  696. (string-append profile "/etc/bar")
  697. get-string-all)
  698. "foo!"))))))
  699. (test-assertm "profile-derivation when etc/ is a relative symlink"
  700. ;; See <https://bugs.gnu.org/32686>.
  701. (mlet* %store-monad
  702. ((etc (gexp->derivation
  703. "etc"
  704. #~(begin
  705. (mkdir #$output)
  706. (call-with-output-file (string-append #$output "/foo")
  707. (lambda (port)
  708. (display "Heya!" port))))))
  709. (thing -> (dummy-package "dummy"
  710. (build-system trivial-build-system)
  711. (inputs
  712. `(("etc" ,etc)))
  713. (arguments
  714. `(#:guile ,%bootstrap-guile
  715. #:builder
  716. (let ((out (assoc-ref %outputs "out"))
  717. (etc (assoc-ref %build-inputs "etc")))
  718. (mkdir out)
  719. (symlink etc (string-append out "/etc"))
  720. #t)))))
  721. (entry -> (package->manifest-entry thing))
  722. (drv (profile-derivation (manifest (list entry))
  723. #:relative-symlinks? #t
  724. #:hooks '()
  725. #:locales? #f))
  726. (profile -> (derivation->output-path drv)))
  727. (mbegin %store-monad
  728. (built-derivations (list drv))
  729. (return (string=? (call-with-input-file
  730. (string-append profile "/etc/foo")
  731. get-string-all)
  732. "Heya!")))))
  733. (test-equalm "union vs. dangling symlink" ;<https://bugs.gnu.org/26949>
  734. "does-not-exist"
  735. (mlet* %store-monad
  736. ((thing1 -> (dummy-package "dummy"
  737. (build-system trivial-build-system)
  738. (arguments
  739. `(#:guile ,%bootstrap-guile
  740. #:builder
  741. (let ((out (assoc-ref %outputs "out")))
  742. (mkdir out)
  743. (symlink "does-not-exist"
  744. (string-append out "/dangling"))
  745. #t)))))
  746. (thing2 -> (package (inherit thing1) (name "dummy2")))
  747. (drv (profile-derivation (packages->manifest
  748. (list thing1 thing2))
  749. #:hooks '()
  750. #:locales? #f))
  751. (profile -> (derivation->output-path drv)))
  752. (mbegin %store-monad
  753. (built-derivations (list drv))
  754. (return (readlink (readlink (string-append profile "/dangling")))))))
  755. (test-equalm "profile in profile"
  756. '("foo" "0")
  757. ;; Make sure we can build a profile that has another profile has one of its
  758. ;; entries. The new profile's /manifest and /etc/profile must override the
  759. ;; other's.
  760. (mlet* %store-monad
  761. ((prof0 (profile-derivation
  762. (manifest
  763. (list (package->manifest-entry %bootstrap-guile)))
  764. #:hooks '()
  765. #:locales? #f))
  766. (prof1 (profile-derivation
  767. (manifest (list (manifest-entry
  768. (name "foo")
  769. (version "0")
  770. (item prof0))))
  771. #:hooks '()
  772. #:locales? #f)))
  773. (mbegin %store-monad
  774. (built-derivations (list prof1))
  775. (let ((out (derivation->output-path prof1)))
  776. (return (and (file-exists?
  777. (string-append out "/bin/guile"))
  778. (let ((manifest (profile-manifest out)))
  779. (match (manifest-entries manifest)
  780. ((entry)
  781. (list (manifest-entry-name entry)
  782. (manifest-entry-version entry)))))))))))
  783. (test-end "profiles")
  784. ;;; Local Variables:
  785. ;;; eval: (put 'dummy-package 'scheme-indent-function 1)
  786. ;;; End: