profiles.scm 31 KB

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