Start computing channel instance derivations for multiple systems

These aren't stored yet, but this is a start.
This commit is contained in:
Christopher Baines 2020-02-09 21:03:05 +00:00
parent beab4babac
commit 13b0ebe561

View file

@ -714,64 +714,71 @@ WHERE job_id = $1"
(build-derivations store (list derivation)))) (build-derivations store (list derivation))))
(derivation->output-path derivation))) (derivation->output-path derivation)))
(define (channel->derivation-file-name store channel) (define (channel->derivation-file-names-by-system store channel)
(define use-container? (defined? (define use-container? (defined?
'open-inferior/container 'open-inferior/container
(resolve-module '(guix inferior)))) (resolve-module '(guix inferior))))
(define inferior-code (define (inferior-code channel-instance systems)
`(lambda (store) `(lambda (store)
(let ((instances (let* ((instances
(list (list
(channel-instance (channel-instance
(channel (name ',(channel-name channel)) (channel (name ',(channel-name channel))
(url ,(channel-url channel)) (url ,(channel-url channel))
(branch ,(channel-branch channel)) (branch ,(channel-branch channel))
(commit ,(channel-commit channel))) (commit ,(channel-commit channel)))
,(channel-instance-commit channel-instance) ,(channel-instance-commit channel-instance)
,(channel-instance-checkout channel-instance))))) ,(channel-instance-checkout channel-instance)))))
(run-with-store store (map
(mlet* %store-monad ((manifest (channel-instances->manifest (lambda (system)
instances)) (log-time
(derv (profile-derivation manifest))) (simple-format
(mbegin %store-monad #f "computing the derivation-file-name for ~A"
(return (derivation-file-name derv)))))))) system)
(lambda ()
(define (start-inferior-and-return-derivation-file-names) (with-store store
;; /etc is only missing if open-inferior/container has been used ((set-current-system system) store)
(when use-container? (let ((manifest
(inferior-eval (catch #t
'(begin (lambda ()
;; Create /etc/pass, as %known-shorthand-profiles in (guix ((channel-instances->manifest instances) store))
;; profiles) tries to read from this file. Because the environment (lambda (key . args)
;; is cleaned in build-self.scm, xdg-directory in (guix utils) (simple-format
;; falls back to accessing /etc/passwd. (current-error-port)
(mkdir "/etc") "error: while computing manifest entry derivation for ~A\n"
(call-with-output-file "/etc/passwd" system)
(lambda (port) (simple-format
(display "root:x:0:0::/root:/bin/bash" port)))) (current-error-port)
inferior)) "error ~A: ~A\n" key args)
#f))))
(let ((channel-instance `(,system
(first .
(latest-channel-instances store ((manifest-entry-item
(list channel))))) . ,(and manifest
(inferior-eval '(use-modules (guix channels) (derivation-file-name
(guix profiles)) (manifest-entry-item
inferior) (first
(inferior-eval '(define channel-instance (manifest-entries manifest))))))
(@@ (guix channels) channel-instance)) (profile
inferior) . ,(catch #t
(lambda ()
(let ((result (and manifest
(inferior-eval-with-store (derivation-file-name
inferior (run-with-store store
store (profile-derivation
inferior-code))) manifest
#:hooks %channel-profile-hooks)))))
(close-inferior inferior) (lambda (key . args)
(simple-format
result))) (current-error-port)
"error: while computing profile derivation for ~A\n"
system)
(simple-format
(current-error-port)
"error ~A: ~A\n" key args)
#f))))))))))
(list ,@systems)))))
(let ((inferior (let ((inferior
(if use-container? (if use-container?
@ -788,6 +795,49 @@ WHERE job_id = $1"
(open-inferior (guix-store-path store) (open-inferior (guix-store-path store)
#:error-port (real-error-port)))))) #:error-port (real-error-port))))))
(define (start-inferior-and-return-derivation-file-names)
;; /etc is only missing if open-inferior/container has been used
(when use-container?
(inferior-eval
'(begin
;; Create /etc/pass, as %known-shorthand-profiles in (guix
;; profiles) tries to read from this file. Because the environment
;; is cleaned in build-self.scm, xdg-directory in (guix utils)
;; falls back to accessing /etc/passwd.
(mkdir "/etc")
(call-with-output-file "/etc/passwd"
(lambda (port)
(display "root:x:0:0::/root:/bin/bash" port))))
inferior))
(let ((channel-instance
(first
(latest-channel-instances store
(list channel)))))
(inferior-eval '(use-modules (srfi srfi-1)
(guix channels)
(guix grafts)
(guix profiles))
inferior)
(inferior-eval '(when (defined? '%graft?) (%graft? #f))
inferior)
(inferior-eval '(define channel-instance
(@@ (guix channels) channel-instance))
inferior)
(let* ((systems
(inferior-eval '(@ (guix packages) %supported-systems)
inferior))
(result
(inferior-eval-with-store
inferior
store
(inferior-code channel-instance systems))))
(close-inferior inferior)
result)))
(catch (catch
#t #t
(lambda () (lambda ()
@ -797,14 +847,14 @@ WHERE job_id = $1"
(display (backtrace) (current-error-port)) (display (backtrace) (current-error-port))
(display "\n" (current-error-port)) (display "\n" (current-error-port))
(simple-format (current-error-port) (simple-format (current-error-port)
"error: channel->derivation-file-name: ~A: ~A\n" "error: channel->derivation-file-names-by-system: ~A: ~A\n"
key parameters)))) key parameters))))
(lambda args (lambda args
(close-inferior inferior) (close-inferior inferior)
#f)))) #f))))
(define (channel->manifest-store-item conn store channel) (define (channel->manifest-store-item conn store channel)
(let* ((manifest-store-item-derivation-file-name (let* ((derivation-file-names-by-system
(log-time (log-time
"computing the channel derivation" "computing the channel derivation"
(lambda () (lambda ()
@ -814,12 +864,20 @@ WHERE job_id = $1"
conn conn
'channel->manifest-store-item 'channel->manifest-store-item
(lambda () (lambda ()
(channel->derivation-file-name store channel)))))) (channel->derivation-file-names-by-system store channel))))))
(derivation (derivation
(read-derivation-from-file manifest-store-item-derivation-file-name))) (read-derivation-from-file (assoc-ref
(simple-format (current-error-port) (assoc-ref derivation-file-names-by-system
"debug: channel dervation: ~A\n" (%current-system))
manifest-store-item-derivation-file-name) 'profile))))
(for-each
(match-lambda
((system . derivation-file-name)
(simple-format (current-error-port)
"debug: ~A: channel dervation: ~A\n"
system
derivation-file-name)))
derivation-file-names-by-system)
(log-time (log-time
"building the channel derivation" "building the channel derivation"
(lambda () (lambda ()