profiles.scm 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780
  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 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-assert "package->development-manifest"
  236. (let ((manifest (package->development-manifest packages:hello)))
  237. (every (lambda (name)
  238. (manifest-installed? manifest
  239. (manifest-pattern (name name))))
  240. '("gcc" "binutils" "glibc" "coreutils" "grep" "sed"))))
  241. (test-assertm "profile-derivation"
  242. (mlet* %store-monad
  243. ((entry -> (package->manifest-entry %bootstrap-guile))
  244. (guile (package->derivation %bootstrap-guile))
  245. (drv (profile-derivation (manifest (list entry))
  246. #:hooks '()
  247. #:locales? #f))
  248. (profile -> (derivation->output-path drv))
  249. (bindir -> (string-append profile "/bin"))
  250. (_ (built-derivations (list drv))))
  251. (return (and (file-exists? (string-append bindir "/guile"))
  252. (string=? (dirname (readlink bindir))
  253. (derivation->output-path guile))))))
  254. (test-assertm "profile-derivation, ordering & collisions"
  255. ;; ENTRY1 and ENTRY2 both provide 'bin/guile'--a collision. Make sure
  256. ;; ENTRY1 "wins" over ENTRY2. See <https://bugs.gnu.org/49102>.
  257. (mlet* %store-monad
  258. ((entry1 -> (package->manifest-entry %bootstrap-guile))
  259. (entry2 -> (manifest-entry
  260. (name "fake-guile")
  261. (version "0")
  262. (item (computed-file
  263. "fake-guile"
  264. #~(begin
  265. (mkdir #$output)
  266. (mkdir (string-append #$output "/bin"))
  267. (call-with-output-file
  268. (string-append #$output "/bin/guile")
  269. (lambda (port)
  270. (display "Fake!\n" port))))
  271. #:guile %bootstrap-guile))))
  272. (guile (package->derivation %bootstrap-guile))
  273. (drv (profile-derivation (manifest (list entry1 entry2))
  274. #:hooks '()
  275. #:locales? #f))
  276. (profile -> (derivation->output-path drv))
  277. (bindir -> (string-append profile "/bin"))
  278. (file -> (string-append bindir "/guile"))
  279. (_ (built-derivations (list drv))))
  280. (return (string=? (readlink file)
  281. (string-append
  282. (derivation->output-path guile)
  283. "/bin/guile")))))
  284. (test-assertm "load-profile"
  285. (mlet* %store-monad
  286. ((entry -> (package->manifest-entry %bootstrap-guile))
  287. (guile (package->derivation %bootstrap-guile))
  288. (drv (profile-derivation (manifest (list entry))
  289. #:hooks '()
  290. #:locales? #f))
  291. (profile -> (derivation->output-path drv))
  292. (bindir -> (string-append profile "/bin"))
  293. (_ (built-derivations (list drv))))
  294. (define-syntax-rule (with-environment-excursion exp ...)
  295. (let ((env (environ)))
  296. (dynamic-wind
  297. (const #t)
  298. (lambda () exp ...)
  299. (lambda () (environ env)))))
  300. (return (and (with-environment-excursion
  301. (load-profile profile)
  302. (and (string-prefix? (string-append bindir ":")
  303. (getenv "PATH"))
  304. (getenv "GUILE_LOAD_PATH")))
  305. (with-environment-excursion
  306. (load-profile profile #:pure? #t #:white-list '())
  307. (equal? (list (string-append "PATH=" bindir))
  308. (environ)))))))
  309. (test-assertm "<profile>"
  310. (mlet* %store-monad
  311. ((entry -> (package->manifest-entry %bootstrap-guile))
  312. (profile -> (profile (hooks '()) (locales? #f)
  313. (content (manifest (list entry)))))
  314. (drv (lower-object profile))
  315. (profile -> (derivation->output-path drv))
  316. (bindir -> (string-append profile "/bin"))
  317. (_ (built-derivations (list drv))))
  318. (return (file-exists? (string-append bindir "/guile")))))
  319. (test-assertm "profile-derivation relative symlinks, one entry"
  320. (mlet* %store-monad
  321. ((entry -> (package->manifest-entry %bootstrap-guile))
  322. (guile (package->derivation %bootstrap-guile))
  323. (drv (profile-derivation (manifest (list entry))
  324. #:relative-symlinks? #t
  325. #:hooks '()
  326. #:locales? #f))
  327. (profile -> (derivation->output-path drv))
  328. (bindir -> (string-append profile "/bin"))
  329. (_ (built-derivations (list drv))))
  330. (return (and (file-exists? (string-append bindir "/guile"))
  331. (string=? (readlink bindir)
  332. (string-append "../"
  333. (basename
  334. (derivation->output-path guile))
  335. "/bin"))))))
  336. (unless (network-reachable?) (test-skip 1))
  337. (test-assertm "profile-derivation relative symlinks, two entries"
  338. (mlet* %store-monad
  339. ((manifest -> (packages->manifest
  340. (list %bootstrap-guile gnu-make-for-tests)))
  341. (guile (package->derivation %bootstrap-guile))
  342. (make (package->derivation gnu-make-for-tests))
  343. (drv (profile-derivation manifest
  344. #:relative-symlinks? #t
  345. #:hooks '()
  346. #:locales? #f))
  347. (profile -> (derivation->output-path drv))
  348. (bindir -> (string-append profile "/bin"))
  349. (_ (built-derivations (list drv))))
  350. (return (and (file-exists? (string-append bindir "/guile"))
  351. (file-exists? (string-append bindir "/make"))
  352. (string=? (readlink (string-append bindir "/guile"))
  353. (string-append "../../"
  354. (basename
  355. (derivation->output-path guile))
  356. "/bin/guile"))
  357. (string=? (readlink (string-append bindir "/make"))
  358. (string-append "../../"
  359. (basename
  360. (derivation->output-path make))
  361. "/bin/make"))))))
  362. (test-assertm "profile-derivation, inputs"
  363. (mlet* %store-monad
  364. ((entry -> (package->manifest-entry packages:glibc "debug"))
  365. (drv (profile-derivation (manifest (list entry))
  366. #:hooks '()
  367. #:locales? #f)))
  368. (return (derivation-inputs drv))))
  369. (test-assertm "profile-derivation, cross-compilation"
  370. (mlet* %store-monad
  371. ((manifest -> (packages->manifest (list packages:sed packages:grep)))
  372. (target -> "arm-linux-gnueabihf")
  373. (grep (package->cross-derivation packages:grep target))
  374. (sed (package->cross-derivation packages:sed target))
  375. (locales (package->derivation packages:glibc-utf8-locales))
  376. (drv (profile-derivation manifest
  377. #:hooks '()
  378. #:locales? #t
  379. #:target target)))
  380. (define (find-input package)
  381. (let ((name (string-append (package-full-name package "-") ".drv")))
  382. (any (lambda (input)
  383. (let ((input (derivation-input-path input)))
  384. (and (string-suffix? name input) input)))
  385. (derivation-inputs drv))))
  386. ;; The inputs for grep and sed should be cross-build derivations, but that
  387. ;; for the glibc-utf8-locales should be a native build.
  388. (return (and (string=? (derivation-system drv) (%current-system))
  389. (string=? (find-input packages:grep)
  390. (derivation-file-name grep))
  391. (string=? (find-input packages:sed)
  392. (derivation-file-name sed))
  393. (string=? (find-input packages:glibc-utf8-locales)
  394. (derivation-file-name locales))))))
  395. (test-assert "package->manifest-entry defaults to \"out\""
  396. (let ((outputs (package-outputs packages:glibc)))
  397. (equal? (manifest-entry-output
  398. (package->manifest-entry (package
  399. (inherit packages:glibc)
  400. (outputs (reverse outputs)))))
  401. (manifest-entry-output
  402. (package->manifest-entry packages:glibc))
  403. "out")))
  404. (test-assertm "profile-manifest, search-paths"
  405. (mlet* %store-monad
  406. ((guile -> (package
  407. (inherit %bootstrap-guile)
  408. (native-search-paths
  409. (package-native-search-paths packages:guile-2.0))))
  410. (entry -> (package->manifest-entry guile))
  411. (drv (profile-derivation (manifest (list entry))
  412. #:hooks '()
  413. #:locales? #f))
  414. (profile -> (derivation->output-path drv)))
  415. (mbegin %store-monad
  416. (built-derivations (list drv))
  417. ;; Read the manifest back and make sure search paths are preserved.
  418. (let ((manifest (profile-manifest profile)))
  419. (match (manifest-entries manifest)
  420. ((result)
  421. (return (equal? (manifest-entry-search-paths result)
  422. (manifest-entry-search-paths entry)
  423. (package-native-search-paths
  424. packages:guile-2.0)))))))))
  425. (test-assert "package->manifest-entry, search paths"
  426. ;; See <http://bugs.gnu.org/22073>.
  427. (let ((mpl (@ (gnu packages python-xyz) python2-matplotlib)))
  428. (lset= eq?
  429. (package-transitive-native-search-paths mpl)
  430. (manifest-entry-search-paths
  431. (package->manifest-entry mpl)))))
  432. (test-assert "packages->manifest, no duplicates"
  433. (let ((expected
  434. (manifest
  435. (list
  436. (package->manifest-entry packages:guile-2.2))))
  437. (manifest (packages->manifest
  438. (list packages:guile-2.2 packages:guile-2.2))))
  439. (every manifest-entry=? (manifest-entries expected)
  440. (manifest-entries manifest))))
  441. (test-equal "packages->manifest, propagated inputs"
  442. (map (match-lambda
  443. ((label package)
  444. (list (package-name package) (package-version package)
  445. package)))
  446. (package-propagated-inputs packages:guile-2.2))
  447. (map (lambda (entry)
  448. (list (manifest-entry-name entry)
  449. (manifest-entry-version entry)
  450. (manifest-entry-item entry)))
  451. (manifest-entry-dependencies
  452. (package->manifest-entry packages:guile-2.2))))
  453. (test-assert "manifest-entry-parent"
  454. (let ((entry (package->manifest-entry packages:guile-2.2)))
  455. (match (manifest-entry-dependencies entry)
  456. ((dependencies ..1)
  457. (and (every (lambda (parent)
  458. (eq? entry (force parent)))
  459. (map manifest-entry-parent dependencies))
  460. (not (force (manifest-entry-parent entry))))))))
  461. (test-assertm "read-manifest"
  462. (mlet* %store-monad ((manifest -> (packages->manifest
  463. (list (package
  464. (inherit %bootstrap-guile)
  465. (native-search-paths
  466. (package-native-search-paths
  467. packages:guile-2.0))))))
  468. (drv (profile-derivation manifest
  469. #:hooks '()
  470. #:locales? #f))
  471. (out -> (derivation->output-path drv)))
  472. (define (entry->sexp entry)
  473. (list (manifest-entry-name entry)
  474. (manifest-entry-version entry)
  475. (manifest-entry-search-paths entry)
  476. (manifest-entry-dependencies entry)
  477. (force (manifest-entry-parent entry))))
  478. (mbegin %store-monad
  479. (built-derivations (list drv))
  480. (let ((manifest2 (profile-manifest out)))
  481. (return (equal? (map entry->sexp (manifest-entries manifest))
  482. (map entry->sexp (manifest-entries manifest2))))))))
  483. (test-equal "collision"
  484. '(("guile-bootstrap" "2.0") ("guile-bootstrap" "42"))
  485. (guard (c ((profile-collision-error? c)
  486. (let ((entry1 (profile-collision-error-entry c))
  487. (entry2 (profile-collision-error-conflict c)))
  488. (list (list (manifest-entry-name entry1)
  489. (manifest-entry-version entry1))
  490. (list (manifest-entry-name entry2)
  491. (manifest-entry-version entry2))))))
  492. (run-with-store %store
  493. (mlet* %store-monad ((p0 -> (package
  494. (inherit %bootstrap-guile)
  495. (version "42")))
  496. (p1 -> (dummy-package "p1"
  497. (propagated-inputs `(("p0" ,p0)))))
  498. (manifest -> (packages->manifest
  499. (list %bootstrap-guile p1)))
  500. (drv (profile-derivation manifest
  501. #:hooks '()
  502. #:locales? #f)))
  503. (return #f)))))
  504. (test-equal "collision of propagated inputs"
  505. '(("guile-bootstrap" "2.0") ("guile-bootstrap" "42"))
  506. (guard (c ((profile-collision-error? c)
  507. (let ((entry1 (profile-collision-error-entry c))
  508. (entry2 (profile-collision-error-conflict c)))
  509. (list (list (manifest-entry-name entry1)
  510. (manifest-entry-version entry1))
  511. (list (manifest-entry-name entry2)
  512. (manifest-entry-version entry2))))))
  513. (run-with-store %store
  514. (mlet* %store-monad ((p0 -> (package
  515. (inherit %bootstrap-guile)
  516. (version "42")))
  517. (p1 -> (dummy-package "p1"
  518. (propagated-inputs
  519. `(("guile" ,%bootstrap-guile)))))
  520. (p2 -> (dummy-package "p2"
  521. (propagated-inputs
  522. `(("guile" ,p0)))))
  523. (manifest -> (packages->manifest (list p1 p2)))
  524. (drv (profile-derivation manifest
  525. #:hooks '()
  526. #:locales? #f)))
  527. (return #f)))))
  528. (test-assertm "no collision"
  529. ;; Here we have an entry that is "lowered" (its 'item' field is a store file
  530. ;; name) and another entry (its 'item' field is a package) that is
  531. ;; equivalent.
  532. (mlet* %store-monad ((p -> (dummy-package "p"
  533. (propagated-inputs
  534. `(("guile" ,%bootstrap-guile)))))
  535. (guile (package->derivation %bootstrap-guile))
  536. (entry -> (manifest-entry
  537. (inherit (package->manifest-entry
  538. %bootstrap-guile))
  539. (item (derivation->output-path guile))))
  540. (manifest -> (manifest
  541. (list entry
  542. (package->manifest-entry p))))
  543. (drv (profile-derivation manifest)))
  544. (return (->bool drv))))
  545. (test-assertm "etc/profile"
  546. ;; Make sure we get an 'etc/profile' file that at least defines $PATH.
  547. (mlet* %store-monad
  548. ((guile -> (package
  549. (inherit %bootstrap-guile)
  550. (native-search-paths
  551. (package-native-search-paths packages:guile-2.0))))
  552. (entry -> (package->manifest-entry guile))
  553. (drv (profile-derivation (manifest (list entry))
  554. #:hooks '()
  555. #:locales? #f))
  556. (profile -> (derivation->output-path drv)))
  557. (mbegin %store-monad
  558. (built-derivations (list drv))
  559. (let* ((pipe (open-input-pipe
  560. (string-append "unset GUIX_PROFILE; "
  561. ;; 'source' is a Bashism; use '.' (dot).
  562. ". " profile "/etc/profile; "
  563. ;; Don't try to parse set(1) output because
  564. ;; it differs among shells; just use echo.
  565. "echo $PATH")))
  566. (path (get-string-all pipe)))
  567. (return
  568. (and (zero? (close-pipe pipe))
  569. (string-contains path (string-append profile "/bin"))))))))
  570. (test-assertm "etc/profile when etc/ already exists"
  571. ;; Here 'union-build' makes the profile's etc/ a symlink to the package's
  572. ;; etc/ directory, which makes it read-only. Make sure the profile build
  573. ;; handles that.
  574. (mlet* %store-monad
  575. ((thing -> (dummy-package "dummy"
  576. (build-system trivial-build-system)
  577. (arguments
  578. `(#:guile ,%bootstrap-guile
  579. #:builder
  580. (let ((out (assoc-ref %outputs "out")))
  581. (mkdir out)
  582. (mkdir (string-append out "/etc"))
  583. (call-with-output-file (string-append out "/etc/foo")
  584. (lambda (port)
  585. (display "foo!" port)))
  586. #t)))))
  587. (entry -> (package->manifest-entry thing))
  588. (drv (profile-derivation (manifest (list entry))
  589. #:hooks '()
  590. #:locales? #f))
  591. (profile -> (derivation->output-path drv)))
  592. (mbegin %store-monad
  593. (built-derivations (list drv))
  594. (return (and (file-exists? (string-append profile "/etc/profile"))
  595. (string=? (call-with-input-file
  596. (string-append profile "/etc/foo")
  597. get-string-all)
  598. "foo!"))))))
  599. (test-assertm "etc/profile when etc/ is a symlink"
  600. ;; When etc/ is a symlink, the unsymlink code in 0.8.2 would fail
  601. ;; gracelessly because 'scandir' would return #f.
  602. (mlet* %store-monad
  603. ((thing -> (dummy-package "dummy"
  604. (build-system trivial-build-system)
  605. (arguments
  606. `(#:guile ,%bootstrap-guile
  607. #:builder
  608. (let ((out (assoc-ref %outputs "out")))
  609. (mkdir out)
  610. (mkdir (string-append out "/foo"))
  611. (symlink "foo" (string-append out "/etc"))
  612. (call-with-output-file (string-append out "/etc/bar")
  613. (lambda (port)
  614. (display "foo!" port)))
  615. #t)))))
  616. (entry -> (package->manifest-entry thing))
  617. (drv (profile-derivation (manifest (list entry))
  618. #:hooks '()
  619. #:locales? #f))
  620. (profile -> (derivation->output-path drv)))
  621. (mbegin %store-monad
  622. (built-derivations (list drv))
  623. (return (and (file-exists? (string-append profile "/etc/profile"))
  624. (string=? (call-with-input-file
  625. (string-append profile "/etc/bar")
  626. get-string-all)
  627. "foo!"))))))
  628. (test-assertm "profile-derivation when etc/ is a relative symlink"
  629. ;; See <https://bugs.gnu.org/32686>.
  630. (mlet* %store-monad
  631. ((etc (gexp->derivation
  632. "etc"
  633. #~(begin
  634. (mkdir #$output)
  635. (call-with-output-file (string-append #$output "/foo")
  636. (lambda (port)
  637. (display "Heya!" port))))))
  638. (thing -> (dummy-package "dummy"
  639. (build-system trivial-build-system)
  640. (inputs
  641. `(("etc" ,etc)))
  642. (arguments
  643. `(#:guile ,%bootstrap-guile
  644. #:builder
  645. (let ((out (assoc-ref %outputs "out"))
  646. (etc (assoc-ref %build-inputs "etc")))
  647. (mkdir out)
  648. (symlink etc (string-append out "/etc"))
  649. #t)))))
  650. (entry -> (package->manifest-entry thing))
  651. (drv (profile-derivation (manifest (list entry))
  652. #:relative-symlinks? #t
  653. #:hooks '()
  654. #:locales? #f))
  655. (profile -> (derivation->output-path drv)))
  656. (mbegin %store-monad
  657. (built-derivations (list drv))
  658. (return (string=? (call-with-input-file
  659. (string-append profile "/etc/foo")
  660. get-string-all)
  661. "Heya!")))))
  662. (test-equalm "union vs. dangling symlink" ;<https://bugs.gnu.org/26949>
  663. "does-not-exist"
  664. (mlet* %store-monad
  665. ((thing1 -> (dummy-package "dummy"
  666. (build-system trivial-build-system)
  667. (arguments
  668. `(#:guile ,%bootstrap-guile
  669. #:builder
  670. (let ((out (assoc-ref %outputs "out")))
  671. (mkdir out)
  672. (symlink "does-not-exist"
  673. (string-append out "/dangling"))
  674. #t)))))
  675. (thing2 -> (package (inherit thing1) (name "dummy2")))
  676. (drv (profile-derivation (packages->manifest
  677. (list thing1 thing2))
  678. #:hooks '()
  679. #:locales? #f))
  680. (profile -> (derivation->output-path drv)))
  681. (mbegin %store-monad
  682. (built-derivations (list drv))
  683. (return (readlink (readlink (string-append profile "/dangling")))))))
  684. (test-equalm "profile in profile"
  685. '("foo" "0")
  686. ;; Make sure we can build a profile that has another profile has one of its
  687. ;; entries. The new profile's /manifest and /etc/profile must override the
  688. ;; other's.
  689. (mlet* %store-monad
  690. ((prof0 (profile-derivation
  691. (manifest
  692. (list (package->manifest-entry %bootstrap-guile)))
  693. #:hooks '()
  694. #:locales? #f))
  695. (prof1 (profile-derivation
  696. (manifest (list (manifest-entry
  697. (name "foo")
  698. (version "0")
  699. (item prof0))))
  700. #:hooks '()
  701. #:locales? #f)))
  702. (mbegin %store-monad
  703. (built-derivations (list prof1))
  704. (let ((out (derivation->output-path prof1)))
  705. (return (and (file-exists?
  706. (string-append out "/bin/guile"))
  707. (let ((manifest (profile-manifest out)))
  708. (match (manifest-entries manifest)
  709. ((entry)
  710. (list (manifest-entry-name entry)
  711. (manifest-entry-version entry)))))))))))
  712. (test-end "profiles")
  713. ;;; Local Variables:
  714. ;;; eval: (put 'dummy-package 'scheme-indent-function 1)
  715. ;;; End: