services: guix: Add 'set-http-proxy' action.
Fixes <https://bugs.gnu.org/25569>. Reported by Divan Santana <divan@santanas.co.za>. * gnu/services/base.scm (shepherd-set-http-proxy-action): New procedure. (guix-shepherd-service): Add 'actions' field. Change 'start' to a lambda; check the value of the "http_proxy" environment variable and add "http_proxy" and "https_proxy" to #:environment-variables as a function of that. * gnu/tests/base.scm (run-basic-test)["guix-daemon set-http-proxy action", "guix-daemon set-http-proxy action, clear"]: New tests. * doc/guix.texi (Base Services): Document it.master
parent
1e6fe44da8
commit
3302e03ba0
|
@ -12779,9 +12779,24 @@ List of extra command-line options for @command{guix-daemon}.
|
||||||
File where @command{guix-daemon}'s standard output and standard error
|
File where @command{guix-daemon}'s standard output and standard error
|
||||||
are written.
|
are written.
|
||||||
|
|
||||||
|
@cindex HTTP proxy, for @code{guix-daemon}
|
||||||
|
@cindex proxy, for @code{guix-daemon} HTTP access
|
||||||
@item @code{http-proxy} (default: @code{#f})
|
@item @code{http-proxy} (default: @code{#f})
|
||||||
The HTTP proxy used for downloading fixed-output derivations and
|
The URL of the HTTP and HTTPS proxy used for downloading fixed-output
|
||||||
substitutes.
|
derivations and substitutes.
|
||||||
|
|
||||||
|
It is also possible to change the daemon's proxy at run time through the
|
||||||
|
@code{set-http-proxy} action, which restarts it:
|
||||||
|
|
||||||
|
@example
|
||||||
|
herd set-http-proxy guix-daemon http://localhost:8118
|
||||||
|
@end example
|
||||||
|
|
||||||
|
To clear the proxy settings, run:
|
||||||
|
|
||||||
|
@example
|
||||||
|
herd set-http-proxy guix-daemon
|
||||||
|
@end example
|
||||||
|
|
||||||
@item @code{tmpdir} (default: @code{#f})
|
@item @code{tmpdir} (default: @code{#f})
|
||||||
A directory path where the @command{guix-daemon} will perform builds.
|
A directory path where the @command{guix-daemon} will perform builds.
|
||||||
|
|
|
@ -1640,6 +1640,30 @@ archive' public keys, with GUIX."
|
||||||
(define %default-guix-configuration
|
(define %default-guix-configuration
|
||||||
(guix-configuration))
|
(guix-configuration))
|
||||||
|
|
||||||
|
(define shepherd-set-http-proxy-action
|
||||||
|
;; Shepherd action to change the HTTP(S) proxy.
|
||||||
|
(shepherd-action
|
||||||
|
(name 'set-http-proxy)
|
||||||
|
(documentation
|
||||||
|
"Change the HTTP(S) proxy used by 'guix-daemon' and restart it.")
|
||||||
|
(procedure #~(lambda* (_ #:optional proxy)
|
||||||
|
(let ((environment (environ)))
|
||||||
|
;; A bit of a hack: communicate PROXY to the 'start'
|
||||||
|
;; method via environment variables.
|
||||||
|
(if proxy
|
||||||
|
(begin
|
||||||
|
(format #t "changing HTTP/HTTPS \
|
||||||
|
proxy of 'guix-daemon' to ~s...~%"
|
||||||
|
proxy)
|
||||||
|
(setenv "http_proxy" proxy))
|
||||||
|
(begin
|
||||||
|
(format #t "clearing HTTP/HTTPS \
|
||||||
|
proxy of 'guix-daemon'...~%")
|
||||||
|
(unsetenv "http_proxy")))
|
||||||
|
(action 'guix-daemon 'restart)
|
||||||
|
(environ environment)
|
||||||
|
#t)))))
|
||||||
|
|
||||||
(define (guix-shepherd-service config)
|
(define (guix-shepherd-service config)
|
||||||
"Return a <shepherd-service> for the Guix daemon service with CONFIG."
|
"Return a <shepherd-service> for the Guix daemon service with CONFIG."
|
||||||
(match-record config <guix-configuration>
|
(match-record config <guix-configuration>
|
||||||
|
@ -1651,47 +1675,58 @@ archive' public keys, with GUIX."
|
||||||
(documentation "Run the Guix daemon.")
|
(documentation "Run the Guix daemon.")
|
||||||
(provision '(guix-daemon))
|
(provision '(guix-daemon))
|
||||||
(requirement '(user-processes))
|
(requirement '(user-processes))
|
||||||
|
(actions (list shepherd-set-http-proxy-action))
|
||||||
(modules '((srfi srfi-1)))
|
(modules '((srfi srfi-1)))
|
||||||
(start
|
(start
|
||||||
#~(make-forkexec-constructor
|
#~(lambda _
|
||||||
(cons* #$(file-append guix "/bin/guix-daemon")
|
(define proxy
|
||||||
"--build-users-group" #$build-group
|
;; HTTP/HTTPS proxy. The 'http_proxy' variable is set by
|
||||||
"--max-silent-time" #$(number->string max-silent-time)
|
;; the 'set-http-proxy' action.
|
||||||
"--timeout" #$(number->string timeout)
|
(or (getenv "http_proxy") #$http-proxy))
|
||||||
"--log-compression" #$(symbol->string log-compression)
|
|
||||||
#$@(if use-substitutes?
|
|
||||||
'()
|
|
||||||
'("--no-substitutes"))
|
|
||||||
"--substitute-urls" #$(string-join substitute-urls)
|
|
||||||
#$@extra-options
|
|
||||||
|
|
||||||
;; Add CHROOT-DIRECTORIES and all their dependencies (if
|
(fork+exec-command
|
||||||
;; these are store items) to the chroot.
|
(cons* #$(file-append guix "/bin/guix-daemon")
|
||||||
(append-map (lambda (file)
|
"--build-users-group" #$build-group
|
||||||
(append-map (lambda (directory)
|
"--max-silent-time" #$(number->string max-silent-time)
|
||||||
(list "--chroot-directory"
|
"--timeout" #$(number->string timeout)
|
||||||
directory))
|
"--log-compression" #$(symbol->string log-compression)
|
||||||
(call-with-input-file file
|
#$@(if use-substitutes?
|
||||||
read)))
|
'()
|
||||||
'#$(map references-file chroot-directories)))
|
'("--no-substitutes"))
|
||||||
|
"--substitute-urls" #$(string-join substitute-urls)
|
||||||
|
#$@extra-options
|
||||||
|
|
||||||
#:environment-variables
|
;; Add CHROOT-DIRECTORIES and all their dependencies
|
||||||
(list #$@(if http-proxy
|
;; (if these are store items) to the chroot.
|
||||||
(list (string-append "http_proxy=" http-proxy))
|
(append-map (lambda (file)
|
||||||
'())
|
(append-map (lambda (directory)
|
||||||
#$@(if tmpdir
|
(list "--chroot-directory"
|
||||||
(list (string-append "TMPDIR=" tmpdir))
|
directory))
|
||||||
'())
|
(call-with-input-file file
|
||||||
|
read)))
|
||||||
|
'#$(map references-file
|
||||||
|
chroot-directories)))
|
||||||
|
|
||||||
;; Make sure we run in a UTF-8 locale so that 'guix
|
#:environment-variables
|
||||||
;; offload' correctly restores nars that contain UTF-8
|
(append (list #$@(if tmpdir
|
||||||
;; file names such as 'nss-certs'. See
|
(list (string-append "TMPDIR=" tmpdir))
|
||||||
;; <https://bugs.gnu.org/32942>.
|
'())
|
||||||
(string-append "GUIX_LOCPATH="
|
|
||||||
#$glibc-utf8-locales "/lib/locale")
|
|
||||||
"LC_ALL=en_US.utf8")
|
|
||||||
|
|
||||||
#:log-file #$log-file))
|
;; Make sure we run in a UTF-8 locale so that
|
||||||
|
;; 'guix offload' correctly restores nars that
|
||||||
|
;; contain UTF-8 file names such as
|
||||||
|
;; 'nss-certs'. See
|
||||||
|
;; <https://bugs.gnu.org/32942>.
|
||||||
|
(string-append "GUIX_LOCPATH="
|
||||||
|
#$glibc-utf8-locales
|
||||||
|
"/lib/locale")
|
||||||
|
"LC_ALL=en_US.utf8")
|
||||||
|
(if proxy
|
||||||
|
(list (string-append "http_proxy=" proxy)
|
||||||
|
(string-append "https_proxy=" proxy))
|
||||||
|
'()))
|
||||||
|
|
||||||
|
#:log-file #$log-file)))
|
||||||
(stop #~(make-kill-destructor))))))
|
(stop #~(make-kill-destructor))))))
|
||||||
|
|
||||||
(define (guix-accounts config)
|
(define (guix-accounts config)
|
||||||
|
|
|
@ -459,6 +459,21 @@ info --version")
|
||||||
(marionette-eval '(readlink "/var/guix/gcroots/profiles")
|
(marionette-eval '(readlink "/var/guix/gcroots/profiles")
|
||||||
marionette))
|
marionette))
|
||||||
|
|
||||||
|
(test-equal "guix-daemon set-http-proxy action"
|
||||||
|
'(#t) ;one value, #t
|
||||||
|
(marionette-eval '(with-shepherd-action 'guix-daemon
|
||||||
|
('set-http-proxy "http://localhost:8118")
|
||||||
|
result
|
||||||
|
result)
|
||||||
|
marionette))
|
||||||
|
|
||||||
|
(test-equal "guix-daemon set-http-proxy action, clear"
|
||||||
|
'(#t) ;one value, #t
|
||||||
|
(marionette-eval '(with-shepherd-action 'guix-daemon
|
||||||
|
('set-http-proxy)
|
||||||
|
result
|
||||||
|
result)
|
||||||
|
marionette))
|
||||||
|
|
||||||
(test-assert "screendump"
|
(test-assert "screendump"
|
||||||
(begin
|
(begin
|
||||||
|
|
Reference in New Issue