profiles.scm 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019 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-assert "manifest-remove"
  102. (let* ((m0 (manifest (list guile-2.0.9 guile-2.0.9:debug)))
  103. (m1 (manifest-remove m0
  104. (list (manifest-pattern (name "guile")))))
  105. (m2 (manifest-remove m1
  106. (list (manifest-pattern (name "guile"))))) ; same
  107. (m3 (manifest-remove m2
  108. (list (manifest-pattern
  109. (name "guile") (output "debug")))))
  110. (m4 (manifest-remove m3
  111. (list (manifest-pattern (name "guile"))))))
  112. (match (manifest-entries m2)
  113. ((($ <manifest-entry> "guile" "2.0.9" "debug"))
  114. (and (equal? m1 m2)
  115. (null? (manifest-entries m3))
  116. (null? (manifest-entries m4)))))))
  117. (test-assert "manifest-add"
  118. (let* ((m0 (manifest '()))
  119. (m1 (manifest-add m0 (list guile-1.8.8)))
  120. (m2 (manifest-add m1 (list guile-2.0.9)))
  121. (m3 (manifest-add m2 (list guile-2.0.9:debug)))
  122. (m4 (manifest-add m3 (list guile-2.0.9:debug))))
  123. (and (match (manifest-entries m1)
  124. ((($ <manifest-entry> "guile" "1.8.8" "out")) #t)
  125. (_ #f))
  126. (match (manifest-entries m2)
  127. ((($ <manifest-entry> "guile" "2.0.9" "out")) #t)
  128. (_ #f))
  129. (equal? m3 m4))))
  130. (test-equal "manifest-add removes duplicates" ;<https://bugs.gnu.org/30569>
  131. (list guile-2.0.9)
  132. (manifest-entries (manifest-add (manifest '())
  133. (list guile-2.0.9 guile-2.0.9))))
  134. (test-assert "manifest-perform-transaction"
  135. (let* ((m0 (manifest (list guile-2.0.9 guile-2.0.9:debug)))
  136. (t1 (manifest-transaction
  137. (install (list guile-1.8.8))
  138. (remove (list (manifest-pattern (name "guile")
  139. (output "debug"))))))
  140. (t2 (manifest-transaction
  141. (remove (list (manifest-pattern (name "guile")
  142. (version "2.0.9")
  143. (output #f))))))
  144. (m1 (manifest-perform-transaction m0 t1))
  145. (m2 (manifest-perform-transaction m1 t2))
  146. (m3 (manifest-perform-transaction m0 t2)))
  147. (and (match (manifest-entries m1)
  148. ((($ <manifest-entry> "guile" "1.8.8" "out")) #t)
  149. (_ #f))
  150. (equal? m1 m2)
  151. (null? (manifest-entries m3)))))
  152. (test-assert "manifest-transaction-effects"
  153. (let* ((m0 (manifest (list guile-1.8.8)))
  154. (t (manifest-transaction
  155. (install (list guile-2.0.9 glibc)))))
  156. (let-values (((remove install upgrade downgrade)
  157. (manifest-transaction-effects m0 t)))
  158. (and (null? remove) (null? downgrade)
  159. (equal? (list glibc) install)
  160. (equal? (list (cons guile-1.8.8 guile-2.0.9)) upgrade)))))
  161. (test-assert "manifest-transaction-effects and downgrades"
  162. (let* ((m0 (manifest (list guile-2.0.9)))
  163. (t (manifest-transaction (install (list guile-1.8.8)))))
  164. (let-values (((remove install upgrade downgrade)
  165. (manifest-transaction-effects m0 t)))
  166. (and (null? remove) (null? install) (null? upgrade)
  167. (equal? (list (cons guile-2.0.9 guile-1.8.8)) downgrade)))))
  168. (test-assert "manifest-transaction-effects and pseudo-upgrades"
  169. (let* ((m0 (manifest (list guile-2.0.9)))
  170. (t (manifest-transaction (install (list guile-2.0.9)))))
  171. (let-values (((remove install upgrade downgrade)
  172. (manifest-transaction-effects m0 t)))
  173. (and (null? remove) (null? install) (null? downgrade)
  174. (equal? (list (cons guile-2.0.9 guile-2.0.9)) upgrade)))))
  175. (test-assert "manifest-transaction-null?"
  176. (manifest-transaction-null? (manifest-transaction)))
  177. (test-assert "manifest-transaction-removal-candidate?"
  178. (let ((m (manifest (list guile-2.0.9)))
  179. (t (manifest-transaction
  180. (remove (list (manifest-pattern (name "guile")))))))
  181. (and (manifest-transaction-removal-candidate? guile-2.0.9 t)
  182. (not (manifest-transaction-removal-candidate? glibc t)))))
  183. (test-assertm "profile-derivation"
  184. (mlet* %store-monad
  185. ((entry -> (package->manifest-entry %bootstrap-guile))
  186. (guile (package->derivation %bootstrap-guile))
  187. (drv (profile-derivation (manifest (list entry))
  188. #:hooks '()
  189. #:locales? #f))
  190. (profile -> (derivation->output-path drv))
  191. (bindir -> (string-append profile "/bin"))
  192. (_ (built-derivations (list drv))))
  193. (return (and (file-exists? (string-append bindir "/guile"))
  194. (string=? (dirname (readlink bindir))
  195. (derivation->output-path guile))))))
  196. (test-assertm "profile-derivation relative symlinks, one entry"
  197. (mlet* %store-monad
  198. ((entry -> (package->manifest-entry %bootstrap-guile))
  199. (guile (package->derivation %bootstrap-guile))
  200. (drv (profile-derivation (manifest (list entry))
  201. #:relative-symlinks? #t
  202. #:hooks '()
  203. #:locales? #f))
  204. (profile -> (derivation->output-path drv))
  205. (bindir -> (string-append profile "/bin"))
  206. (_ (built-derivations (list drv))))
  207. (return (and (file-exists? (string-append bindir "/guile"))
  208. (string=? (readlink bindir)
  209. (string-append "../"
  210. (basename
  211. (derivation->output-path guile))
  212. "/bin"))))))
  213. (unless (network-reachable?) (test-skip 1))
  214. (test-assertm "profile-derivation relative symlinks, two entries"
  215. (mlet* %store-monad
  216. ((gnu-make-boot0 -> (@@ (gnu packages commencement) gnu-make-boot0))
  217. (manifest -> (packages->manifest
  218. (list %bootstrap-guile gnu-make-boot0)))
  219. (guile (package->derivation %bootstrap-guile))
  220. (make (package->derivation gnu-make-boot0))
  221. (drv (profile-derivation manifest
  222. #:relative-symlinks? #t
  223. #:hooks '()
  224. #:locales? #f))
  225. (profile -> (derivation->output-path drv))
  226. (bindir -> (string-append profile "/bin"))
  227. (_ (built-derivations (list drv))))
  228. (return (and (file-exists? (string-append bindir "/guile"))
  229. (file-exists? (string-append bindir "/make"))
  230. (string=? (readlink (string-append bindir "/guile"))
  231. (string-append "../../"
  232. (basename
  233. (derivation->output-path guile))
  234. "/bin/guile"))
  235. (string=? (readlink (string-append bindir "/make"))
  236. (string-append "../../"
  237. (basename
  238. (derivation->output-path make))
  239. "/bin/make"))))))
  240. (test-assertm "profile-derivation, inputs"
  241. (mlet* %store-monad
  242. ((entry -> (package->manifest-entry packages:glibc "debug"))
  243. (drv (profile-derivation (manifest (list entry))
  244. #:hooks '()
  245. #:locales? #f)))
  246. (return (derivation-inputs drv))))
  247. (test-assertm "profile-derivation, cross-compilation"
  248. (mlet* %store-monad
  249. ((manifest -> (packages->manifest (list packages:sed packages:grep)))
  250. (target -> "arm-linux-gnueabihf")
  251. (grep (package->cross-derivation packages:grep target))
  252. (sed (package->cross-derivation packages:sed target))
  253. (locales (package->derivation packages:glibc-utf8-locales))
  254. (drv (profile-derivation manifest
  255. #:hooks '()
  256. #:locales? #t
  257. #:target target)))
  258. (define (find-input package)
  259. (let ((name (string-append (package-full-name package "-") ".drv")))
  260. (any (lambda (input)
  261. (let ((input (derivation-input-path input)))
  262. (and (string-suffix? name input) input)))
  263. (derivation-inputs drv))))
  264. ;; The inputs for grep and sed should be cross-build derivations, but that
  265. ;; for the glibc-utf8-locales should be a native build.
  266. (return (and (string=? (derivation-system drv) (%current-system))
  267. (string=? (find-input packages:grep)
  268. (derivation-file-name grep))
  269. (string=? (find-input packages:sed)
  270. (derivation-file-name sed))
  271. (string=? (find-input packages:glibc-utf8-locales)
  272. (derivation-file-name locales))))))
  273. (test-assert "package->manifest-entry defaults to \"out\""
  274. (let ((outputs (package-outputs packages:glibc)))
  275. (equal? (manifest-entry-output
  276. (package->manifest-entry (package
  277. (inherit packages:glibc)
  278. (outputs (reverse outputs)))))
  279. (manifest-entry-output
  280. (package->manifest-entry packages:glibc))
  281. "out")))
  282. (test-assertm "profile-manifest, search-paths"
  283. (mlet* %store-monad
  284. ((guile -> (package
  285. (inherit %bootstrap-guile)
  286. (native-search-paths
  287. (package-native-search-paths packages:guile-2.0))))
  288. (entry -> (package->manifest-entry guile))
  289. (drv (profile-derivation (manifest (list entry))
  290. #:hooks '()
  291. #:locales? #f))
  292. (profile -> (derivation->output-path drv)))
  293. (mbegin %store-monad
  294. (built-derivations (list drv))
  295. ;; Read the manifest back and make sure search paths are preserved.
  296. (let ((manifest (profile-manifest profile)))
  297. (match (manifest-entries manifest)
  298. ((result)
  299. (return (equal? (manifest-entry-search-paths result)
  300. (manifest-entry-search-paths entry)
  301. (package-native-search-paths
  302. packages:guile-2.0)))))))))
  303. (test-assert "package->manifest-entry, search paths"
  304. ;; See <http://bugs.gnu.org/22073>.
  305. (let ((mpl (@ (gnu packages python-xyz) python2-matplotlib)))
  306. (lset= eq?
  307. (package-transitive-native-search-paths mpl)
  308. (manifest-entry-search-paths
  309. (package->manifest-entry mpl)))))
  310. (test-equal "packages->manifest, propagated inputs"
  311. (map (match-lambda
  312. ((label package)
  313. (list (package-name package) (package-version package)
  314. package)))
  315. (package-propagated-inputs packages:guile-2.2))
  316. (map (lambda (entry)
  317. (list (manifest-entry-name entry)
  318. (manifest-entry-version entry)
  319. (manifest-entry-item entry)))
  320. (manifest-entry-dependencies
  321. (package->manifest-entry packages:guile-2.2))))
  322. (test-assert "manifest-entry-parent"
  323. (let ((entry (package->manifest-entry packages:guile-2.2)))
  324. (match (manifest-entry-dependencies entry)
  325. ((dependencies ..1)
  326. (and (every (lambda (parent)
  327. (eq? entry (force parent)))
  328. (map manifest-entry-parent dependencies))
  329. (not (force (manifest-entry-parent entry))))))))
  330. (test-assertm "read-manifest"
  331. (mlet* %store-monad ((manifest -> (packages->manifest
  332. (list (package
  333. (inherit %bootstrap-guile)
  334. (native-search-paths
  335. (package-native-search-paths
  336. packages:guile-2.0))))))
  337. (drv (profile-derivation manifest
  338. #:hooks '()
  339. #:locales? #f))
  340. (out -> (derivation->output-path drv)))
  341. (define (entry->sexp entry)
  342. (list (manifest-entry-name entry)
  343. (manifest-entry-version entry)
  344. (manifest-entry-search-paths entry)
  345. (manifest-entry-dependencies entry)
  346. (force (manifest-entry-parent entry))))
  347. (mbegin %store-monad
  348. (built-derivations (list drv))
  349. (let ((manifest2 (profile-manifest out)))
  350. (return (equal? (map entry->sexp (manifest-entries manifest))
  351. (map entry->sexp (manifest-entries manifest2))))))))
  352. (test-equal "collision"
  353. '(("guile-bootstrap" "2.0") ("guile-bootstrap" "42"))
  354. (guard (c ((profile-collision-error? c)
  355. (let ((entry1 (profile-collision-error-entry c))
  356. (entry2 (profile-collision-error-conflict c)))
  357. (list (list (manifest-entry-name entry1)
  358. (manifest-entry-version entry1))
  359. (list (manifest-entry-name entry2)
  360. (manifest-entry-version entry2))))))
  361. (run-with-store %store
  362. (mlet* %store-monad ((p0 -> (package
  363. (inherit %bootstrap-guile)
  364. (version "42")))
  365. (p1 -> (dummy-package "p1"
  366. (propagated-inputs `(("p0" ,p0)))))
  367. (manifest -> (packages->manifest
  368. (list %bootstrap-guile p1)))
  369. (drv (profile-derivation manifest
  370. #:hooks '()
  371. #:locales? #f)))
  372. (return #f)))))
  373. (test-equal "collision of propagated inputs"
  374. '(("guile-bootstrap" "2.0") ("guile-bootstrap" "42"))
  375. (guard (c ((profile-collision-error? c)
  376. (let ((entry1 (profile-collision-error-entry c))
  377. (entry2 (profile-collision-error-conflict c)))
  378. (list (list (manifest-entry-name entry1)
  379. (manifest-entry-version entry1))
  380. (list (manifest-entry-name entry2)
  381. (manifest-entry-version entry2))))))
  382. (run-with-store %store
  383. (mlet* %store-monad ((p0 -> (package
  384. (inherit %bootstrap-guile)
  385. (version "42")))
  386. (p1 -> (dummy-package "p1"
  387. (propagated-inputs
  388. `(("guile" ,%bootstrap-guile)))))
  389. (p2 -> (dummy-package "p2"
  390. (propagated-inputs
  391. `(("guile" ,p0)))))
  392. (manifest -> (packages->manifest (list p1 p2)))
  393. (drv (profile-derivation manifest
  394. #:hooks '()
  395. #:locales? #f)))
  396. (return #f)))))
  397. (test-assertm "no collision"
  398. ;; Here we have an entry that is "lowered" (its 'item' field is a store file
  399. ;; name) and another entry (its 'item' field is a package) that is
  400. ;; equivalent.
  401. (mlet* %store-monad ((p -> (dummy-package "p"
  402. (propagated-inputs
  403. `(("guile" ,%bootstrap-guile)))))
  404. (guile (package->derivation %bootstrap-guile))
  405. (entry -> (manifest-entry
  406. (inherit (package->manifest-entry
  407. %bootstrap-guile))
  408. (item (derivation->output-path guile))))
  409. (manifest -> (manifest
  410. (list entry
  411. (package->manifest-entry p))))
  412. (drv (profile-derivation manifest)))
  413. (return (->bool drv))))
  414. (test-assertm "etc/profile"
  415. ;; Make sure we get an 'etc/profile' file that at least defines $PATH.
  416. (mlet* %store-monad
  417. ((guile -> (package
  418. (inherit %bootstrap-guile)
  419. (native-search-paths
  420. (package-native-search-paths packages:guile-2.0))))
  421. (entry -> (package->manifest-entry guile))
  422. (drv (profile-derivation (manifest (list entry))
  423. #:hooks '()
  424. #:locales? #f))
  425. (profile -> (derivation->output-path drv)))
  426. (mbegin %store-monad
  427. (built-derivations (list drv))
  428. (let* ((pipe (open-input-pipe
  429. (string-append "unset GUIX_PROFILE; "
  430. ;; 'source' is a Bashism; use '.' (dot).
  431. ". " profile "/etc/profile; "
  432. ;; Don't try to parse set(1) output because
  433. ;; it differs among shells; just use echo.
  434. "echo $PATH")))
  435. (path (get-string-all pipe)))
  436. (return
  437. (and (zero? (close-pipe pipe))
  438. (string-contains path (string-append profile "/bin"))))))))
  439. (test-assertm "etc/profile when etc/ already exists"
  440. ;; Here 'union-build' makes the profile's etc/ a symlink to the package's
  441. ;; etc/ directory, which makes it read-only. Make sure the profile build
  442. ;; handles that.
  443. (mlet* %store-monad
  444. ((thing -> (dummy-package "dummy"
  445. (build-system trivial-build-system)
  446. (arguments
  447. `(#:guile ,%bootstrap-guile
  448. #:builder
  449. (let ((out (assoc-ref %outputs "out")))
  450. (mkdir out)
  451. (mkdir (string-append out "/etc"))
  452. (call-with-output-file (string-append out "/etc/foo")
  453. (lambda (port)
  454. (display "foo!" port)))
  455. #t)))))
  456. (entry -> (package->manifest-entry thing))
  457. (drv (profile-derivation (manifest (list entry))
  458. #:hooks '()
  459. #:locales? #f))
  460. (profile -> (derivation->output-path drv)))
  461. (mbegin %store-monad
  462. (built-derivations (list drv))
  463. (return (and (file-exists? (string-append profile "/etc/profile"))
  464. (string=? (call-with-input-file
  465. (string-append profile "/etc/foo")
  466. get-string-all)
  467. "foo!"))))))
  468. (test-assertm "etc/profile when etc/ is a symlink"
  469. ;; When etc/ is a symlink, the unsymlink code in 0.8.2 would fail
  470. ;; gracelessly because 'scandir' would return #f.
  471. (mlet* %store-monad
  472. ((thing -> (dummy-package "dummy"
  473. (build-system trivial-build-system)
  474. (arguments
  475. `(#:guile ,%bootstrap-guile
  476. #:builder
  477. (let ((out (assoc-ref %outputs "out")))
  478. (mkdir out)
  479. (mkdir (string-append out "/foo"))
  480. (symlink "foo" (string-append out "/etc"))
  481. (call-with-output-file (string-append out "/etc/bar")
  482. (lambda (port)
  483. (display "foo!" port)))
  484. #t)))))
  485. (entry -> (package->manifest-entry thing))
  486. (drv (profile-derivation (manifest (list entry))
  487. #:hooks '()
  488. #:locales? #f))
  489. (profile -> (derivation->output-path drv)))
  490. (mbegin %store-monad
  491. (built-derivations (list drv))
  492. (return (and (file-exists? (string-append profile "/etc/profile"))
  493. (string=? (call-with-input-file
  494. (string-append profile "/etc/bar")
  495. get-string-all)
  496. "foo!"))))))
  497. (test-assertm "profile-derivation when etc/ is a relative symlink"
  498. ;; See <https://bugs.gnu.org/32686>.
  499. (mlet* %store-monad
  500. ((etc (gexp->derivation
  501. "etc"
  502. #~(begin
  503. (mkdir #$output)
  504. (call-with-output-file (string-append #$output "/foo")
  505. (lambda (port)
  506. (display "Heya!" port))))))
  507. (thing -> (dummy-package "dummy"
  508. (build-system trivial-build-system)
  509. (inputs
  510. `(("etc" ,etc)))
  511. (arguments
  512. `(#:guile ,%bootstrap-guile
  513. #:builder
  514. (let ((out (assoc-ref %outputs "out"))
  515. (etc (assoc-ref %build-inputs "etc")))
  516. (mkdir out)
  517. (symlink etc (string-append out "/etc"))
  518. #t)))))
  519. (entry -> (package->manifest-entry thing))
  520. (drv (profile-derivation (manifest (list entry))
  521. #:relative-symlinks? #t
  522. #:hooks '()
  523. #:locales? #f))
  524. (profile -> (derivation->output-path drv)))
  525. (mbegin %store-monad
  526. (built-derivations (list drv))
  527. (return (string=? (call-with-input-file
  528. (string-append profile "/etc/foo")
  529. get-string-all)
  530. "Heya!")))))
  531. (test-equalm "union vs. dangling symlink" ;<https://bugs.gnu.org/26949>
  532. "does-not-exist"
  533. (mlet* %store-monad
  534. ((thing1 -> (dummy-package "dummy"
  535. (build-system trivial-build-system)
  536. (arguments
  537. `(#:guile ,%bootstrap-guile
  538. #:builder
  539. (let ((out (assoc-ref %outputs "out")))
  540. (mkdir out)
  541. (symlink "does-not-exist"
  542. (string-append out "/dangling"))
  543. #t)))))
  544. (thing2 -> (package (inherit thing1) (name "dummy2")))
  545. (drv (profile-derivation (packages->manifest
  546. (list thing1 thing2))
  547. #:hooks '()
  548. #:locales? #f))
  549. (profile -> (derivation->output-path drv)))
  550. (mbegin %store-monad
  551. (built-derivations (list drv))
  552. (return (readlink (readlink (string-append profile "/dangling")))))))
  553. (test-equalm "profile in profile"
  554. '("foo" "0")
  555. ;; Make sure we can build a profile that has another profile has one of its
  556. ;; entries. The new profile's /manifest and /etc/profile must override the
  557. ;; other's.
  558. (mlet* %store-monad
  559. ((prof0 (profile-derivation
  560. (manifest
  561. (list (package->manifest-entry %bootstrap-guile)))
  562. #:hooks '()
  563. #:locales? #f))
  564. (prof1 (profile-derivation
  565. (manifest (list (manifest-entry
  566. (name "foo")
  567. (version "0")
  568. (item prof0))))
  569. #:hooks '()
  570. #:locales? #f)))
  571. (mbegin %store-monad
  572. (built-derivations (list prof1))
  573. (let ((out (derivation->output-path prof1)))
  574. (return (and (file-exists?
  575. (string-append out "/bin/guile"))
  576. (let ((manifest (profile-manifest out)))
  577. (match (manifest-entries manifest)
  578. ((entry)
  579. (list (manifest-entry-name entry)
  580. (manifest-entry-version entry)))))))))))
  581. (test-end "profiles")
  582. ;;; Local Variables:
  583. ;;; eval: (put 'dummy-package 'scheme-indent-function 1)
  584. ;;; End: