profiles.scm 34 KB

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