Support setting environment variables in the inferior

When processing jobs, this is mostly to allow setting GUIX_DOWNLOAD_METHODS.
This commit is contained in:
Christopher Baines 2024-06-24 15:17:52 +01:00
parent d7103eccc9
commit 31bd2156f7
5 changed files with 73 additions and 12 deletions

View file

@ -127,6 +127,7 @@ guix-data-service: error: missing log line: ~A
(define* (process-jobs conn #:key max-processes (define* (process-jobs conn #:key max-processes
latest-branch-revision-max-processes latest-branch-revision-max-processes
skip-system-tests? skip-system-tests?
extra-inferior-environment-variables
per-job-parallelism) per-job-parallelism)
(define (fetch-new-jobs) (define (fetch-new-jobs)
(let ((free-space (free-disk-space "/gnu/store"))) (let ((free-space (free-disk-space "/gnu/store")))
@ -148,6 +149,11 @@ guix-data-service: error: missing log line: ~A
,@(if skip-system-tests? ,@(if skip-system-tests?
'("--skip-system-tests") '("--skip-system-tests")
'()) '())
,@(map (match-lambda
((key . val)
(simple-format #f "--inferior-set-environment-variable=~A=~A"
key val)))
extra-inferior-environment-variables)
,@(if per-job-parallelism ,@(if per-job-parallelism
(list (simple-format #f "--parallelism=~A" per-job-parallelism)) (list (simple-format #f "--parallelism=~A" per-job-parallelism))
'())) '()))

View file

@ -1328,8 +1328,14 @@
output))) output)))
(define (start-inferior-for-data-extration store store-path guix-locpath) (define (start-inferior-for-data-extration store store-path guix-locpath
extra-inferior-environment-variables)
(let* ((original-guix-locpath (getenv "GUIX_LOCPATH")) (let* ((original-guix-locpath (getenv "GUIX_LOCPATH"))
(original-extra-env-vars-values
(map (match-lambda
((key . _)
(getenv key)))
extra-inferior-environment-variables))
(inf (begin (inf (begin
;; Unset the GUILE_LOAD_PATH and GUILE_LOAD_COMPILED_PATH to ;; Unset the GUILE_LOAD_PATH and GUILE_LOAD_COMPILED_PATH to
;; avoid the values for these being used in the ;; avoid the values for these being used in the
@ -1342,6 +1348,15 @@
(unsetenv "GUILE_LOAD_COMPILED_PATH") (unsetenv "GUILE_LOAD_COMPILED_PATH")
(simple-format (current-error-port) "debug: set GUIX_LOCPATH to ~A\n" (simple-format (current-error-port) "debug: set GUIX_LOCPATH to ~A\n"
guix-locpath) guix-locpath)
(for-each
(match-lambda
((key . val)
(simple-format (current-error-port)
"debug: set ~A to ~A\n"
key val)
(setenv key val)))
extra-inferior-environment-variables)
(if (defined? (if (defined?
'open-inferior/container 'open-inferior/container
(resolve-module '(guix inferior))) (resolve-module '(guix inferior)))
@ -1358,6 +1373,11 @@
(open-inferior store-path (open-inferior store-path
#:error-port (current-error-port))))))) #:error-port (current-error-port)))))))
(setenv "GUIX_LOCPATH" original-guix-locpath) ; restore GUIX_LOCPATH (setenv "GUIX_LOCPATH" original-guix-locpath) ; restore GUIX_LOCPATH
(for-each
(lambda (key val)
(setenv key val))
(map car extra-inferior-environment-variables)
original-extra-env-vars-values)
(when (eq? inf #f) (when (eq? inf #f)
(error "error: inferior is #f")) (error "error: inferior is #f"))
@ -1404,6 +1424,7 @@
guix-revision-id commit guix-revision-id commit
guix-source store-path guix-source store-path
#:key skip-system-tests? #:key skip-system-tests?
extra-inferior-environment-variables
parallelism) parallelism)
(define guix-locpath (define guix-locpath
@ -1422,12 +1443,13 @@
(make-resource-pool (make-resource-pool
(lambda () (lambda ()
(let* ((inferior-store (open-connection)) (let* ((inferior-store (open-connection))
(inferior (start-inferior-for-data-extration inferior-store (inferior (start-inferior-for-data-extration
store-path inferior-store
guix-locpath))) store-path
guix-locpath
extra-inferior-environment-variables)))
(ensure-non-blocking-store-connection inferior-store) (ensure-non-blocking-store-connection inferior-store)
(make-inferior-non-blocking! inferior) (make-inferior-non-blocking! inferior)
(simple-format #t "debug: started new inferior and store connection\n") (simple-format #t "debug: started new inferior and store connection\n")
(cons inferior inferior-store))) (cons inferior inferior-store)))
@ -1666,7 +1688,8 @@
(prevent-inlining-for-tests load-channel-instances) (prevent-inlining-for-tests load-channel-instances)
(define* (load-new-guix-revision conn git-repository-id commit (define* (load-new-guix-revision conn git-repository-id commit
#:key skip-system-tests? parallelism) #:key skip-system-tests? parallelism
extra-inferior-environment-variables)
(let* ((git-repository-fields (let* ((git-repository-fields
(select-git-repository conn git-repository-id)) (select-git-repository conn git-repository-id))
(git-repository-url (git-repository-url
@ -1712,6 +1735,8 @@
commit guix-source store-item commit guix-source store-item
#:skip-system-tests? #:skip-system-tests?
skip-system-tests? skip-system-tests?
#:extra-inferior-environment-variables
extra-inferior-environment-variables
#:parallelism parallelism))) #:parallelism parallelism)))
(if (defined? 'channel-news-for-commit (if (defined? 'channel-news-for-commit
@ -2115,6 +2140,7 @@ SKIP LOCKED")
(prevent-inlining-for-tests with-store-connection) (prevent-inlining-for-tests with-store-connection)
(define* (process-load-new-guix-revision-job id #:key skip-system-tests? (define* (process-load-new-guix-revision-job id #:key skip-system-tests?
extra-inferior-environment-variables
parallelism) parallelism)
(with-postgresql-connection (with-postgresql-connection
(simple-format #f "load-new-guix-revision ~A" id) (simple-format #f "load-new-guix-revision ~A" id)
@ -2146,11 +2172,14 @@ SKIP LOCKED")
(lambda () (lambda ()
(with-throw-handler #t (with-throw-handler #t
(lambda () (lambda ()
(load-new-guix-revision conn (load-new-guix-revision
git-repository-id conn
commit git-repository-id
#:skip-system-tests? #t commit
#:parallelism parallelism)) #:skip-system-tests? #t
#:extra-inferior-environment-variables
extra-inferior-environment-variables
#:parallelism parallelism))
(lambda (key . args) (lambda (key . args)
(simple-format (current-error-port) (simple-format (current-error-port)
"error: load-new-guix-revision: ~A ~A\n" "error: load-new-guix-revision: ~A ~A\n"

View file

@ -51,7 +51,12 @@
(alist-cons 'parallelism (alist-cons 'parallelism
(string->number arg) (string->number arg)
(alist-delete 'parallelism (alist-delete 'parallelism
result)))))) result))))
(option '("inferior-set-environment-variable") #t #f
(lambda (opt name arg result)
(alist-cons 'inferior-environment-variable
(string-split arg #\=)
result)))))
(define %default-options (define %default-options
'((parallelism . 1))) '((parallelism . 1)))
@ -79,6 +84,13 @@
(process-load-new-guix-revision-job (process-load-new-guix-revision-job
job job
#:skip-system-tests? (assq-ref opts 'skip-system-tests) #:skip-system-tests? (assq-ref opts 'skip-system-tests)
#:extra-inferior-environment-variables
(filter-map
(match-lambda
(('inferior-environment-variable key val)
(cons key val))
(_ #f))
opts)
#:parallelism (assq-ref opts 'parallelism))) #:parallelism (assq-ref opts 'parallelism)))
#:hz 0 #:hz 0
#:parallelism 1))))) #:parallelism 1)))))

View file

@ -24,6 +24,7 @@
(use-modules (srfi srfi-1) (use-modules (srfi srfi-1)
(srfi srfi-37) (srfi srfi-37)
(ice-9 match)
(guix-data-service database) (guix-data-service database)
(guix-data-service jobs)) (guix-data-service jobs))
@ -49,6 +50,11 @@
(lambda (opt name arg result) (lambda (opt name arg result)
(alist-cons 'per-job-parallelism (alist-cons 'per-job-parallelism
(string->number arg) (string->number arg)
result)))
(option '("inferior-set-environment-variable") #t #f
(lambda (opt name arg result)
(alist-cons 'inferior-environment-variable
(string-split arg #\=)
result))))) result)))))
(define %default-options (define %default-options
@ -95,6 +101,13 @@
(* 2 (assq-ref opts 'max-processes))) (* 2 (assq-ref opts 'max-processes)))
#:skip-system-tests? #:skip-system-tests?
(assq-ref opts 'skip-system-tests) (assq-ref opts 'skip-system-tests)
#:extra-inferior-environment-variables
(filter-map
(match-lambda
(('inferior-environment-variable key val)
(cons key val))
(_ #f))
opts)
#:per-job-parallelism #:per-job-parallelism
(assq-ref opts 'per-job-parallelism))) (assq-ref opts 'per-job-parallelism)))
(lambda _ (lambda _

View file

@ -65,6 +65,7 @@
(lambda* (conn store guix-revision-id commit (lambda* (conn store guix-revision-id commit
guix-source store-path guix-source store-path
#:key skip-system-tests? #:key skip-system-tests?
extra-inferior-environment-variables
parallelism) parallelism)
#t)) #t))