pack.scm 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2015, 2017, 2018, 2019, 2020 Ludovic Courtès <ludo@gnu.org>
  3. ;;; Copyright © 2017, 2018 Ricardo Wurmus <rekado@elephly.net>
  4. ;;; Copyright © 2018 Konrad Hinsen <konrad.hinsen@fastmail.net>
  5. ;;; Copyright © 2018 Chris Marusich <cmmarusich@gmail.com>
  6. ;;; Copyright © 2018 Efraim Flashner <efraim@flashner.co.il>
  7. ;;; Copyright © 2020 Tobias Geerinckx-Rice <me@tobias.gr>
  8. ;;;
  9. ;;; This file is part of GNU Guix.
  10. ;;;
  11. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  12. ;;; under the terms of the GNU General Public License as published by
  13. ;;; the Free Software Foundation; either version 3 of the License, or (at
  14. ;;; your option) any later version.
  15. ;;;
  16. ;;; GNU Guix is distributed in the hope that it will be useful, but
  17. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  18. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. ;;; GNU General Public License for more details.
  20. ;;;
  21. ;;; You should have received a copy of the GNU General Public License
  22. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  23. (define-module (guix scripts pack)
  24. #:use-module (guix scripts)
  25. #:use-module (guix ui)
  26. #:use-module (guix gexp)
  27. #:use-module (guix utils)
  28. #:use-module (guix store)
  29. #:use-module ((guix status) #:select (with-status-verbosity))
  30. #:use-module ((guix self) #:select (make-config.scm))
  31. #:use-module (guix grafts)
  32. #:autoload (guix inferior) (inferior-package?
  33. inferior-package-name
  34. inferior-package-version)
  35. #:use-module (guix monads)
  36. #:use-module (guix modules)
  37. #:use-module (guix packages)
  38. #:use-module (guix profiles)
  39. #:use-module (guix describe)
  40. #:use-module (guix derivations)
  41. #:use-module (guix search-paths)
  42. #:use-module (guix build-system gnu)
  43. #:use-module (guix scripts build)
  44. #:use-module ((guix self) #:select (make-config.scm))
  45. #:use-module (gnu packages)
  46. #:use-module (gnu packages bootstrap)
  47. #:use-module ((gnu packages compression) #:hide (zip))
  48. #:use-module (gnu packages guile)
  49. #:use-module (gnu packages base)
  50. #:autoload (gnu packages package-management) (guix)
  51. #:autoload (gnu packages gnupg) (guile-gcrypt)
  52. #:autoload (gnu packages guile) (guile2.0-json guile-json)
  53. #:use-module (srfi srfi-1)
  54. #:use-module (srfi srfi-9)
  55. #:use-module (srfi srfi-26)
  56. #:use-module (srfi srfi-37)
  57. #:use-module (ice-9 match)
  58. #:export (compressor?
  59. lookup-compressor
  60. self-contained-tarball
  61. docker-image
  62. squashfs-image
  63. guix-pack))
  64. ;; Type of a compression tool.
  65. (define-record-type <compressor>
  66. (compressor name extension command)
  67. compressor?
  68. (name compressor-name) ;string (e.g., "gzip")
  69. (extension compressor-extension) ;string (e.g., ".lz")
  70. (command compressor-command)) ;gexp (e.g., #~("/gnu/store/…/gzip" "-9n"))
  71. (define %compressors
  72. ;; Available compression tools.
  73. (list (compressor "gzip" ".gz"
  74. #~(#+(file-append gzip "/bin/gzip") "-9n"))
  75. (compressor "lzip" ".lz"
  76. #~(#+(file-append lzip "/bin/lzip") "-9"))
  77. (compressor "xz" ".xz"
  78. #~(#+(file-append xz "/bin/xz") "-e"))
  79. (compressor "bzip2" ".bz2"
  80. #~(#+(file-append bzip2 "/bin/bzip2") "-9"))
  81. (compressor "zstd" ".zst"
  82. ;; The default level 3 compresses better than gzip in a
  83. ;; fraction of the time, while the highest level 19
  84. ;; (de)compresses more slowly and worse than xz.
  85. #~(#+(file-append zstd "/bin/zstd") "-3"))
  86. (compressor "none" "" #f)))
  87. ;; This one is only for use in this module, so don't put it in %compressors.
  88. (define bootstrap-xz
  89. (compressor "bootstrap-xz" ".xz"
  90. #~(#+(file-append %bootstrap-coreutils&co "/bin/xz") "-e")))
  91. (define (lookup-compressor name)
  92. "Return the compressor object called NAME. Error out if it could not be
  93. found."
  94. (or (find (match-lambda
  95. (($ <compressor> name*)
  96. (string=? name* name)))
  97. %compressors)
  98. (leave (G_ "~a: compressor not found~%") name)))
  99. (define not-config?
  100. ;; Select (guix …) and (gnu …) modules, except (guix config).
  101. (match-lambda
  102. (('guix 'config) #f)
  103. (('guix _ ...) #t)
  104. (('gnu _ ...) #t)
  105. (_ #f)))
  106. (define gcrypt-sqlite3&co
  107. ;; Guile-Gcrypt, Guile-SQLite3, and their propagated inputs.
  108. (append-map (lambda (package)
  109. (cons package
  110. (match (package-transitive-propagated-inputs package)
  111. (((labels packages) ...)
  112. packages))))
  113. (list guile-gcrypt guile-sqlite3)))
  114. (define (store-database items)
  115. "Return a directory containing a store database where all of ITEMS and their
  116. dependencies are registered."
  117. (define schema
  118. (local-file (search-path %load-path
  119. "guix/store/schema.sql")))
  120. (define labels
  121. (map (lambda (n)
  122. (string-append "closure" (number->string n)))
  123. (iota (length items))))
  124. (define build
  125. (with-extensions gcrypt-sqlite3&co
  126. (with-imported-modules (source-module-closure
  127. '((guix build store-copy)
  128. (guix store database)))
  129. #~(begin
  130. (use-modules (guix store database)
  131. (guix build store-copy)
  132. (srfi srfi-1))
  133. (define (read-closure closure)
  134. (call-with-input-file closure read-reference-graph))
  135. (define db-file
  136. (store-database-file #:state-directory #$output))
  137. ;; Make sure non-ASCII file names are properly handled.
  138. (setenv "GUIX_LOCPATH"
  139. #+(file-append glibc-utf8-locales "/lib/locale"))
  140. (setlocale LC_ALL "en_US.utf8")
  141. (sql-schema #$schema)
  142. (let ((items (append-map read-closure '#$labels)))
  143. (with-database db-file db
  144. (register-items db items
  145. #:deduplicate? #f
  146. #:reset-timestamps? #f
  147. #:registration-time %epoch)))))))
  148. (computed-file "store-database" build
  149. #:options `(#:references-graphs ,(zip labels items))))
  150. (define* (self-contained-tarball name profile
  151. #:key target
  152. (profile-name "guix-profile")
  153. deduplicate?
  154. entry-point
  155. (compressor (first %compressors))
  156. localstatedir?
  157. (symlinks '())
  158. (archiver tar))
  159. "Return a self-contained tarball containing a store initialized with the
  160. closure of PROFILE, a derivation. The tarball contains /gnu/store; if
  161. LOCALSTATEDIR? is true, it also contains /var/guix, including /var/guix/db
  162. with a properly initialized store database.
  163. SYMLINKS must be a list of (SOURCE -> TARGET) tuples denoting symlinks to be
  164. added to the pack."
  165. (define database
  166. (and localstatedir?
  167. (file-append (store-database (list profile))
  168. "/db/db.sqlite")))
  169. (define set-utf8-locale
  170. ;; Arrange to not depend on 'glibc-utf8-locales' when using '--bootstrap'.
  171. (and (or (not (profile? profile))
  172. (profile-locales? profile))
  173. #~(begin
  174. (setenv "GUIX_LOCPATH"
  175. #+(file-append glibc-utf8-locales "/lib/locale"))
  176. (setlocale LC_ALL "en_US.utf8"))))
  177. (define build
  178. (with-imported-modules (source-module-closure
  179. `((guix build utils)
  180. (guix build union)
  181. (gnu build install))
  182. #:select? not-config?)
  183. #~(begin
  184. (use-modules (guix build utils)
  185. ((guix build union) #:select (relative-file-name))
  186. (gnu build install)
  187. (srfi srfi-1)
  188. (srfi srfi-26)
  189. (ice-9 match))
  190. (define %root "root")
  191. (define symlink->directives
  192. ;; Return "populate directives" to make the given symlink and its
  193. ;; parent directories.
  194. (match-lambda
  195. ((source '-> target)
  196. (let ((target (string-append #$profile "/" target))
  197. (parent (dirname source)))
  198. ;; Never add a 'directory' directive for "/" so as to
  199. ;; preserve its ownnership when extracting the archive (see
  200. ;; below), and also because this would lead to adding the
  201. ;; same entries twice in the tarball.
  202. `(,@(if (string=? parent "/")
  203. '()
  204. `((directory ,parent)))
  205. (,source
  206. -> ,(relative-file-name parent target)))))))
  207. (define directives
  208. ;; Fully-qualified symlinks.
  209. (append-map symlink->directives '#$symlinks))
  210. ;; The --sort option was added to GNU tar in version 1.28, released
  211. ;; 2014-07-28. For testing, we use the bootstrap tar, which is
  212. ;; older and doesn't support it.
  213. (define tar-supports-sort?
  214. (zero? (system* (string-append #+archiver "/bin/tar")
  215. "cf" "/dev/null" "--files-from=/dev/null"
  216. "--sort=name")))
  217. ;; Make sure non-ASCII file names are properly handled.
  218. #+set-utf8-locale
  219. ;; Add 'tar' to the search path.
  220. (setenv "PATH" #+(file-append archiver "/bin"))
  221. ;; Note: there is not much to gain here with deduplication and there
  222. ;; is the overhead of the '.links' directory, so turn it off.
  223. ;; Furthermore GNU tar < 1.30 sometimes fails to extract tarballs
  224. ;; with hard links:
  225. ;; <http://lists.gnu.org/archive/html/bug-tar/2017-11/msg00009.html>.
  226. (populate-single-profile-directory %root
  227. #:profile #$profile
  228. #:profile-name #$profile-name
  229. #:closure "profile"
  230. #:database #+database)
  231. ;; Create SYMLINKS.
  232. (for-each (cut evaluate-populate-directive <> %root)
  233. directives)
  234. ;; Create the tarball. Use GNU format so there's no file name
  235. ;; length limitation.
  236. (with-directory-excursion %root
  237. (exit
  238. (zero? (apply system* "tar"
  239. #+@(if (compressor-command compressor)
  240. #~("-I"
  241. (string-join
  242. '#+(compressor-command compressor)))
  243. #~())
  244. "--format=gnu"
  245. ;; Avoid non-determinism in the archive. Use
  246. ;; mtime = 1, not zero, because that is what the
  247. ;; daemon does for files in the store (see the
  248. ;; 'mtimeStore' constant in local-store.cc.)
  249. (if tar-supports-sort? "--sort=name" "--mtime=@1")
  250. "--mtime=@1" ;for files in /var/guix
  251. "--owner=root:0"
  252. "--group=root:0"
  253. "--check-links"
  254. "-cvf" #$output
  255. ;; Avoid adding / and /var to the tarball, so
  256. ;; that the ownership and permissions of those
  257. ;; directories will not be overwritten when
  258. ;; extracting the archive. Do not include /root
  259. ;; because the root account might have a
  260. ;; different home directory.
  261. #$@(if localstatedir?
  262. '("./var/guix")
  263. '())
  264. (string-append "." (%store-directory))
  265. (delete-duplicates
  266. (filter-map (match-lambda
  267. (('directory directory)
  268. (string-append "." directory))
  269. ((source '-> _)
  270. (string-append "." source))
  271. (_ #f))
  272. directives)))))))))
  273. (when entry-point
  274. (warning (G_ "entry point not supported in the '~a' format~%")
  275. 'tarball))
  276. (gexp->derivation (string-append name ".tar"
  277. (compressor-extension compressor))
  278. build
  279. #:target target
  280. #:references-graphs `(("profile" ,profile))))
  281. (define (singularity-environment-file profile)
  282. "Return a shell script that defines the environment variables corresponding
  283. to the search paths of PROFILE."
  284. (define build
  285. (with-extensions (list guile-gcrypt)
  286. (with-imported-modules `(((guix config) => ,(make-config.scm))
  287. ,@(source-module-closure
  288. `((guix profiles)
  289. (guix search-paths))
  290. #:select? not-config?))
  291. #~(begin
  292. (use-modules (guix profiles) (guix search-paths)
  293. (ice-9 match))
  294. (call-with-output-file #$output
  295. (lambda (port)
  296. (for-each (match-lambda
  297. ((spec . value)
  298. (format port "~a=~a~%export ~a~%"
  299. (search-path-specification-variable spec)
  300. value
  301. (search-path-specification-variable spec))))
  302. (profile-search-paths #$profile))))))))
  303. (computed-file "singularity-environment.sh" build))
  304. (define* (squashfs-image name profile
  305. #:key target
  306. (profile-name "guix-profile")
  307. (compressor (first %compressors))
  308. entry-point
  309. localstatedir?
  310. (symlinks '())
  311. (archiver squashfs-tools))
  312. "Return a squashfs image containing a store initialized with the closure of
  313. PROFILE, a derivation. The image contains a subset of /gnu/store, empty mount
  314. points for virtual file systems (like procfs), and optional symlinks.
  315. SYMLINKS must be a list of (SOURCE -> TARGET) tuples denoting symlinks to be
  316. added to the pack."
  317. (define database
  318. (and localstatedir?
  319. (file-append (store-database (list profile))
  320. "/db/db.sqlite")))
  321. (define environment
  322. (singularity-environment-file profile))
  323. (define symlinks*
  324. ;; Singularity requires /bin (specifically /bin/sh), so ensure that
  325. ;; symlink is created.
  326. (if (find (match-lambda
  327. (("/bin" . _) #t)
  328. (_ #f))
  329. symlinks)
  330. symlinks
  331. `(("/bin" -> "bin") ,@symlinks)))
  332. (define build
  333. (with-imported-modules (source-module-closure
  334. '((guix build utils)
  335. (guix build store-copy)
  336. (guix build union)
  337. (gnu build install))
  338. #:select? not-config?)
  339. #~(begin
  340. (use-modules (guix build utils)
  341. (guix build store-copy)
  342. ((guix build union) #:select (relative-file-name))
  343. (gnu build install)
  344. (srfi srfi-1)
  345. (srfi srfi-26)
  346. (ice-9 match))
  347. (define database #+database)
  348. (define entry-point #$entry-point)
  349. (define (mksquashfs args)
  350. (apply invoke "mksquashfs"
  351. `(,@args
  352. ;; Do not create a "recovery file" when appending to the
  353. ;; file system since it's useless in this case.
  354. "-no-recovery"
  355. ;; Do not attempt to store extended attributes.
  356. ;; See <https://bugs.gnu.org/40043>.
  357. "-no-xattrs"
  358. ;; Set file times and the file system creation time to
  359. ;; one second after the Epoch.
  360. "-all-time" "1" "-mkfs-time" "1"
  361. ;; Reset all UIDs and GIDs.
  362. "-force-uid" "0" "-force-gid" "0")))
  363. (setenv "PATH" #+(file-append archiver "/bin"))
  364. ;; We need an empty file in order to have a valid file argument when
  365. ;; we reparent the root file system. Read on for why that's
  366. ;; necessary.
  367. (with-output-to-file ".empty" (lambda () (display "")))
  368. ;; Create the squashfs image in several steps.
  369. ;; Add all store items. Unfortunately mksquashfs throws away all
  370. ;; ancestor directories and only keeps the basename. We fix this
  371. ;; in the following invocations of mksquashfs.
  372. (mksquashfs `(,@(map store-info-item
  373. (call-with-input-file "profile"
  374. read-reference-graph))
  375. #$environment
  376. ,#$output
  377. ;; Do not perform duplicate checking because we
  378. ;; don't have any dupes.
  379. "-no-duplicates"
  380. "-comp"
  381. ,#+(compressor-name compressor)))
  382. ;; Here we reparent the store items. For each sub-directory of
  383. ;; the store prefix we need one invocation of "mksquashfs".
  384. (for-each (lambda (dir)
  385. (mksquashfs `(".empty"
  386. ,#$output
  387. "-root-becomes" ,dir)))
  388. (reverse (string-tokenize (%store-directory)
  389. (char-set-complement (char-set #\/)))))
  390. ;; Add symlinks and mount points.
  391. (mksquashfs
  392. `(".empty"
  393. ,#$output
  394. ;; Create SYMLINKS via pseudo file definitions.
  395. ,@(append-map
  396. (match-lambda
  397. ((source '-> target)
  398. ;; Create relative symlinks to work around a bug in
  399. ;; Singularity 2.x:
  400. ;; https://bugs.gnu.org/34913
  401. ;; https://github.com/sylabs/singularity/issues/1487
  402. (let ((target (string-append #$profile "/" target)))
  403. (list "-p"
  404. (string-join
  405. ;; name s mode uid gid symlink
  406. (list source
  407. "s" "777" "0" "0"
  408. (relative-file-name (dirname source)
  409. target)))))))
  410. '#$symlinks*)
  411. "-p" "/.singularity.d d 555 0 0"
  412. ;; Create the environment file.
  413. "-p" "/.singularity.d/env d 555 0 0"
  414. "-p" ,(string-append
  415. "/.singularity.d/env/90-environment.sh s 777 0 0 "
  416. (relative-file-name "/.singularity.d/env"
  417. #$environment))
  418. ;; Create /.singularity.d/actions, and optionally the 'run'
  419. ;; script, used by 'singularity run'.
  420. "-p" "/.singularity.d/actions d 555 0 0"
  421. ,@(if entry-point
  422. `(;; This one if for Singularity 2.x.
  423. "-p"
  424. ,(string-append
  425. "/.singularity.d/actions/run s 777 0 0 "
  426. (relative-file-name "/.singularity.d/actions"
  427. (string-append #$profile "/"
  428. entry-point)))
  429. ;; This one is for Singularity 3.x.
  430. "-p"
  431. ,(string-append
  432. "/.singularity.d/runscript s 777 0 0 "
  433. (relative-file-name "/.singularity.d"
  434. (string-append #$profile "/"
  435. entry-point))))
  436. '())
  437. ;; Create empty mount points.
  438. "-p" "/proc d 555 0 0"
  439. "-p" "/sys d 555 0 0"
  440. "-p" "/dev d 555 0 0"
  441. "-p" "/home d 555 0 0"))
  442. (when database
  443. ;; Initialize /var/guix.
  444. (install-database-and-gc-roots "var-etc" database #$profile)
  445. (mksquashfs `("var-etc" ,#$output))))))
  446. (gexp->derivation (string-append name
  447. (compressor-extension compressor)
  448. ".squashfs")
  449. build
  450. #:target target
  451. #:references-graphs `(("profile" ,profile))))
  452. (define* (docker-image name profile
  453. #:key target
  454. (profile-name "guix-profile")
  455. (compressor (first %compressors))
  456. entry-point
  457. localstatedir?
  458. (symlinks '())
  459. (archiver tar))
  460. "Return a derivation to construct a Docker image of PROFILE. The
  461. image is a tarball conforming to the Docker Image Specification, compressed
  462. with COMPRESSOR. It can be passed to 'docker load'. If TARGET is true, it
  463. must a be a GNU triplet and it is used to derive the architecture metadata in
  464. the image."
  465. (define database
  466. (and localstatedir?
  467. (file-append (store-database (list profile))
  468. "/db/db.sqlite")))
  469. (define defmod 'define-module) ;trick Geiser
  470. (define build
  471. ;; Guile-JSON and Guile-Gcrypt are required by (guix docker).
  472. (with-extensions (list guile-json-3 guile-gcrypt)
  473. (with-imported-modules `(((guix config) => ,(make-config.scm))
  474. ,@(source-module-closure
  475. `((guix docker)
  476. (guix build store-copy)
  477. (guix profiles)
  478. (guix search-paths))
  479. #:select? not-config?))
  480. #~(begin
  481. (use-modules (guix docker) (guix build store-copy)
  482. (guix profiles) (guix search-paths)
  483. (srfi srfi-1) (srfi srfi-19)
  484. (ice-9 match))
  485. (define environment
  486. (map (match-lambda
  487. ((spec . value)
  488. (cons (search-path-specification-variable spec)
  489. value)))
  490. (profile-search-paths #$profile)))
  491. (define symlink->directives
  492. ;; Return "populate directives" to make the given symlink and its
  493. ;; parent directories.
  494. (match-lambda
  495. ((source '-> target)
  496. (let ((target (string-append #$profile "/" target))
  497. (parent (dirname source)))
  498. `((directory ,parent)
  499. (,source -> ,target))))))
  500. (define directives
  501. ;; Create a /tmp directory, as some programs expect it, and
  502. ;; create SYMLINKS.
  503. `((directory "/tmp" ,(getuid) ,(getgid) #o1777)
  504. ,@(append-map symlink->directives '#$symlinks)))
  505. (define tag
  506. ;; Compute a meaningful "repository" name, which will show up in
  507. ;; the output of "docker images".
  508. (let ((manifest (profile-manifest #$profile)))
  509. (let loop ((names (map manifest-entry-name
  510. (manifest-entries manifest))))
  511. (define str (string-join names "-"))
  512. (if (< (string-length str) 40)
  513. str
  514. (match names
  515. ((_) str)
  516. ((names ... _) (loop names))))))) ;drop one entry
  517. (setenv "PATH" #+(file-append archiver "/bin"))
  518. (build-docker-image #$output
  519. (map store-info-item
  520. (call-with-input-file "profile"
  521. read-reference-graph))
  522. #$profile
  523. #:repository tag
  524. #:database #+database
  525. #:system (or #$target (utsname:machine (uname)))
  526. #:environment environment
  527. #:entry-point
  528. #$(and entry-point
  529. #~(list (string-append #$profile "/"
  530. #$entry-point)))
  531. #:extra-files directives
  532. #:compressor '#+(compressor-command compressor)
  533. #:creation-time (make-time time-utc 0 1))))))
  534. (gexp->derivation (string-append name ".tar"
  535. (compressor-extension compressor))
  536. build
  537. #:target target
  538. #:references-graphs `(("profile" ,profile))))
  539. ;;;
  540. ;;; Compiling C programs.
  541. ;;;
  542. ;; A C compiler. That lowers to a single program that can be passed typical C
  543. ;; compiler flags, and it makes sure the whole toolchain is available.
  544. (define-record-type <c-compiler>
  545. (%c-compiler toolchain guile)
  546. c-compiler?
  547. (toolchain c-compiler-toolchain)
  548. (guile c-compiler-guile))
  549. (define* (c-compiler #:optional inputs
  550. #:key (guile (default-guile)))
  551. (%c-compiler inputs guile))
  552. (define (bootstrap-c-compiler)
  553. "Return the C compiler that uses the bootstrap toolchain. This is used only
  554. by '--bootstrap', for testing purposes."
  555. (define bootstrap-toolchain
  556. (list (first (assoc-ref (%bootstrap-inputs) "gcc"))
  557. (first (assoc-ref (%bootstrap-inputs) "binutils"))
  558. (first (assoc-ref (%bootstrap-inputs) "libc"))))
  559. (c-compiler bootstrap-toolchain
  560. #:guile %bootstrap-guile))
  561. (define-gexp-compiler (c-compiler-compiler (compiler <c-compiler>) system target)
  562. "Lower COMPILER to a single script that does the right thing."
  563. (define toolchain
  564. (or (c-compiler-toolchain compiler)
  565. (list (first (assoc-ref (standard-packages) "gcc"))
  566. (first (assoc-ref (standard-packages) "ld-wrapper"))
  567. (first (assoc-ref (standard-packages) "binutils"))
  568. (first (assoc-ref (standard-packages) "libc"))
  569. (gexp-input (first (assoc-ref (standard-packages) "libc"))
  570. "static"))))
  571. (define inputs
  572. (match (append-map package-propagated-inputs
  573. (filter package? toolchain))
  574. (((labels things . _) ...)
  575. (append toolchain things))))
  576. (define search-paths
  577. (cons $PATH
  578. (append-map package-native-search-paths
  579. (filter package? inputs))))
  580. (define run
  581. (with-imported-modules (source-module-closure
  582. '((guix build utils)
  583. (guix search-paths)))
  584. #~(begin
  585. (use-modules (guix build utils) (guix search-paths)
  586. (ice-9 match))
  587. (define (output-file args)
  588. (let loop ((args args))
  589. (match args
  590. (() "a.out")
  591. (("-o" file _ ...) file)
  592. ((head rest ...) (loop rest)))))
  593. (set-search-paths (map sexp->search-path-specification
  594. '#$(map search-path-specification->sexp
  595. search-paths))
  596. '#$inputs)
  597. (let ((output (output-file (command-line))))
  598. (apply invoke "gcc" (cdr (command-line)))
  599. (invoke "strip" output)))))
  600. (when target
  601. ;; TODO: Yep, we'll have to do it someday!
  602. (leave (G_ "cross-compilation not implemented here;
  603. please email '~a'~%")
  604. (@ (guix config) %guix-bug-report-address)))
  605. (gexp->script "c-compiler" run
  606. #:guile (c-compiler-guile compiler)))
  607. ;;;
  608. ;;; Wrapped package.
  609. ;;;
  610. (define* (wrapped-package package
  611. #:optional
  612. (output* "out")
  613. (compiler (c-compiler))
  614. #:key proot?)
  615. "Return the OUTPUT of PACKAGE with its binaries wrapped such that they are
  616. relocatable. When PROOT? is true, include PRoot in the result and use it as a
  617. last resort for relocation."
  618. (define runner
  619. (local-file (search-auxiliary-file "run-in-namespace.c")))
  620. (define audit-source
  621. (local-file (search-auxiliary-file "pack-audit.c")))
  622. (define (proot)
  623. (specification->package "proot-static"))
  624. (define (fakechroot-library)
  625. (computed-file "libfakechroot.so"
  626. #~(copy-file #$(file-append
  627. (specification->package "fakechroot")
  628. "/lib/fakechroot/libfakechroot.so")
  629. #$output)))
  630. (define (audit-module)
  631. ;; Return an ld.so audit module for use by the 'fakechroot' execution
  632. ;; engine that translates file names of all the files ld.so loads.
  633. (computed-file "pack-audit.so"
  634. (with-imported-modules '((guix build utils))
  635. #~(begin
  636. (use-modules (guix build utils))
  637. (copy-file #$audit-source "audit.c")
  638. (substitute* "audit.c"
  639. (("@STORE_DIRECTORY@")
  640. (%store-directory)))
  641. (invoke #$compiler "-std=gnu99"
  642. "-shared" "-fPIC" "-Os" "-g0"
  643. "-Wall" "audit.c" "-o" #$output)))))
  644. (define build
  645. (with-imported-modules (source-module-closure
  646. '((guix build utils)
  647. (guix build union)
  648. (guix build gremlin)
  649. (guix elf)))
  650. #~(begin
  651. (use-modules (guix build utils)
  652. ((guix build union) #:select (relative-file-name))
  653. (guix elf)
  654. (guix build gremlin)
  655. (ice-9 binary-ports)
  656. (ice-9 ftw)
  657. (ice-9 match)
  658. (srfi srfi-1)
  659. (rnrs bytevectors))
  660. (define input
  661. ;; The OUTPUT* output of PACKAGE.
  662. (ungexp package output*))
  663. (define target
  664. ;; The output we are producing.
  665. (ungexp output output*))
  666. (define (strip-store-prefix file)
  667. ;; Given a file name like "/gnu/store/…-foo-1.2/bin/foo", return
  668. ;; "/bin/foo".
  669. (let* ((len (string-length (%store-directory)))
  670. (base (string-drop file (+ 1 len))))
  671. (match (string-index base #\/)
  672. (#f base)
  673. (index (string-drop base index)))))
  674. (define (elf-interpreter elf)
  675. ;; Return the interpreter of ELF as a string, or #f if ELF has no
  676. ;; interpreter segment.
  677. (match (find (lambda (segment)
  678. (= (elf-segment-type segment) PT_INTERP))
  679. (elf-segments elf))
  680. (#f #f) ;maybe a .so
  681. (segment
  682. (let ((bv (make-bytevector (- (elf-segment-memsz segment) 1))))
  683. (bytevector-copy! (elf-bytes elf)
  684. (elf-segment-offset segment)
  685. bv 0 (bytevector-length bv))
  686. (utf8->string bv)))))
  687. (define (runpath file)
  688. ;; Return the RUNPATH of FILE as a list of directories.
  689. (let* ((bv (call-with-input-file file get-bytevector-all))
  690. (elf (parse-elf bv))
  691. (dyninfo (elf-dynamic-info elf)))
  692. (or (and=> dyninfo elf-dynamic-info-runpath)
  693. '())))
  694. (define (elf-loader-compile-flags program)
  695. ;; Return the cpp flags defining macros for the ld.so/fakechroot
  696. ;; wrapper of PROGRAM.
  697. ;; TODO: Handle scripts by wrapping their interpreter.
  698. (if (elf-file? program)
  699. (let* ((bv (call-with-input-file program
  700. get-bytevector-all))
  701. (elf (parse-elf bv))
  702. (interp (elf-interpreter elf))
  703. (gconv (and interp
  704. (string-append (dirname interp)
  705. "/gconv"))))
  706. (if interp
  707. (list (string-append "-DPROGRAM_INTERPRETER=\""
  708. interp "\"")
  709. (string-append "-DFAKECHROOT_LIBRARY=\""
  710. #$(fakechroot-library) "\"")
  711. (string-append "-DLOADER_AUDIT_MODULE=\""
  712. #$(audit-module) "\"")
  713. ;; XXX: Normally (runpath #$(audit-module)) is
  714. ;; enough. However, to work around
  715. ;; <https://sourceware.org/bugzilla/show_bug.cgi?id=26634>
  716. ;; (glibc <= 2.32), pass the whole search path of
  717. ;; PROGRAM, which presumably is a superset of that
  718. ;; of the audit module.
  719. (string-append "-DLOADER_AUDIT_RUNPATH={ "
  720. (string-join
  721. (map object->string
  722. (runpath program))
  723. ", " 'suffix)
  724. "NULL }")
  725. (if gconv
  726. (string-append "-DGCONV_DIRECTORY=\""
  727. gconv "\"")
  728. "-UGCONV_DIRECTORY"))
  729. '()))
  730. '()))
  731. (define (build-wrapper program)
  732. ;; Build a user-namespace wrapper for PROGRAM.
  733. (format #t "building wrapper for '~a'...~%" program)
  734. (copy-file #$runner "run.c")
  735. (substitute* "run.c"
  736. (("@WRAPPED_PROGRAM@") program)
  737. (("@STORE_DIRECTORY@") (%store-directory)))
  738. (let* ((base (strip-store-prefix program))
  739. (result (string-append target "/" base))
  740. (proot #$(and proot?
  741. #~(string-drop
  742. #$(file-append (proot) "/bin/proot")
  743. (+ (string-length (%store-directory))
  744. 1)))))
  745. (mkdir-p (dirname result))
  746. (apply invoke #$compiler "-std=gnu99" "-static" "-Os" "-g0" "-Wall"
  747. "run.c" "-o" result
  748. (append (if proot
  749. (list (string-append "-DPROOT_PROGRAM=\""
  750. proot "\""))
  751. '())
  752. (elf-loader-compile-flags program)))
  753. (delete-file "run.c")))
  754. (setvbuf (current-output-port) 'line)
  755. ;; Link the top-level files of PACKAGE so that search paths are
  756. ;; properly defined in PROFILE/etc/profile.
  757. (mkdir target)
  758. (for-each (lambda (file)
  759. (unless (member file '("." ".." "bin" "sbin" "libexec"))
  760. (let ((file* (string-append input "/" file)))
  761. (symlink (relative-file-name target file*)
  762. (string-append target "/" file)))))
  763. (scandir input))
  764. (for-each build-wrapper
  765. ;; Note: Trailing slash in case these are symlinks.
  766. (append (find-files (string-append input "/bin/"))
  767. (find-files (string-append input "/sbin/"))
  768. (find-files (string-append input "/libexec/")))))))
  769. (computed-file (string-append
  770. (cond ((package? package)
  771. (package-full-name package "-"))
  772. ((inferior-package? package)
  773. (string-append (inferior-package-name package)
  774. "-"
  775. (inferior-package-version package)))
  776. (else "wrapper"))
  777. "R")
  778. build))
  779. (define (wrapped-manifest-entry entry . args)
  780. (manifest-entry
  781. (inherit entry)
  782. (item (apply wrapped-package
  783. (manifest-entry-item entry)
  784. (manifest-entry-output entry)
  785. args))
  786. (dependencies (map (lambda (entry)
  787. (apply wrapped-manifest-entry entry args))
  788. (manifest-entry-dependencies entry)))))
  789. ;;;
  790. ;;; Command-line options.
  791. ;;;
  792. (define %default-options
  793. ;; Alist of default option values.
  794. `((format . tarball)
  795. (profile-name . "guix-profile")
  796. (system . ,(%current-system))
  797. (substitutes? . #t)
  798. (offload? . #t)
  799. (graft? . #t)
  800. (print-build-trace? . #t)
  801. (print-extended-build-trace? . #t)
  802. (multiplexed-build-output? . #t)
  803. (debug . 0)
  804. (verbosity . 1)
  805. (symlinks . ())
  806. (compressor . ,(first %compressors))))
  807. (define %formats
  808. ;; Supported pack formats.
  809. `((tarball . ,self-contained-tarball)
  810. (squashfs . ,squashfs-image)
  811. (docker . ,docker-image)))
  812. (define (show-formats)
  813. ;; Print the supported pack formats.
  814. (display (G_ "The supported formats for 'guix pack' are:"))
  815. (newline)
  816. (display (G_ "
  817. tarball Self-contained tarball, ready to run on another machine"))
  818. (display (G_ "
  819. squashfs Squashfs image suitable for Singularity"))
  820. (display (G_ "
  821. docker Tarball ready for 'docker load'"))
  822. (newline))
  823. (define %options
  824. ;; Specifications of the command-line options.
  825. (cons* (option '(#\h "help") #f #f
  826. (lambda args
  827. (show-help)
  828. (exit 0)))
  829. (option '(#\V "version") #f #f
  830. (lambda args
  831. (show-version-and-exit "guix pack")))
  832. (option '(#\n "dry-run") #f #f
  833. (lambda (opt name arg result)
  834. (alist-cons 'dry-run? #t result)))
  835. (option '(#\d "derivation") #f #f
  836. (lambda (opt name arg result)
  837. (alist-cons 'derivation-only? #t result)))
  838. (option '(#\f "format") #t #f
  839. (lambda (opt name arg result)
  840. (alist-cons 'format (string->symbol arg) result)))
  841. (option '("list-formats") #f #f
  842. (lambda args
  843. (show-formats)
  844. (exit 0)))
  845. (option '(#\R "relocatable") #f #f
  846. (lambda (opt name arg result)
  847. (match (assq-ref result 'relocatable?)
  848. (#f
  849. (alist-cons 'relocatable? #t result))
  850. (_
  851. (alist-cons 'relocatable? 'proot
  852. (alist-delete 'relocatable? result))))))
  853. (option '(#\e "expression") #t #f
  854. (lambda (opt name arg result)
  855. (alist-cons 'expression arg result)))
  856. (option '(#\m "manifest") #t #f
  857. (lambda (opt name arg result)
  858. (alist-cons 'manifest arg result)))
  859. (option '(#\s "system") #t #f
  860. (lambda (opt name arg result)
  861. (alist-cons 'system arg
  862. (alist-delete 'system result eq?))))
  863. (option '("entry-point") #t #f
  864. (lambda (opt name arg result)
  865. (alist-cons 'entry-point arg result)))
  866. (option '("target") #t #f
  867. (lambda (opt name arg result)
  868. (alist-cons 'target arg
  869. (alist-delete 'target result eq?))))
  870. (option '(#\C "compression") #t #f
  871. (lambda (opt name arg result)
  872. (alist-cons 'compressor (lookup-compressor arg)
  873. result)))
  874. (option '(#\S "symlink") #t #f
  875. (lambda (opt name arg result)
  876. ;; Note: Using 'string-split' allows us to handle empty
  877. ;; TARGET (as in "/opt/guile=", meaning that /opt/guile is
  878. ;; a symlink to the profile) correctly.
  879. (match (string-split arg (char-set #\=))
  880. ((source target)
  881. (let ((symlinks (assoc-ref result 'symlinks)))
  882. (alist-cons 'symlinks
  883. `((,source -> ,target) ,@symlinks)
  884. (alist-delete 'symlinks result eq?))))
  885. (x
  886. (leave (G_ "~a: invalid symlink specification~%")
  887. arg)))))
  888. (option '("save-provenance") #f #f
  889. (lambda (opt name arg result)
  890. (alist-cons 'save-provenance? #t result)))
  891. (option '("localstatedir") #f #f
  892. (lambda (opt name arg result)
  893. (alist-cons 'localstatedir? #t result)))
  894. (option '("profile-name") #t #f
  895. (lambda (opt name arg result)
  896. (match arg
  897. ((or "guix-profile" "current-guix")
  898. (alist-cons 'profile-name arg result))
  899. (_
  900. (leave (G_ "~a: unsupported profile name~%") arg)))))
  901. (option '(#\r "root") #t #f
  902. (lambda (opt name arg result)
  903. (alist-cons 'gc-root arg result)))
  904. (option '(#\v "verbosity") #t #f
  905. (lambda (opt name arg result)
  906. (let ((level (string->number* arg)))
  907. (alist-cons 'verbosity level
  908. (alist-delete 'verbosity result)))))
  909. (option '("bootstrap") #f #f
  910. (lambda (opt name arg result)
  911. (alist-cons 'bootstrap? #t result)))
  912. (append %transformation-options
  913. %standard-build-options)))
  914. (define (show-help)
  915. (display (G_ "Usage: guix pack [OPTION]... PACKAGE...
  916. Create a bundle of PACKAGE.\n"))
  917. (show-build-options-help)
  918. (newline)
  919. (show-transformation-options-help)
  920. (newline)
  921. (display (G_ "
  922. -f, --format=FORMAT build a pack in the given FORMAT"))
  923. (display (G_ "
  924. --list-formats list the formats available"))
  925. (display (G_ "
  926. -R, --relocatable produce relocatable executables"))
  927. (display (G_ "
  928. -e, --expression=EXPR consider the package EXPR evaluates to"))
  929. (display (G_ "
  930. -s, --system=SYSTEM attempt to build for SYSTEM--e.g., \"i686-linux\""))
  931. (display (G_ "
  932. --target=TRIPLET cross-build for TRIPLET--e.g., \"armel-linux-gnu\""))
  933. (display (G_ "
  934. -C, --compression=TOOL compress using TOOL--e.g., \"lzip\""))
  935. (display (G_ "
  936. -S, --symlink=SPEC create symlinks to the profile according to SPEC"))
  937. (display (G_ "
  938. -m, --manifest=FILE create a pack with the manifest from FILE"))
  939. (display (G_ "
  940. --entry-point=PROGRAM
  941. use PROGRAM as the entry point of the pack"))
  942. (display (G_ "
  943. --save-provenance save provenance information"))
  944. (display (G_ "
  945. --localstatedir include /var/guix in the resulting pack"))
  946. (display (G_ "
  947. --profile-name=NAME
  948. populate /var/guix/profiles/.../NAME"))
  949. (display (G_ "
  950. -r, --root=FILE make FILE a symlink to the result, and register it
  951. as a garbage collector root"))
  952. (display (G_ "
  953. -d, --derivation return the derivation of the pack"))
  954. (display (G_ "
  955. -v, --verbosity=LEVEL use the given verbosity LEVEL"))
  956. (display (G_ "
  957. --bootstrap use the bootstrap binaries to build the pack"))
  958. (newline)
  959. (display (G_ "
  960. -h, --help display this help and exit"))
  961. (display (G_ "
  962. -V, --version display version information and exit"))
  963. (newline)
  964. (show-bug-report-information))
  965. ;;;
  966. ;;; Entry point.
  967. ;;;
  968. (define-command (guix-pack . args)
  969. (category development)
  970. (synopsis "create application bundles")
  971. (define opts
  972. (parse-command-line args %options (list %default-options)))
  973. (define maybe-package-argument
  974. ;; Given an option pair, return a package, a package/output tuple, or #f.
  975. (match-lambda
  976. (('argument . spec)
  977. (call-with-values
  978. (lambda ()
  979. (specification->package+output spec))
  980. list))
  981. (('expression . exp)
  982. (read/eval-package-expression exp))
  983. (x #f)))
  984. (define (manifest-from-args store opts)
  985. (let* ((transform (options->transformation opts))
  986. (packages (map (match-lambda
  987. (((? package? package) output)
  988. (list (transform store package) output))
  989. ((? package? package)
  990. (list (transform store package) "out")))
  991. (reverse
  992. (filter-map maybe-package-argument opts))))
  993. (manifests (filter-map (match-lambda
  994. (('manifest . file) file)
  995. (_ #f))
  996. opts)))
  997. (define with-provenance
  998. (if (assoc-ref opts 'save-provenance?)
  999. (lambda (manifest)
  1000. (map-manifest-entries
  1001. (lambda (entry)
  1002. (let ((entry (manifest-entry-with-provenance entry)))
  1003. (unless (assq 'provenance (manifest-entry-properties entry))
  1004. (warning (G_ "could not determine provenance of package ~a~%")
  1005. (manifest-entry-name entry)))
  1006. entry))
  1007. manifest))
  1008. identity))
  1009. (define (with-transformations manifest)
  1010. (map-manifest-entries manifest-entry-with-transformations
  1011. manifest))
  1012. (with-provenance
  1013. (with-transformations
  1014. (cond
  1015. ((and (not (null? manifests)) (not (null? packages)))
  1016. (leave (G_ "both a manifest and a package list were given~%")))
  1017. ((not (null? manifests))
  1018. (concatenate-manifests
  1019. (map (lambda (file)
  1020. (let ((user-module (make-user-module
  1021. '((guix profiles) (gnu)))))
  1022. (load* file user-module)))
  1023. manifests)))
  1024. (else
  1025. (packages->manifest packages)))))))
  1026. (with-error-handling
  1027. (with-store store
  1028. (with-status-verbosity (assoc-ref opts 'verbosity)
  1029. ;; Set the build options before we do anything else.
  1030. (set-build-options-from-command-line store opts)
  1031. (with-build-handler (build-notifier #:dry-run?
  1032. (assoc-ref opts 'dry-run?)
  1033. #:verbosity
  1034. (assoc-ref opts 'verbosity)
  1035. #:use-substitutes?
  1036. (assoc-ref opts 'substitutes?))
  1037. (parameterize ((%graft? (assoc-ref opts 'graft?))
  1038. (%guile-for-build (package-derivation
  1039. store
  1040. (if (assoc-ref opts 'bootstrap?)
  1041. %bootstrap-guile
  1042. (default-guile))
  1043. (assoc-ref opts 'system)
  1044. #:graft? (assoc-ref opts 'graft?))))
  1045. (let* ((derivation? (assoc-ref opts 'derivation-only?))
  1046. (relocatable? (assoc-ref opts 'relocatable?))
  1047. (proot? (eq? relocatable? 'proot))
  1048. (manifest (let ((manifest (manifest-from-args store opts)))
  1049. ;; Note: We cannot honor '--bootstrap' here because
  1050. ;; 'glibc-bootstrap' lacks 'libc.a'.
  1051. (if relocatable?
  1052. (map-manifest-entries
  1053. (cut wrapped-manifest-entry <> #:proot? proot?)
  1054. manifest)
  1055. manifest)))
  1056. (pack-format (assoc-ref opts 'format))
  1057. (name (string-append (symbol->string pack-format)
  1058. "-pack"))
  1059. (target (assoc-ref opts 'target))
  1060. (bootstrap? (assoc-ref opts 'bootstrap?))
  1061. (compressor (if bootstrap?
  1062. bootstrap-xz
  1063. (assoc-ref opts 'compressor)))
  1064. (archiver (if (equal? pack-format 'squashfs)
  1065. squashfs-tools
  1066. (if bootstrap?
  1067. %bootstrap-coreutils&co
  1068. tar)))
  1069. (symlinks (assoc-ref opts 'symlinks))
  1070. (build-image (match (assq-ref %formats pack-format)
  1071. ((? procedure? proc) proc)
  1072. (#f
  1073. (leave (G_ "~a: unknown pack format~%")
  1074. pack-format))))
  1075. (localstatedir? (assoc-ref opts 'localstatedir?))
  1076. (entry-point (assoc-ref opts 'entry-point))
  1077. (profile-name (assoc-ref opts 'profile-name))
  1078. (gc-root (assoc-ref opts 'gc-root))
  1079. (profile (profile
  1080. (content manifest)
  1081. ;; Always produce relative symlinks for
  1082. ;; Singularity (see
  1083. ;; <https://bugs.gnu.org/34913>).
  1084. (relative-symlinks?
  1085. (or relocatable?
  1086. (eq? 'squashfs pack-format)))
  1087. (hooks (if bootstrap?
  1088. '()
  1089. %default-profile-hooks))
  1090. (locales? (not bootstrap?)))))
  1091. (define (lookup-package package)
  1092. (manifest-lookup manifest (manifest-pattern (name package))))
  1093. (when (null? (manifest-entries manifest))
  1094. (warning (G_ "no packages specified; building an empty pack~%")))
  1095. (when (and (eq? pack-format 'squashfs)
  1096. (not (any lookup-package '("bash" "bash-minimal"))))
  1097. (warning (G_ "Singularity requires you to provide a shell~%"))
  1098. (display-hint (G_ "Add @code{bash} or @code{bash-minimal} \
  1099. to your package list.")))
  1100. (run-with-store store
  1101. (mlet* %store-monad ((drv (build-image name profile
  1102. #:target
  1103. target
  1104. #:compressor
  1105. compressor
  1106. #:symlinks
  1107. symlinks
  1108. #:localstatedir?
  1109. localstatedir?
  1110. #:entry-point
  1111. entry-point
  1112. #:profile-name
  1113. profile-name
  1114. #:archiver
  1115. archiver)))
  1116. (mbegin %store-monad
  1117. (mwhen derivation?
  1118. (return (format #t "~a~%"
  1119. (derivation-file-name drv))))
  1120. (munless derivation?
  1121. (built-derivations (list drv))
  1122. (mwhen gc-root
  1123. (register-root* (match (derivation->output-paths drv)
  1124. (((names . items) ...)
  1125. items))
  1126. gc-root))
  1127. (return (format #t "~a~%"
  1128. (derivation->output-path drv))))))
  1129. #:target target
  1130. #:system (assoc-ref opts 'system)))))))))