summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2018-05-30 11:10:27 +0200
committerLudovic Courtès <ludo@gnu.org>2018-06-09 12:02:27 +0200
commit8a0d9bc8a3f153159d9e239a151c0fa98f1e12d8 (patch)
tree38c0ed21f58688c13caa869bd41765fe6bc4597f
parentd6fb0985a611a6549b45cc58461a8dc52c8b9f3e (diff)
self: Produce a complete package with the 'guix' command.
* guix/self.scm (guix-command): New procedure. (compiled-guix): Add #:pull-version parameter. [command, package]: New variables. Honor PULL-VERSION. (guix-derivation): Add #:pull-version and pass it to 'compiled-guix'. * build-aux/build-self.scm (build-program): Add #:pull-version parameter. Pass it to 'guix-derivation'. (build): Add #:pull-version and pass it to 'build-program'. * build-aux/compile-as-derivation.scm: Pass #:pull-version to BUILD.
-rw-r--r--build-aux/build-self.scm19
-rw-r--r--build-aux/compile-as-derivation.scm2
-rw-r--r--guix/self.scm153
3 files changed, 132 insertions, 42 deletions
diff --git a/build-aux/build-self.scm b/build-aux/build-self.scm
index bccb7a959e9..5898b6515cc 100644
--- a/build-aux/build-self.scm
+++ b/build-aux/build-self.scm
@@ -184,7 +184,8 @@ person's version identifier."
184 (date->string (current-date 0) "~Y~m~d.~H")) 184 (date->string (current-date 0) "~Y~m~d.~H"))
185 185
186(define* (build-program source version 186(define* (build-program source version
187 #:optional (guile-version (effective-version))) 187 #:optional (guile-version (effective-version))
188 #:key (pull-version 0))
188 "Return a program that computes the derivation to build Guix from SOURCE." 189 "Return a program that computes the derivation to build Guix from SOURCE."
189 (define select? 190 (define select?
190 ;; Select every module but (guix config) and non-Guix modules. 191 ;; Select every module but (guix config) and non-Guix modules.
@@ -253,11 +254,14 @@ person's version identifier."
253 (spin system))) 254 (spin system)))
254 255
255 (display 256 (display
256 (derivation-file-name 257 (and=>
257 (run-with-store store 258 (run-with-store store
258 (guix-derivation #$source #$version 259 (guix-derivation #$source #$version
259 #$guile-version) 260 #$guile-version
260 #:system system))))))) 261 #:pull-version
262 #$pull-version)
263 #:system system)
264 derivation-file-name))))))
261 #:module-path (list source)))) 265 #:module-path (list source))))
262 266
263;; The procedure below is our return value. 267;; The procedure below is our return value.
@@ -266,13 +270,15 @@ person's version identifier."
266 (guile-version (match ((@ (guile) version)) 270 (guile-version (match ((@ (guile) version))
267 ("2.2.2" "2.2.2") 271 ("2.2.2" "2.2.2")
268 (_ (effective-version)))) 272 (_ (effective-version))))
273 (pull-version 0)
269 #:allow-other-keys 274 #:allow-other-keys
270 #:rest rest) 275 #:rest rest)
271 "Return a derivation that unpacks SOURCE into STORE and compiles Scheme 276 "Return a derivation that unpacks SOURCE into STORE and compiles Scheme
272files." 277files."
273 ;; Build the build program and then use it as a trampoline to build from 278 ;; Build the build program and then use it as a trampoline to build from
274 ;; SOURCE. 279 ;; SOURCE.
275 (mlet %store-monad ((build (build-program source version guile-version)) 280 (mlet %store-monad ((build (build-program source version guile-version
281 #:pull-version pull-version))
276 (system (if system (return system) (current-system)))) 282 (system (if system (return system) (current-system))))
277 (mbegin %store-monad 283 (mbegin %store-monad
278 (show-what-to-build* (list build)) 284 (show-what-to-build* (list build))
@@ -292,6 +298,9 @@ files."
292 (return (newline (current-output-port))) 298 (return (newline (current-output-port)))
293 ((store-lift add-temp-root) drv) 299 ((store-lift add-temp-root) drv)
294 (return (read-derivation-from-file drv)))) 300 (return (read-derivation-from-file drv))))
301 ("#f"
302 ;; Unsupported PULL-VERSION.
303 (return #f))
295 ((? string? str) 304 ((? string? str)
296 (error "invalid build result" (list build str)))))))) 305 (error "invalid build result" (list build str))))))))
297 306
diff --git a/build-aux/compile-as-derivation.scm b/build-aux/compile-as-derivation.scm
index afb134a92a1..2a45e71bb9d 100644
--- a/build-aux/compile-as-derivation.scm
+++ b/build-aux/compile-as-derivation.scm
@@ -43,7 +43,7 @@
43 (mlet* %store-monad ((source (interned-file source "guix-source" 43 (mlet* %store-monad ((source (interned-file source "guix-source"
44 #:select? git? 44 #:select? git?
45 #:recursive? #t)) 45 #:recursive? #t))
46 (drv (build source))) 46 (drv (build source #:pull-version 1)))
47 (mbegin %store-monad 47 (mbegin %store-monad
48 (show-what-to-build* (list drv)) 48 (show-what-to-build* (list drv))
49 (built-derivations (list drv)) 49 (built-derivations (list drv))
diff --git a/guix/self.scm b/guix/self.scm
index 3acfac6f80b..28faeaab0c2 100644
--- a/guix/self.scm
+++ b/guix/self.scm
@@ -34,6 +34,7 @@
34 #:use-module (srfi srfi-9) 34 #:use-module (srfi srfi-9)
35 #:use-module (ice-9 match) 35 #:use-module (ice-9 match)
36 #:export (make-config.scm 36 #:export (make-config.scm
37 whole-package ;for internal use in 'guix pull'
37 compiled-guix 38 compiled-guix
38 guix-derivation 39 guix-derivation
39 reload-guix)) 40 reload-guix))
@@ -192,7 +193,66 @@ list of file-name/file-like objects suitable as inputs to 'imported-files'."
192 (file-name->module-name (string-drop file prefix))) 193 (file-name->module-name (string-drop file prefix)))
193 (scheme-files (string-append directory "/" sub-directory))))) 194 (scheme-files (string-append directory "/" sub-directory)))))
194 195
196(define* (guix-command modules #:key (dependencies '())
197 (guile-version (effective-version)))
198 "Return the 'guix' command such that it adds MODULES and DEPENDENCIES in its
199load path."
200 (program-file "guix-command"
201 #~(begin
202 (set! %load-path
203 (append '#$(map (lambda (package)
204 (file-append package
205 "/share/guile/site/"
206 guile-version))
207 dependencies)
208 %load-path))
209
210 (set! %load-compiled-path
211 (append '#$(map (lambda (package)
212 (file-append package "/lib/guile/"
213 guile-version
214 "/site-ccache"))
215 dependencies)
216 %load-compiled-path))
217
218 (set! %load-path (cons #$modules %load-path))
219 (set! %load-compiled-path
220 (cons #$modules %load-compiled-path))
221
222 (let ((guix-main (module-ref (resolve-interface '(guix ui))
223 'guix-main)))
224 ;; TODO: Compute locale data.
225 ;; (bindtextdomain "guix" "@localedir@")
226 ;; (bindtextdomain "guix-packages" "@localedir@")
227
228 ;; XXX: It would be more convenient to change it to:
229 ;; (exit (apply guix-main (command-line)))
230 (apply guix-main (command-line))))))
231
232(define* (whole-package name modules dependencies
233 #:key (guile-version (effective-version)))
234 "Return the whole Guix package NAME that uses MODULES, a derivation of all
235the modules, and DEPENDENCIES, a list of packages depended on."
236 (let ((command (guix-command modules
237 #:dependencies dependencies
238 #:guile-version guile-version)))
239 ;; TODO: Move compiled modules to 'lib/guile' instead of 'share/guile'.
240 (computed-file name
241 (with-imported-modules '((guix build utils))
242 #~(begin
243 (use-modules (guix build utils))
244 (mkdir-p (string-append #$output "/bin"))
245 (symlink #$command
246 (string-append #$output "/bin/guix"))
247
248 (let ((modules (string-append #$output
249 "/share/guile/site/"
250 (effective-version))))
251 (mkdir-p (dirname modules))
252 (symlink #$modules modules)))))))
253
195(define* (compiled-guix source #:key (version %guix-version) 254(define* (compiled-guix source #:key (version %guix-version)
255 (pull-version 1)
196 (name (string-append "guix-" version)) 256 (name (string-append "guix-" version))
197 (guile-version (effective-version)) 257 (guile-version (effective-version))
198 (guile-for-build (guile-for-build guile-version)) 258 (guile-for-build (guile-for-build guile-version))
@@ -351,32 +411,46 @@ list of file-name/file-like objects suitable as inputs to 'imported-files'."
351 %guix-home-page-url))) 411 %guix-home-page-url)))
352 #:guile-for-build guile-for-build)) 412 #:guile-for-build guile-for-build))
353 413
354 (directory-union name 414 (define built-modules
355 (append-map (lambda (node) 415 (directory-union (string-append name "-modules")
356 (list (node-source node) 416 (append-map (lambda (node)
357 (node-compiled node))) 417 (list (node-source node)
358 418 (node-compiled node)))
359 ;; Note: *CONFIG* comes first so that it 419
360 ;; overrides the (guix config) module that 420 ;; Note: *CONFIG* comes first so that it
361 ;; comes with *CORE-MODULES*. 421 ;; overrides the (guix config) module that
362 (list *config* 422 ;; comes with *CORE-MODULES*.
363 *cli-modules* 423 (list *config*
364 *system-modules* 424 *cli-modules*
365 *package-modules* 425 *system-modules*
366 *core-package-modules* 426 *package-modules*
367 *extra-modules* 427 *core-package-modules*
368 *core-modules*)) 428 *extra-modules*
369 429 *core-modules*))
370 ;; Silently choose the first entry upon collision so that 430
371 ;; we choose *CONFIG*. 431 ;; Silently choose the first entry upon collision so that
372 #:resolve-collision 'first 432 ;; we choose *CONFIG*.
373 433 #:resolve-collision 'first
374 ;; When we do (add-to-store "utils.scm"), "utils.scm" must 434
375 ;; be a regular file, not a symlink. Thus, arrange so that 435 ;; When we do (add-to-store "utils.scm"), "utils.scm" must
376 ;; regular files appear as regular files in the final 436 ;; be a regular file, not a symlink. Thus, arrange so that
377 ;; output. 437 ;; regular files appear as regular files in the final
378 #:copy? #t 438 ;; output.
379 #:quiet? #t)) 439 #:copy? #t
440 #:quiet? #t))
441
442 ;; Version 0 of 'guix pull' meant we'd just return Scheme modules.
443 ;; Version 1 is when we return the full package.
444 (cond ((= 1 pull-version)
445 ;; The whole package, with a standard file hierarchy.
446 (whole-package name built-modules dependencies
447 #:guile-version guile-version))
448 ((= 0 pull-version)
449 ;; Legacy 'guix pull': just return the compiled modules.
450 built-modules)
451 (else
452 ;; Unsupported 'guix pull' version.
453 #f)))
380 454
381 455
382;;; 456;;;
@@ -630,9 +704,12 @@ running Guile."
630 'guile-2.0)))) 704 'guile-2.0))))
631 705
632(define* (guix-derivation source version 706(define* (guix-derivation source version
633 #:optional (guile-version (effective-version))) 707 #:optional (guile-version (effective-version))
708 #:key (pull-version 0))
634 "Return, as a monadic value, the derivation to build the Guix from SOURCE 709 "Return, as a monadic value, the derivation to build the Guix from SOURCE
635for GUILE-VERSION. Use VERSION as the version string." 710for GUILE-VERSION. Use VERSION as the version string. PULL-VERSION specifies
711the version of the 'guix pull' protocol. Return #f if this PULL-VERSION value
712is not supported."
636 (define (shorten version) 713 (define (shorten version)
637 (if (and (string-every char-set:hex-digit version) 714 (if (and (string-every char-set:hex-digit version)
638 (> (string-length version) 9)) 715 (> (string-length version) 9))
@@ -644,11 +721,15 @@ for GUILE-VERSION. Use VERSION as the version string."
644 721
645 (mbegin %store-monad 722 (mbegin %store-monad
646 (set-guile-for-build guile) 723 (set-guile-for-build guile)
647 (lower-object (compiled-guix source 724 (let ((guix (compiled-guix source
648 #:version version 725 #:version version
649 #:name (string-append "guix-" 726 #:name (string-append "guix-"
650 (shorten version)) 727 (shorten version))
651 #:guile-version (match guile-version 728 #:pull-version pull-version
652 ("2.2.2" "2.2") 729 #:guile-version (match guile-version
653 (version version)) 730 ("2.2.2" "2.2")
654 #:guile-for-build guile)))) 731 (version version))
732 #:guile-for-build guile)))
733 (if guix
734 (lower-object guix)
735 (return #f)))))