2014-01-23 23:48:34 +01:00
|
|
|
|
;;; GNU Guix --- Functional package management for GNU
|
2018-06-11 11:42:59 +02:00
|
|
|
|
;;; Copyright © 2014, 2015, 2016, 2017, 2018 Ludovic Courtès <ludo@gnu.org>
|
2017-12-13 23:42:40 +01:00
|
|
|
|
;;; Copyright © 2017 Ricardo Wurmus <rekado@elephly.net>
|
2014-01-23 23:48:34 +01:00
|
|
|
|
;;;
|
|
|
|
|
;;; This file is part of GNU Guix.
|
|
|
|
|
;;;
|
|
|
|
|
;;; GNU Guix is free software; you can redistribute it and/or modify it
|
|
|
|
|
;;; under the terms of the GNU General Public License as published by
|
|
|
|
|
;;; the Free Software Foundation; either version 3 of the License, or (at
|
|
|
|
|
;;; your option) any later version.
|
|
|
|
|
;;;
|
|
|
|
|
;;; GNU Guix is distributed in the hope that it will be useful, but
|
|
|
|
|
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
;;; GNU General Public License for more details.
|
|
|
|
|
;;;
|
|
|
|
|
;;; You should have received a copy of the GNU General Public License
|
|
|
|
|
;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
(define-module (guix scripts offload)
|
2014-03-02 22:39:48 +01:00
|
|
|
|
#:use-module (ssh key)
|
|
|
|
|
#:use-module (ssh auth)
|
|
|
|
|
#:use-module (ssh session)
|
|
|
|
|
#:use-module (ssh channel)
|
2016-11-05 00:47:34 +01:00
|
|
|
|
#:use-module (ssh popen)
|
|
|
|
|
#:use-module (ssh dist)
|
|
|
|
|
#:use-module (ssh dist node)
|
2016-12-01 21:49:16 +01:00
|
|
|
|
#:use-module (ssh version)
|
2014-01-23 23:48:34 +01:00
|
|
|
|
#:use-module (guix config)
|
|
|
|
|
#:use-module (guix records)
|
2016-12-30 23:22:27 +01:00
|
|
|
|
#:use-module (guix ssh)
|
2014-01-23 23:48:34 +01:00
|
|
|
|
#:use-module (guix store)
|
|
|
|
|
#:use-module (guix derivations)
|
2016-10-19 14:28:56 +02:00
|
|
|
|
#:use-module ((guix serialization)
|
|
|
|
|
#:select (nar-error? nar-error-file))
|
2014-01-23 23:48:34 +01:00
|
|
|
|
#:use-module (guix nar)
|
|
|
|
|
#:use-module (guix utils)
|
2017-05-28 16:09:32 +02:00
|
|
|
|
#:use-module ((guix build syscalls)
|
|
|
|
|
#:select (fcntl-flock set-thread-name))
|
2014-03-06 21:38:45 +01:00
|
|
|
|
#:use-module ((guix build utils) #:select (which mkdir-p))
|
2014-01-23 23:48:34 +01:00
|
|
|
|
#:use-module (guix ui)
|
|
|
|
|
#:use-module (srfi srfi-1)
|
2014-03-26 16:22:41 +01:00
|
|
|
|
#:use-module (srfi srfi-11)
|
2014-01-23 23:48:34 +01:00
|
|
|
|
#:use-module (srfi srfi-26)
|
|
|
|
|
#:use-module (srfi srfi-34)
|
|
|
|
|
#:use-module (srfi srfi-35)
|
|
|
|
|
#:use-module (ice-9 popen)
|
|
|
|
|
#:use-module (ice-9 rdelim)
|
|
|
|
|
#:use-module (ice-9 match)
|
|
|
|
|
#:use-module (ice-9 regex)
|
|
|
|
|
#:use-module (ice-9 format)
|
2016-10-19 14:28:56 +02:00
|
|
|
|
#:use-module (ice-9 binary-ports)
|
2014-01-23 23:48:34 +01:00
|
|
|
|
#:export (build-machine
|
|
|
|
|
build-requirements
|
|
|
|
|
guix-offload))
|
|
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
;;;
|
|
|
|
|
;;; Attempt to offload builds to the machines listed in
|
|
|
|
|
;;; /etc/guix/machines.scm, transferring missing dependencies over SSH, and
|
|
|
|
|
;;; retrieving the build output(s) over SSH upon success.
|
|
|
|
|
;;;
|
|
|
|
|
;;; This command should not be used directly; instead, it is called on-demand
|
|
|
|
|
;;; by the daemon, unless it was started with '--no-build-hook' or a client
|
|
|
|
|
;;; inhibited build hooks.
|
|
|
|
|
;;;
|
|
|
|
|
;;; Code:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define-record-type* <build-machine>
|
|
|
|
|
build-machine make-build-machine
|
|
|
|
|
build-machine?
|
|
|
|
|
(name build-machine-name) ; string
|
2014-03-13 21:58:04 +01:00
|
|
|
|
(port build-machine-port ; number
|
|
|
|
|
(default 22))
|
2014-01-23 23:48:34 +01:00
|
|
|
|
(system build-machine-system) ; string
|
|
|
|
|
(user build-machine-user) ; string
|
|
|
|
|
(private-key build-machine-private-key ; file name
|
2014-03-02 22:39:48 +01:00
|
|
|
|
(default (user-openssh-private-key)))
|
|
|
|
|
(host-key build-machine-host-key) ; string
|
2016-12-05 23:15:17 +01:00
|
|
|
|
(compression build-machine-compression ; string
|
|
|
|
|
(default "zlib@openssh.com,zlib"))
|
|
|
|
|
(compression-level build-machine-compression-level ;integer
|
|
|
|
|
(default 3))
|
2016-11-05 00:47:34 +01:00
|
|
|
|
(daemon-socket build-machine-daemon-socket ; string
|
|
|
|
|
(default "/var/guix/daemon-socket/socket"))
|
2014-01-23 23:48:34 +01:00
|
|
|
|
(parallel-builds build-machine-parallel-builds ; number
|
|
|
|
|
(default 1))
|
|
|
|
|
(speed build-machine-speed ; inexact real
|
|
|
|
|
(default 1.0))
|
|
|
|
|
(features build-machine-features ; list of strings
|
|
|
|
|
(default '())))
|
|
|
|
|
|
|
|
|
|
(define-record-type* <build-requirements>
|
|
|
|
|
build-requirements make-build-requirements
|
|
|
|
|
build-requirements?
|
|
|
|
|
(system build-requirements-system) ; string
|
|
|
|
|
(features build-requirements-features ; list of strings
|
|
|
|
|
(default '())))
|
|
|
|
|
|
|
|
|
|
(define %machine-file
|
|
|
|
|
;; File that lists machines available as build slaves.
|
|
|
|
|
(string-append %config-directory "/machines.scm"))
|
|
|
|
|
|
2014-03-02 22:39:48 +01:00
|
|
|
|
(define (user-openssh-private-key)
|
|
|
|
|
"Return the user's default SSH private key, or #f if it could not be
|
2014-01-23 23:48:34 +01:00
|
|
|
|
determined."
|
|
|
|
|
(and=> (getenv "HOME")
|
2014-03-02 22:39:48 +01:00
|
|
|
|
(cut string-append <> "/.ssh/id_rsa")))
|
2014-01-23 23:48:34 +01:00
|
|
|
|
|
|
|
|
|
(define %user-module
|
|
|
|
|
;; Module in which the machine description file is loaded.
|
|
|
|
|
(let ((module (make-fresh-user-module)))
|
|
|
|
|
(module-use! module (resolve-interface '(guix scripts offload)))
|
|
|
|
|
module))
|
|
|
|
|
|
|
|
|
|
(define* (build-machines #:optional (file %machine-file))
|
|
|
|
|
"Read the list of build machines from FILE and return it."
|
|
|
|
|
(catch #t
|
|
|
|
|
(lambda ()
|
|
|
|
|
;; Avoid ABI incompatibility with the <build-machine> record.
|
2017-12-01 18:31:16 +01:00
|
|
|
|
;; (set! %fresh-auto-compile #t)
|
2014-01-23 23:48:34 +01:00
|
|
|
|
|
|
|
|
|
(save-module-excursion
|
|
|
|
|
(lambda ()
|
|
|
|
|
(set-current-module %user-module)
|
2018-06-14 23:08:08 +02:00
|
|
|
|
(match (primitive-load file)
|
|
|
|
|
(((? build-machine? machines) ...)
|
|
|
|
|
machines)
|
|
|
|
|
(_
|
|
|
|
|
;; Instead of crashing, assume the empty list.
|
|
|
|
|
(warning (G_ "'~a' did not return a list of build machines; \
|
|
|
|
|
ignoring it~%")
|
|
|
|
|
file)
|
|
|
|
|
'())))))
|
2014-01-23 23:48:34 +01:00
|
|
|
|
(lambda args
|
|
|
|
|
(match args
|
2016-09-20 10:51:39 +02:00
|
|
|
|
(('system-error . rest)
|
2014-01-23 23:48:34 +01:00
|
|
|
|
(let ((err (system-error-errno args)))
|
|
|
|
|
;; Silently ignore missing file since this is a common case.
|
|
|
|
|
(if (= ENOENT err)
|
|
|
|
|
'()
|
ui: Rename '_' to 'G_'.
This avoids collisions with '_' when the latter is used as a 'match'
pattern for instance. See
<https://lists.gnu.org/archive/html/guix-devel/2017-04/msg00464.html>.
* guix/ui.scm: Rename '_' to 'G_'.
* po/guix/Makevars (XGETTEXT_OPTIONS): Adjust accordingly.
* build-aux/compile-all.scm (warnings): Remove 'format'.
* gnu/packages.scm,
gnu/services.scm,
gnu/services/shepherd.scm,
gnu/system.scm,
gnu/system/shadow.scm,
guix/gnupg.scm,
guix/http-client.scm,
guix/import/cpan.scm,
guix/import/elpa.scm,
guix/import/pypi.scm,
guix/nar.scm,
guix/scripts.scm,
guix/scripts/archive.scm,
guix/scripts/authenticate.scm,
guix/scripts/build.scm,
guix/scripts/challenge.scm,
guix/scripts/container.scm,
guix/scripts/container/exec.scm,
guix/scripts/copy.scm,
guix/scripts/download.scm,
guix/scripts/edit.scm,
guix/scripts/environment.scm,
guix/scripts/gc.scm,
guix/scripts/graph.scm,
guix/scripts/hash.scm,
guix/scripts/import.scm,
guix/scripts/import/cpan.scm,
guix/scripts/import/cran.scm,
guix/scripts/import/crate.scm,
guix/scripts/import/elpa.scm,
guix/scripts/import/gem.scm,
guix/scripts/import/gnu.scm,
guix/scripts/import/hackage.scm,
guix/scripts/import/nix.scm,
guix/scripts/import/pypi.scm,
guix/scripts/import/stackage.scm,
guix/scripts/lint.scm,
guix/scripts/offload.scm,
guix/scripts/pack.scm,
guix/scripts/package.scm,
guix/scripts/perform-download.scm,
guix/scripts/publish.scm,
guix/scripts/pull.scm,
guix/scripts/refresh.scm,
guix/scripts/size.scm,
guix/scripts/substitute.scm,
guix/scripts/system.scm,
guix/ssh.scm,
guix/upstream.scm: Use 'G_' instead of '_'. Most of this change was
obtained by running: "sed -i -e's/(_ "/(G_ "/g' `find -name \*.scm`".
2017-05-03 15:57:02 +02:00
|
|
|
|
(leave (G_ "failed to open machine file '~a': ~a~%")
|
2014-02-02 01:32:50 +01:00
|
|
|
|
file (strerror err)))))
|
2014-06-26 22:23:36 +02:00
|
|
|
|
(('syntax-error proc message properties form . rest)
|
|
|
|
|
(let ((loc (source-properties->location properties)))
|
ui: Rename '_' to 'G_'.
This avoids collisions with '_' when the latter is used as a 'match'
pattern for instance. See
<https://lists.gnu.org/archive/html/guix-devel/2017-04/msg00464.html>.
* guix/ui.scm: Rename '_' to 'G_'.
* po/guix/Makevars (XGETTEXT_OPTIONS): Adjust accordingly.
* build-aux/compile-all.scm (warnings): Remove 'format'.
* gnu/packages.scm,
gnu/services.scm,
gnu/services/shepherd.scm,
gnu/system.scm,
gnu/system/shadow.scm,
guix/gnupg.scm,
guix/http-client.scm,
guix/import/cpan.scm,
guix/import/elpa.scm,
guix/import/pypi.scm,
guix/nar.scm,
guix/scripts.scm,
guix/scripts/archive.scm,
guix/scripts/authenticate.scm,
guix/scripts/build.scm,
guix/scripts/challenge.scm,
guix/scripts/container.scm,
guix/scripts/container/exec.scm,
guix/scripts/copy.scm,
guix/scripts/download.scm,
guix/scripts/edit.scm,
guix/scripts/environment.scm,
guix/scripts/gc.scm,
guix/scripts/graph.scm,
guix/scripts/hash.scm,
guix/scripts/import.scm,
guix/scripts/import/cpan.scm,
guix/scripts/import/cran.scm,
guix/scripts/import/crate.scm,
guix/scripts/import/elpa.scm,
guix/scripts/import/gem.scm,
guix/scripts/import/gnu.scm,
guix/scripts/import/hackage.scm,
guix/scripts/import/nix.scm,
guix/scripts/import/pypi.scm,
guix/scripts/import/stackage.scm,
guix/scripts/lint.scm,
guix/scripts/offload.scm,
guix/scripts/pack.scm,
guix/scripts/package.scm,
guix/scripts/perform-download.scm,
guix/scripts/publish.scm,
guix/scripts/pull.scm,
guix/scripts/refresh.scm,
guix/scripts/size.scm,
guix/scripts/substitute.scm,
guix/scripts/system.scm,
guix/ssh.scm,
guix/upstream.scm: Use 'G_' instead of '_'. Most of this change was
obtained by running: "sed -i -e's/(_ "/(G_ "/g' `find -name \*.scm`".
2017-05-03 15:57:02 +02:00
|
|
|
|
(leave (G_ "~a: ~a~%")
|
2014-06-26 22:23:36 +02:00
|
|
|
|
(location->string loc) message)))
|
2016-09-20 10:51:39 +02:00
|
|
|
|
(x
|
ui: Rename '_' to 'G_'.
This avoids collisions with '_' when the latter is used as a 'match'
pattern for instance. See
<https://lists.gnu.org/archive/html/guix-devel/2017-04/msg00464.html>.
* guix/ui.scm: Rename '_' to 'G_'.
* po/guix/Makevars (XGETTEXT_OPTIONS): Adjust accordingly.
* build-aux/compile-all.scm (warnings): Remove 'format'.
* gnu/packages.scm,
gnu/services.scm,
gnu/services/shepherd.scm,
gnu/system.scm,
gnu/system/shadow.scm,
guix/gnupg.scm,
guix/http-client.scm,
guix/import/cpan.scm,
guix/import/elpa.scm,
guix/import/pypi.scm,
guix/nar.scm,
guix/scripts.scm,
guix/scripts/archive.scm,
guix/scripts/authenticate.scm,
guix/scripts/build.scm,
guix/scripts/challenge.scm,
guix/scripts/container.scm,
guix/scripts/container/exec.scm,
guix/scripts/copy.scm,
guix/scripts/download.scm,
guix/scripts/edit.scm,
guix/scripts/environment.scm,
guix/scripts/gc.scm,
guix/scripts/graph.scm,
guix/scripts/hash.scm,
guix/scripts/import.scm,
guix/scripts/import/cpan.scm,
guix/scripts/import/cran.scm,
guix/scripts/import/crate.scm,
guix/scripts/import/elpa.scm,
guix/scripts/import/gem.scm,
guix/scripts/import/gnu.scm,
guix/scripts/import/hackage.scm,
guix/scripts/import/nix.scm,
guix/scripts/import/pypi.scm,
guix/scripts/import/stackage.scm,
guix/scripts/lint.scm,
guix/scripts/offload.scm,
guix/scripts/pack.scm,
guix/scripts/package.scm,
guix/scripts/perform-download.scm,
guix/scripts/publish.scm,
guix/scripts/pull.scm,
guix/scripts/refresh.scm,
guix/scripts/size.scm,
guix/scripts/substitute.scm,
guix/scripts/system.scm,
guix/ssh.scm,
guix/upstream.scm: Use 'G_' instead of '_'. Most of this change was
obtained by running: "sed -i -e's/(_ "/(G_ "/g' `find -name \*.scm`".
2017-05-03 15:57:02 +02:00
|
|
|
|
(leave (G_ "failed to load machine file '~a': ~s~%")
|
2014-02-02 01:32:50 +01:00
|
|
|
|
file args))))))
|
2014-01-23 23:48:34 +01:00
|
|
|
|
|
2014-03-02 22:39:48 +01:00
|
|
|
|
(define (host-key->type+key host-key)
|
|
|
|
|
"Destructure HOST-KEY, an OpenSSH host key string, and return two values:
|
|
|
|
|
its key type as a symbol, and the actual base64-encoded string."
|
|
|
|
|
(define (type->symbol type)
|
|
|
|
|
(and (string-prefix? "ssh-" type)
|
|
|
|
|
(string->symbol (string-drop type 4))))
|
|
|
|
|
|
|
|
|
|
(match (string-tokenize host-key)
|
2017-04-21 17:18:54 +02:00
|
|
|
|
((type key x)
|
2014-03-02 22:39:48 +01:00
|
|
|
|
(values (type->symbol type) key))
|
|
|
|
|
((type key)
|
|
|
|
|
(values (type->symbol type) key))))
|
|
|
|
|
|
|
|
|
|
(define (private-key-from-file* file)
|
|
|
|
|
"Like 'private-key-from-file', but raise an error that 'with-error-handling'
|
|
|
|
|
can interpret meaningfully."
|
|
|
|
|
(catch 'guile-ssh-error
|
|
|
|
|
(lambda ()
|
|
|
|
|
(private-key-from-file file))
|
|
|
|
|
(lambda (key proc str . rest)
|
|
|
|
|
(raise (condition
|
ui: Rename '_' to 'G_'.
This avoids collisions with '_' when the latter is used as a 'match'
pattern for instance. See
<https://lists.gnu.org/archive/html/guix-devel/2017-04/msg00464.html>.
* guix/ui.scm: Rename '_' to 'G_'.
* po/guix/Makevars (XGETTEXT_OPTIONS): Adjust accordingly.
* build-aux/compile-all.scm (warnings): Remove 'format'.
* gnu/packages.scm,
gnu/services.scm,
gnu/services/shepherd.scm,
gnu/system.scm,
gnu/system/shadow.scm,
guix/gnupg.scm,
guix/http-client.scm,
guix/import/cpan.scm,
guix/import/elpa.scm,
guix/import/pypi.scm,
guix/nar.scm,
guix/scripts.scm,
guix/scripts/archive.scm,
guix/scripts/authenticate.scm,
guix/scripts/build.scm,
guix/scripts/challenge.scm,
guix/scripts/container.scm,
guix/scripts/container/exec.scm,
guix/scripts/copy.scm,
guix/scripts/download.scm,
guix/scripts/edit.scm,
guix/scripts/environment.scm,
guix/scripts/gc.scm,
guix/scripts/graph.scm,
guix/scripts/hash.scm,
guix/scripts/import.scm,
guix/scripts/import/cpan.scm,
guix/scripts/import/cran.scm,
guix/scripts/import/crate.scm,
guix/scripts/import/elpa.scm,
guix/scripts/import/gem.scm,
guix/scripts/import/gnu.scm,
guix/scripts/import/hackage.scm,
guix/scripts/import/nix.scm,
guix/scripts/import/pypi.scm,
guix/scripts/import/stackage.scm,
guix/scripts/lint.scm,
guix/scripts/offload.scm,
guix/scripts/pack.scm,
guix/scripts/package.scm,
guix/scripts/perform-download.scm,
guix/scripts/publish.scm,
guix/scripts/pull.scm,
guix/scripts/refresh.scm,
guix/scripts/size.scm,
guix/scripts/substitute.scm,
guix/scripts/system.scm,
guix/ssh.scm,
guix/upstream.scm: Use 'G_' instead of '_'. Most of this change was
obtained by running: "sed -i -e's/(_ "/(G_ "/g' `find -name \*.scm`".
2017-05-03 15:57:02 +02:00
|
|
|
|
(&message (message (format #f (G_ "failed to load SSH \
|
2014-03-02 22:39:48 +01:00
|
|
|
|
private key from '~a': ~a")
|
|
|
|
|
file str))))))))
|
|
|
|
|
|
|
|
|
|
(define (open-ssh-session machine)
|
|
|
|
|
"Open an SSH session for MACHINE and return it. Throw an error on failure."
|
|
|
|
|
(let ((private (private-key-from-file* (build-machine-private-key machine)))
|
|
|
|
|
(public (public-key-from-file
|
|
|
|
|
(string-append (build-machine-private-key machine)
|
|
|
|
|
".pub")))
|
|
|
|
|
(session (make-session #:user (build-machine-user machine)
|
|
|
|
|
#:host (build-machine-name machine)
|
|
|
|
|
#:port (build-machine-port machine)
|
2016-12-06 01:00:11 +01:00
|
|
|
|
#:timeout 10 ;seconds
|
2014-03-02 22:39:48 +01:00
|
|
|
|
;; #:log-verbosity 'protocol
|
|
|
|
|
#:identity (build-machine-private-key machine)
|
|
|
|
|
|
2016-12-09 14:54:42 +01:00
|
|
|
|
;; By default libssh reads ~/.ssh/known_hosts
|
|
|
|
|
;; and uses that to adjust its choice of cipher
|
|
|
|
|
;; suites, which changes the type of host key
|
|
|
|
|
;; that the server sends (RSA vs. Ed25519,
|
|
|
|
|
;; etc.). Opt for something reproducible and
|
|
|
|
|
;; stateless instead.
|
|
|
|
|
#:knownhosts "/dev/null"
|
|
|
|
|
|
2014-03-02 22:39:48 +01:00
|
|
|
|
;; We need lightweight compression when
|
|
|
|
|
;; exchanging full archives.
|
2016-12-05 23:15:17 +01:00
|
|
|
|
#:compression
|
|
|
|
|
(build-machine-compression machine)
|
|
|
|
|
#:compression-level
|
|
|
|
|
(build-machine-compression-level machine))))
|
2016-12-01 23:20:18 +01:00
|
|
|
|
(match (connect! session)
|
|
|
|
|
('ok
|
|
|
|
|
;; Authenticate the server. XXX: Guile-SSH 0.10.1 doesn't know about
|
|
|
|
|
;; ed25519 keys and 'get-key-type' returns #f in that case.
|
|
|
|
|
(let-values (((server) (get-server-public-key session))
|
|
|
|
|
((type key) (host-key->type+key
|
|
|
|
|
(build-machine-host-key machine))))
|
|
|
|
|
(unless (and (or (not (get-key-type server))
|
|
|
|
|
(eq? (get-key-type server) type))
|
|
|
|
|
(string=? (public-key->string server) key))
|
|
|
|
|
;; Key mismatch: something's wrong. XXX: It could be that the server
|
|
|
|
|
;; provided its Ed25519 key when we where expecting its RSA key.
|
ui: Rename '_' to 'G_'.
This avoids collisions with '_' when the latter is used as a 'match'
pattern for instance. See
<https://lists.gnu.org/archive/html/guix-devel/2017-04/msg00464.html>.
* guix/ui.scm: Rename '_' to 'G_'.
* po/guix/Makevars (XGETTEXT_OPTIONS): Adjust accordingly.
* build-aux/compile-all.scm (warnings): Remove 'format'.
* gnu/packages.scm,
gnu/services.scm,
gnu/services/shepherd.scm,
gnu/system.scm,
gnu/system/shadow.scm,
guix/gnupg.scm,
guix/http-client.scm,
guix/import/cpan.scm,
guix/import/elpa.scm,
guix/import/pypi.scm,
guix/nar.scm,
guix/scripts.scm,
guix/scripts/archive.scm,
guix/scripts/authenticate.scm,
guix/scripts/build.scm,
guix/scripts/challenge.scm,
guix/scripts/container.scm,
guix/scripts/container/exec.scm,
guix/scripts/copy.scm,
guix/scripts/download.scm,
guix/scripts/edit.scm,
guix/scripts/environment.scm,
guix/scripts/gc.scm,
guix/scripts/graph.scm,
guix/scripts/hash.scm,
guix/scripts/import.scm,
guix/scripts/import/cpan.scm,
guix/scripts/import/cran.scm,
guix/scripts/import/crate.scm,
guix/scripts/import/elpa.scm,
guix/scripts/import/gem.scm,
guix/scripts/import/gnu.scm,
guix/scripts/import/hackage.scm,
guix/scripts/import/nix.scm,
guix/scripts/import/pypi.scm,
guix/scripts/import/stackage.scm,
guix/scripts/lint.scm,
guix/scripts/offload.scm,
guix/scripts/pack.scm,
guix/scripts/package.scm,
guix/scripts/perform-download.scm,
guix/scripts/publish.scm,
guix/scripts/pull.scm,
guix/scripts/refresh.scm,
guix/scripts/size.scm,
guix/scripts/substitute.scm,
guix/scripts/system.scm,
guix/ssh.scm,
guix/upstream.scm: Use 'G_' instead of '_'. Most of this change was
obtained by running: "sed -i -e's/(_ "/(G_ "/g' `find -name \*.scm`".
2017-05-03 15:57:02 +02:00
|
|
|
|
(leave (G_ "server at '~a' returned host key '~a' of type '~a' \
|
2014-03-02 22:39:48 +01:00
|
|
|
|
instead of '~a' of type '~a'~%")
|
2016-12-01 23:20:18 +01:00
|
|
|
|
(build-machine-name machine)
|
|
|
|
|
(public-key->string server) (get-key-type server)
|
|
|
|
|
key type)))
|
|
|
|
|
|
|
|
|
|
(let ((auth (userauth-public-key! session private)))
|
|
|
|
|
(unless (eq? 'success auth)
|
|
|
|
|
(disconnect! session)
|
ui: Rename '_' to 'G_'.
This avoids collisions with '_' when the latter is used as a 'match'
pattern for instance. See
<https://lists.gnu.org/archive/html/guix-devel/2017-04/msg00464.html>.
* guix/ui.scm: Rename '_' to 'G_'.
* po/guix/Makevars (XGETTEXT_OPTIONS): Adjust accordingly.
* build-aux/compile-all.scm (warnings): Remove 'format'.
* gnu/packages.scm,
gnu/services.scm,
gnu/services/shepherd.scm,
gnu/system.scm,
gnu/system/shadow.scm,
guix/gnupg.scm,
guix/http-client.scm,
guix/import/cpan.scm,
guix/import/elpa.scm,
guix/import/pypi.scm,
guix/nar.scm,
guix/scripts.scm,
guix/scripts/archive.scm,
guix/scripts/authenticate.scm,
guix/scripts/build.scm,
guix/scripts/challenge.scm,
guix/scripts/container.scm,
guix/scripts/container/exec.scm,
guix/scripts/copy.scm,
guix/scripts/download.scm,
guix/scripts/edit.scm,
guix/scripts/environment.scm,
guix/scripts/gc.scm,
guix/scripts/graph.scm,
guix/scripts/hash.scm,
guix/scripts/import.scm,
guix/scripts/import/cpan.scm,
guix/scripts/import/cran.scm,
guix/scripts/import/crate.scm,
guix/scripts/import/elpa.scm,
guix/scripts/import/gem.scm,
guix/scripts/import/gnu.scm,
guix/scripts/import/hackage.scm,
guix/scripts/import/nix.scm,
guix/scripts/import/pypi.scm,
guix/scripts/import/stackage.scm,
guix/scripts/lint.scm,
guix/scripts/offload.scm,
guix/scripts/pack.scm,
guix/scripts/package.scm,
guix/scripts/perform-download.scm,
guix/scripts/publish.scm,
guix/scripts/pull.scm,
guix/scripts/refresh.scm,
guix/scripts/size.scm,
guix/scripts/substitute.scm,
guix/scripts/system.scm,
guix/ssh.scm,
guix/upstream.scm: Use 'G_' instead of '_'. Most of this change was
obtained by running: "sed -i -e's/(_ "/(G_ "/g' `find -name \*.scm`".
2017-05-03 15:57:02 +02:00
|
|
|
|
(leave (G_ "SSH public key authentication failed for '~a': ~a~%")
|
2016-12-01 23:20:18 +01:00
|
|
|
|
(build-machine-name machine) (get-error session))))
|
|
|
|
|
|
|
|
|
|
session)
|
|
|
|
|
(x
|
|
|
|
|
;; Connection failed or timeout expired.
|
ui: Rename '_' to 'G_'.
This avoids collisions with '_' when the latter is used as a 'match'
pattern for instance. See
<https://lists.gnu.org/archive/html/guix-devel/2017-04/msg00464.html>.
* guix/ui.scm: Rename '_' to 'G_'.
* po/guix/Makevars (XGETTEXT_OPTIONS): Adjust accordingly.
* build-aux/compile-all.scm (warnings): Remove 'format'.
* gnu/packages.scm,
gnu/services.scm,
gnu/services/shepherd.scm,
gnu/system.scm,
gnu/system/shadow.scm,
guix/gnupg.scm,
guix/http-client.scm,
guix/import/cpan.scm,
guix/import/elpa.scm,
guix/import/pypi.scm,
guix/nar.scm,
guix/scripts.scm,
guix/scripts/archive.scm,
guix/scripts/authenticate.scm,
guix/scripts/build.scm,
guix/scripts/challenge.scm,
guix/scripts/container.scm,
guix/scripts/container/exec.scm,
guix/scripts/copy.scm,
guix/scripts/download.scm,
guix/scripts/edit.scm,
guix/scripts/environment.scm,
guix/scripts/gc.scm,
guix/scripts/graph.scm,
guix/scripts/hash.scm,
guix/scripts/import.scm,
guix/scripts/import/cpan.scm,
guix/scripts/import/cran.scm,
guix/scripts/import/crate.scm,
guix/scripts/import/elpa.scm,
guix/scripts/import/gem.scm,
guix/scripts/import/gnu.scm,
guix/scripts/import/hackage.scm,
guix/scripts/import/nix.scm,
guix/scripts/import/pypi.scm,
guix/scripts/import/stackage.scm,
guix/scripts/lint.scm,
guix/scripts/offload.scm,
guix/scripts/pack.scm,
guix/scripts/package.scm,
guix/scripts/perform-download.scm,
guix/scripts/publish.scm,
guix/scripts/pull.scm,
guix/scripts/refresh.scm,
guix/scripts/size.scm,
guix/scripts/substitute.scm,
guix/scripts/system.scm,
guix/ssh.scm,
guix/upstream.scm: Use 'G_' instead of '_'. Most of this change was
obtained by running: "sed -i -e's/(_ "/(G_ "/g' `find -name \*.scm`".
2017-05-03 15:57:02 +02:00
|
|
|
|
(leave (G_ "failed to connect to '~a': ~a~%")
|
2016-12-01 23:20:18 +01:00
|
|
|
|
(build-machine-name machine) (get-error session))))))
|
2014-03-02 22:39:48 +01:00
|
|
|
|
|
2014-03-09 18:08:21 +01:00
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
;;; Synchronization.
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
(define (lock-file file)
|
|
|
|
|
"Wait and acquire an exclusive lock on FILE. Return an open port."
|
|
|
|
|
(mkdir-p (dirname file))
|
|
|
|
|
(let ((port (open-file file "w0")))
|
|
|
|
|
(fcntl-flock port 'write-lock)
|
|
|
|
|
port))
|
|
|
|
|
|
|
|
|
|
(define (unlock-file lock)
|
|
|
|
|
"Unlock LOCK."
|
|
|
|
|
(fcntl-flock lock 'unlock)
|
|
|
|
|
(close-port lock)
|
|
|
|
|
#t)
|
|
|
|
|
|
|
|
|
|
(define-syntax-rule (with-file-lock file exp ...)
|
|
|
|
|
"Wait to acquire a lock on FILE and evaluate EXP in that context."
|
|
|
|
|
(let ((port (lock-file file)))
|
|
|
|
|
(dynamic-wind
|
|
|
|
|
(lambda ()
|
|
|
|
|
#t)
|
|
|
|
|
(lambda ()
|
|
|
|
|
exp ...)
|
|
|
|
|
(lambda ()
|
|
|
|
|
(unlock-file port)))))
|
|
|
|
|
|
|
|
|
|
(define-syntax-rule (with-machine-lock machine hint exp ...)
|
|
|
|
|
"Wait to acquire MACHINE's exclusive lock for HINT, and evaluate EXP in that
|
|
|
|
|
context."
|
|
|
|
|
(with-file-lock (machine-lock-file machine hint)
|
|
|
|
|
exp ...))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define (machine-slot-file machine slot)
|
|
|
|
|
"Return the file name of MACHINE's file for SLOT."
|
|
|
|
|
;; For each machine we have a bunch of files representing each build slot.
|
|
|
|
|
;; When choosing a build machine, we attempt to get an exclusive lock on one
|
|
|
|
|
;; of these; if we fail, that means all the build slots are already taken.
|
|
|
|
|
;; Inspired by Nix's build-remote.pl.
|
|
|
|
|
(string-append (string-append %state-directory "/offload/"
|
|
|
|
|
(build-machine-name machine)
|
|
|
|
|
"/" (number->string slot))))
|
|
|
|
|
|
|
|
|
|
(define (acquire-build-slot machine)
|
|
|
|
|
"Attempt to acquire a build slot on MACHINE. Return the port representing
|
|
|
|
|
the slot, or #f if none is available.
|
|
|
|
|
|
|
|
|
|
This mechanism allows us to set a hard limit on the number of simultaneous
|
|
|
|
|
connections allowed to MACHINE."
|
|
|
|
|
(mkdir-p (dirname (machine-slot-file machine 0)))
|
|
|
|
|
(with-machine-lock machine 'slots
|
|
|
|
|
(any (lambda (slot)
|
|
|
|
|
(let ((port (open-file (machine-slot-file machine slot)
|
|
|
|
|
"w0")))
|
|
|
|
|
(catch 'flock-error
|
|
|
|
|
(lambda ()
|
|
|
|
|
(fcntl-flock port 'write-lock #:wait? #f)
|
|
|
|
|
;; Got it!
|
|
|
|
|
(format (current-error-port)
|
|
|
|
|
"process ~a acquired build slot '~a'~%"
|
|
|
|
|
(getpid) (port-filename port))
|
|
|
|
|
port)
|
|
|
|
|
(lambda args
|
|
|
|
|
;; PORT is already locked by another process.
|
|
|
|
|
(close-port port)
|
|
|
|
|
#f))))
|
|
|
|
|
(iota (build-machine-parallel-builds machine)))))
|
|
|
|
|
|
|
|
|
|
(define (release-build-slot slot)
|
|
|
|
|
"Release SLOT, a build slot as returned as by 'acquire-build-slot'."
|
|
|
|
|
(close-port slot))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
;;; Offloading.
|
|
|
|
|
;;;
|
|
|
|
|
|
2014-03-19 23:12:06 +01:00
|
|
|
|
(define (build-log-port)
|
|
|
|
|
"Return the default port where build logs should be sent. The default is
|
|
|
|
|
file descriptor 4, which is open by the daemon before running the offload
|
|
|
|
|
hook."
|
|
|
|
|
(let ((port (fdopen 4 "w0")))
|
|
|
|
|
;; Make sure file descriptor 4 isn't closed when PORT is GC'd.
|
|
|
|
|
(set-port-revealed! port 1)
|
|
|
|
|
port))
|
|
|
|
|
|
2014-03-09 14:05:30 +01:00
|
|
|
|
(define* (transfer-and-offload drv machine
|
|
|
|
|
#:key
|
|
|
|
|
(inputs '())
|
|
|
|
|
(outputs '())
|
|
|
|
|
(max-silent-time 3600)
|
2014-03-09 23:13:53 +01:00
|
|
|
|
build-timeout
|
2014-03-09 14:05:30 +01:00
|
|
|
|
print-build-trace?)
|
|
|
|
|
"Offload DRV to MACHINE. Prior to the actual offloading, transfer all of
|
|
|
|
|
INPUTS to MACHINE; if building DRV succeeds, retrieve all of OUTPUTS from
|
|
|
|
|
MACHINE."
|
2016-11-02 12:00:47 +01:00
|
|
|
|
(define session
|
|
|
|
|
(open-ssh-session machine))
|
|
|
|
|
|
2016-11-05 00:47:34 +01:00
|
|
|
|
(define store
|
|
|
|
|
(connect-to-remote-daemon session
|
|
|
|
|
(build-machine-daemon-socket machine)))
|
|
|
|
|
|
|
|
|
|
(set-build-options store
|
|
|
|
|
#:print-build-trace print-build-trace?
|
|
|
|
|
#:max-silent-time max-silent-time
|
|
|
|
|
#:timeout build-timeout)
|
|
|
|
|
|
|
|
|
|
;; Protect DRV from garbage collection.
|
|
|
|
|
(add-temp-root store (derivation-file-name drv))
|
|
|
|
|
|
2016-12-30 23:22:27 +01:00
|
|
|
|
(with-store local
|
|
|
|
|
(send-files local (cons (derivation-file-name drv) inputs) store
|
|
|
|
|
#:log-port (current-output-port)))
|
2016-11-05 00:47:34 +01:00
|
|
|
|
(format (current-error-port) "offloading '~a' to '~a'...~%"
|
|
|
|
|
(derivation-file-name drv) (build-machine-name machine))
|
|
|
|
|
(format (current-error-port) "@ build-remote ~a ~a~%"
|
|
|
|
|
(derivation-file-name drv) (build-machine-name machine))
|
|
|
|
|
|
|
|
|
|
(guard (c ((nix-protocol-error? c)
|
|
|
|
|
(format (current-error-port)
|
ui: Rename '_' to 'G_'.
This avoids collisions with '_' when the latter is used as a 'match'
pattern for instance. See
<https://lists.gnu.org/archive/html/guix-devel/2017-04/msg00464.html>.
* guix/ui.scm: Rename '_' to 'G_'.
* po/guix/Makevars (XGETTEXT_OPTIONS): Adjust accordingly.
* build-aux/compile-all.scm (warnings): Remove 'format'.
* gnu/packages.scm,
gnu/services.scm,
gnu/services/shepherd.scm,
gnu/system.scm,
gnu/system/shadow.scm,
guix/gnupg.scm,
guix/http-client.scm,
guix/import/cpan.scm,
guix/import/elpa.scm,
guix/import/pypi.scm,
guix/nar.scm,
guix/scripts.scm,
guix/scripts/archive.scm,
guix/scripts/authenticate.scm,
guix/scripts/build.scm,
guix/scripts/challenge.scm,
guix/scripts/container.scm,
guix/scripts/container/exec.scm,
guix/scripts/copy.scm,
guix/scripts/download.scm,
guix/scripts/edit.scm,
guix/scripts/environment.scm,
guix/scripts/gc.scm,
guix/scripts/graph.scm,
guix/scripts/hash.scm,
guix/scripts/import.scm,
guix/scripts/import/cpan.scm,
guix/scripts/import/cran.scm,
guix/scripts/import/crate.scm,
guix/scripts/import/elpa.scm,
guix/scripts/import/gem.scm,
guix/scripts/import/gnu.scm,
guix/scripts/import/hackage.scm,
guix/scripts/import/nix.scm,
guix/scripts/import/pypi.scm,
guix/scripts/import/stackage.scm,
guix/scripts/lint.scm,
guix/scripts/offload.scm,
guix/scripts/pack.scm,
guix/scripts/package.scm,
guix/scripts/perform-download.scm,
guix/scripts/publish.scm,
guix/scripts/pull.scm,
guix/scripts/refresh.scm,
guix/scripts/size.scm,
guix/scripts/substitute.scm,
guix/scripts/system.scm,
guix/ssh.scm,
guix/upstream.scm: Use 'G_' instead of '_'. Most of this change was
obtained by running: "sed -i -e's/(_ "/(G_ "/g' `find -name \*.scm`".
2017-05-03 15:57:02 +02:00
|
|
|
|
(G_ "derivation '~a' offloaded to '~a' failed: ~a~%")
|
2016-11-05 00:47:34 +01:00
|
|
|
|
(derivation-file-name drv)
|
|
|
|
|
(build-machine-name machine)
|
|
|
|
|
(nix-protocol-error-message c))
|
|
|
|
|
;; Use exit code 100 for a permanent build failure. The daemon
|
|
|
|
|
;; interprets other non-zero codes as transient build failures.
|
|
|
|
|
(primitive-exit 100)))
|
2016-12-06 00:50:08 +01:00
|
|
|
|
(parameterize ((current-build-output-port (build-log-port)))
|
|
|
|
|
(build-derivations store (list drv))))
|
2016-11-05 00:47:34 +01:00
|
|
|
|
|
2018-01-12 22:20:30 +01:00
|
|
|
|
(retrieve-files* outputs store
|
|
|
|
|
|
|
|
|
|
;; We cannot use the 'import-paths' RPC here because we
|
|
|
|
|
;; already hold the locks for FILES.
|
|
|
|
|
#:import
|
|
|
|
|
(lambda (port)
|
|
|
|
|
(restore-file-set port
|
|
|
|
|
#:log-port (current-error-port)
|
|
|
|
|
#:lock? #f)))
|
|
|
|
|
|
2016-11-05 00:47:34 +01:00
|
|
|
|
(format (current-error-port) "done with offloaded '~a'~%"
|
|
|
|
|
(derivation-file-name drv)))
|
|
|
|
|
|
2014-03-09 18:08:21 +01:00
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
;;; Scheduling.
|
|
|
|
|
;;;
|
|
|
|
|
|
2014-01-23 23:48:34 +01:00
|
|
|
|
(define (machine-matches? machine requirements)
|
|
|
|
|
"Return #t if MACHINE matches REQUIREMENTS."
|
|
|
|
|
(and (string=? (build-requirements-system requirements)
|
|
|
|
|
(build-machine-system machine))
|
|
|
|
|
(lset<= string=?
|
|
|
|
|
(build-requirements-features requirements)
|
|
|
|
|
(build-machine-features machine))))
|
|
|
|
|
|
2014-03-01 01:31:18 +01:00
|
|
|
|
(define (machine-load machine)
|
|
|
|
|
"Return the load of MACHINE, divided by the number of parallel builds
|
2016-12-01 23:21:15 +01:00
|
|
|
|
allowed on MACHINE. Return +∞ if MACHINE is unreachable."
|
2016-11-26 23:00:36 +01:00
|
|
|
|
;; Note: This procedure is costly since it creates a new SSH session.
|
2016-12-01 23:21:15 +01:00
|
|
|
|
(match (false-if-exception (open-ssh-session machine))
|
|
|
|
|
((? session? session)
|
|
|
|
|
(let* ((pipe (open-remote-pipe* session OPEN_READ
|
2016-11-25 22:47:37 +01:00
|
|
|
|
"cat" "/proc/loadavg"))
|
2016-12-01 23:21:15 +01:00
|
|
|
|
(line (read-line pipe)))
|
|
|
|
|
(close-port pipe)
|
2017-07-25 21:37:06 +02:00
|
|
|
|
(disconnect! session)
|
2016-12-01 23:21:15 +01:00
|
|
|
|
|
|
|
|
|
(if (eof-object? line)
|
|
|
|
|
+inf.0 ;MACHINE does not respond, so assume it is infinitely loaded
|
|
|
|
|
(match (string-tokenize line)
|
2017-04-21 17:18:54 +02:00
|
|
|
|
((one five fifteen . x)
|
2018-01-14 23:09:28 +01:00
|
|
|
|
(let* ((raw (string->number one))
|
2016-12-01 23:21:15 +01:00
|
|
|
|
(jobs (build-machine-parallel-builds machine))
|
|
|
|
|
(normalized (/ raw jobs)))
|
|
|
|
|
(format (current-error-port) "load on machine '~a' is ~s\
|
2014-03-01 01:31:18 +01:00
|
|
|
|
(normalized: ~s)~%"
|
2016-12-01 23:21:15 +01:00
|
|
|
|
(build-machine-name machine) raw normalized)
|
|
|
|
|
normalized))
|
2017-04-21 17:18:54 +02:00
|
|
|
|
(x
|
2016-12-01 23:21:15 +01:00
|
|
|
|
+inf.0))))) ;something's fishy about MACHINE, so avoid it
|
2017-04-21 17:18:54 +02:00
|
|
|
|
(x
|
2016-12-01 23:21:15 +01:00
|
|
|
|
+inf.0))) ;failed to connect to MACHINE, so avoid it
|
2014-03-01 01:31:18 +01:00
|
|
|
|
|
2014-03-08 11:29:52 +01:00
|
|
|
|
(define (machine-lock-file machine hint)
|
|
|
|
|
"Return the name of MACHINE's lock file for HINT."
|
2014-03-06 21:38:45 +01:00
|
|
|
|
(string-append %state-directory "/offload/"
|
2014-03-08 11:29:52 +01:00
|
|
|
|
(build-machine-name machine)
|
|
|
|
|
"." (symbol->string hint) ".lock"))
|
2014-03-06 21:38:45 +01:00
|
|
|
|
|
2014-03-08 12:15:38 +01:00
|
|
|
|
(define (machine-choice-lock-file)
|
|
|
|
|
"Return the name of the file used as a lock when choosing a build machine."
|
|
|
|
|
(string-append %state-directory "/offload/machine-choice.lock"))
|
|
|
|
|
|
2017-10-12 14:21:54 +02:00
|
|
|
|
(define (random-seed)
|
|
|
|
|
(logxor (getpid) (car (gettimeofday))))
|
|
|
|
|
|
|
|
|
|
(define shuffle
|
|
|
|
|
(let ((state (seed->random-state (random-seed))))
|
|
|
|
|
(lambda (lst)
|
|
|
|
|
"Return LST shuffled (using the Fisher-Yates algorithm.)"
|
|
|
|
|
(define vec (list->vector lst))
|
|
|
|
|
(let loop ((result '())
|
|
|
|
|
(i (vector-length vec)))
|
|
|
|
|
(if (zero? i)
|
|
|
|
|
result
|
|
|
|
|
(let* ((j (random i state))
|
|
|
|
|
(val (vector-ref vec j)))
|
|
|
|
|
(vector-set! vec j (vector-ref vec (- i 1)))
|
|
|
|
|
(loop (cons val result) (- i 1))))))))
|
|
|
|
|
|
2014-03-09 14:05:30 +01:00
|
|
|
|
(define (choose-build-machine machines)
|
2017-07-25 21:55:20 +02:00
|
|
|
|
"Return two values: the best machine among MACHINES and its build
|
|
|
|
|
slot (which must later be released with 'release-build-slot'), or #f and #f."
|
2014-03-08 12:15:38 +01:00
|
|
|
|
|
|
|
|
|
;; Proceed like this:
|
|
|
|
|
;; 1. Acquire the global machine-choice lock.
|
|
|
|
|
;; 2. For all MACHINES, attempt to acquire a build slot, and filter out
|
|
|
|
|
;; those machines for which we failed.
|
|
|
|
|
;; 3. Choose the best machine among those that are left.
|
|
|
|
|
;; 4. Release the previously-acquired build slots of the other machines.
|
|
|
|
|
;; 5. Release the global machine-choice lock.
|
|
|
|
|
|
|
|
|
|
(with-file-lock (machine-choice-lock-file)
|
2017-10-12 14:21:54 +02:00
|
|
|
|
(define machines+slots
|
2014-03-08 12:22:49 +01:00
|
|
|
|
(filter-map (lambda (machine)
|
|
|
|
|
(let ((slot (acquire-build-slot machine)))
|
2017-10-12 14:21:54 +02:00
|
|
|
|
(and slot (list machine slot))))
|
|
|
|
|
(shuffle machines)))
|
2014-03-08 12:15:38 +01:00
|
|
|
|
|
|
|
|
|
(define (undecorate pred)
|
2014-03-13 22:57:21 +01:00
|
|
|
|
(lambda (a b)
|
|
|
|
|
(match a
|
2017-10-12 14:21:54 +02:00
|
|
|
|
((machine1 slot1)
|
2014-03-13 22:57:21 +01:00
|
|
|
|
(match b
|
2017-10-12 14:21:54 +02:00
|
|
|
|
((machine2 slot2)
|
|
|
|
|
(pred machine1 machine2)))))))
|
|
|
|
|
|
|
|
|
|
(define (machine-faster? m1 m2)
|
|
|
|
|
;; Return #t if M1 is faster than M2.
|
|
|
|
|
(> (build-machine-speed m1)
|
|
|
|
|
(build-machine-speed m2)))
|
|
|
|
|
|
|
|
|
|
(let loop ((machines+slots
|
|
|
|
|
(sort machines+slots (undecorate machine-faster?))))
|
|
|
|
|
(match machines+slots
|
|
|
|
|
(((best slot) others ...)
|
2014-03-08 12:15:38 +01:00
|
|
|
|
;; Return the best machine unless it's already overloaded.
|
2017-10-12 14:21:54 +02:00
|
|
|
|
;; Note: We call 'machine-load' only as a last resort because it is
|
|
|
|
|
;; too costly to call it once for every machine.
|
|
|
|
|
(if (< (machine-load best) 2.)
|
2014-09-20 12:10:28 +02:00
|
|
|
|
(match others
|
2017-10-12 14:21:54 +02:00
|
|
|
|
(((machines slots) ...)
|
2014-09-20 12:10:28 +02:00
|
|
|
|
;; Release slots from the uninteresting machines.
|
|
|
|
|
(for-each release-build-slot slots)
|
|
|
|
|
|
2017-07-25 21:55:20 +02:00
|
|
|
|
;; The caller must keep SLOT to protect it from GC and to
|
|
|
|
|
;; eventually release it.
|
|
|
|
|
(values best slot)))
|
2014-03-08 21:23:12 +01:00
|
|
|
|
(begin
|
2014-09-20 12:10:28 +02:00
|
|
|
|
;; BEST is overloaded, so try the next one.
|
2014-03-08 12:15:38 +01:00
|
|
|
|
(release-build-slot slot)
|
2014-09-20 12:10:28 +02:00
|
|
|
|
(loop others))))
|
2017-07-25 21:55:20 +02:00
|
|
|
|
(()
|
|
|
|
|
(values #f #f))))))
|
2014-01-23 23:48:34 +01:00
|
|
|
|
|
2018-06-11 11:42:59 +02:00
|
|
|
|
(define (call-with-timeout timeout drv thunk)
|
|
|
|
|
"Call THUNK and leave after TIMEOUT seconds. If TIMEOUT is #f, simply call
|
|
|
|
|
THUNK. Use DRV as an indication of what we were building when the timeout
|
|
|
|
|
expired."
|
|
|
|
|
(if (number? timeout)
|
|
|
|
|
(dynamic-wind
|
|
|
|
|
(lambda ()
|
|
|
|
|
(sigaction SIGALRM
|
|
|
|
|
(lambda _
|
|
|
|
|
;; The exit code here will be 1, which guix-daemon will
|
|
|
|
|
;; interpret as a transient failure.
|
|
|
|
|
(leave (G_ "timeout expired while offloading '~a'~%")
|
|
|
|
|
(derivation-file-name drv))))
|
|
|
|
|
(alarm timeout))
|
|
|
|
|
thunk
|
|
|
|
|
(lambda ()
|
|
|
|
|
(alarm 0)))
|
|
|
|
|
(thunk)))
|
|
|
|
|
|
|
|
|
|
(define-syntax-rule (with-timeout timeout drv exp ...)
|
|
|
|
|
"Evaluate EXP... and leave after TIMEOUT seconds if EXP hasn't completed.
|
|
|
|
|
If TIMEOUT is #f, simply evaluate EXP..."
|
|
|
|
|
(call-with-timeout timeout drv (lambda () exp ...)))
|
|
|
|
|
|
2014-01-23 23:48:34 +01:00
|
|
|
|
(define* (process-request wants-local? system drv features
|
|
|
|
|
#:key
|
|
|
|
|
print-build-trace? (max-silent-time 3600)
|
2014-03-09 23:13:53 +01:00
|
|
|
|
build-timeout)
|
2014-01-23 23:48:34 +01:00
|
|
|
|
"Process a request to build DRV."
|
2014-03-09 14:05:30 +01:00
|
|
|
|
(let* ((local? (and wants-local? (string=? system (%current-system))))
|
|
|
|
|
(reqs (build-requirements
|
|
|
|
|
(system system)
|
|
|
|
|
(features features)))
|
|
|
|
|
(candidates (filter (cut machine-matches? <> reqs)
|
|
|
|
|
(build-machines))))
|
|
|
|
|
(match candidates
|
|
|
|
|
(()
|
|
|
|
|
;; We'll never be able to match REQS.
|
|
|
|
|
(display "# decline\n"))
|
2017-04-21 17:18:54 +02:00
|
|
|
|
((x ...)
|
2017-07-25 21:55:20 +02:00
|
|
|
|
(let-values (((machine slot)
|
|
|
|
|
(choose-build-machine candidates)))
|
2014-03-09 14:05:30 +01:00
|
|
|
|
(if machine
|
2017-07-25 21:55:20 +02:00
|
|
|
|
(dynamic-wind
|
|
|
|
|
(const #f)
|
|
|
|
|
(lambda ()
|
|
|
|
|
;; Offload DRV to MACHINE.
|
|
|
|
|
(display "# accept\n")
|
|
|
|
|
(let ((inputs (string-tokenize (read-line)))
|
|
|
|
|
(outputs (string-tokenize (read-line))))
|
2018-06-11 11:42:59 +02:00
|
|
|
|
;; Even if BUILD-TIMEOUT is honored by MACHINE, there can
|
|
|
|
|
;; be issues with the connection or deadlocks that could
|
|
|
|
|
;; lead the 'guix offload' process to remain stuck forever.
|
|
|
|
|
;; To avoid that, install a timeout here as well.
|
|
|
|
|
(with-timeout build-timeout drv
|
|
|
|
|
(transfer-and-offload drv machine
|
|
|
|
|
#:inputs inputs
|
|
|
|
|
#:outputs outputs
|
|
|
|
|
#:max-silent-time max-silent-time
|
|
|
|
|
#:build-timeout build-timeout
|
|
|
|
|
#:print-build-trace?
|
|
|
|
|
print-build-trace?))))
|
2017-07-25 21:55:20 +02:00
|
|
|
|
(lambda ()
|
|
|
|
|
(release-build-slot slot)))
|
2014-03-09 14:05:30 +01:00
|
|
|
|
|
|
|
|
|
;; Not now, all the machines are busy.
|
|
|
|
|
(display "# postpone\n")))))))
|
2014-01-23 23:48:34 +01:00
|
|
|
|
|
2016-12-05 18:16:04 +01:00
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
;;; Installation tests.
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
(define (assert-node-repl node name)
|
|
|
|
|
"Bail out if NODE is not running Guile."
|
|
|
|
|
(match (node-guile-version node)
|
|
|
|
|
(#f
|
2018-01-12 23:16:53 +01:00
|
|
|
|
(report-guile-error name))
|
2016-12-05 18:16:04 +01:00
|
|
|
|
((? string? version)
|
|
|
|
|
;; Note: The version string already contains the word "Guile".
|
ui: Rename '_' to 'G_'.
This avoids collisions with '_' when the latter is used as a 'match'
pattern for instance. See
<https://lists.gnu.org/archive/html/guix-devel/2017-04/msg00464.html>.
* guix/ui.scm: Rename '_' to 'G_'.
* po/guix/Makevars (XGETTEXT_OPTIONS): Adjust accordingly.
* build-aux/compile-all.scm (warnings): Remove 'format'.
* gnu/packages.scm,
gnu/services.scm,
gnu/services/shepherd.scm,
gnu/system.scm,
gnu/system/shadow.scm,
guix/gnupg.scm,
guix/http-client.scm,
guix/import/cpan.scm,
guix/import/elpa.scm,
guix/import/pypi.scm,
guix/nar.scm,
guix/scripts.scm,
guix/scripts/archive.scm,
guix/scripts/authenticate.scm,
guix/scripts/build.scm,
guix/scripts/challenge.scm,
guix/scripts/container.scm,
guix/scripts/container/exec.scm,
guix/scripts/copy.scm,
guix/scripts/download.scm,
guix/scripts/edit.scm,
guix/scripts/environment.scm,
guix/scripts/gc.scm,
guix/scripts/graph.scm,
guix/scripts/hash.scm,
guix/scripts/import.scm,
guix/scripts/import/cpan.scm,
guix/scripts/import/cran.scm,
guix/scripts/import/crate.scm,
guix/scripts/import/elpa.scm,
guix/scripts/import/gem.scm,
guix/scripts/import/gnu.scm,
guix/scripts/import/hackage.scm,
guix/scripts/import/nix.scm,
guix/scripts/import/pypi.scm,
guix/scripts/import/stackage.scm,
guix/scripts/lint.scm,
guix/scripts/offload.scm,
guix/scripts/pack.scm,
guix/scripts/package.scm,
guix/scripts/perform-download.scm,
guix/scripts/publish.scm,
guix/scripts/pull.scm,
guix/scripts/refresh.scm,
guix/scripts/size.scm,
guix/scripts/substitute.scm,
guix/scripts/system.scm,
guix/ssh.scm,
guix/upstream.scm: Use 'G_' instead of '_'. Most of this change was
obtained by running: "sed -i -e's/(_ "/(G_ "/g' `find -name \*.scm`".
2017-05-03 15:57:02 +02:00
|
|
|
|
(info (G_ "'~a' is running ~a~%")
|
2016-12-05 18:16:04 +01:00
|
|
|
|
name (node-guile-version node)))))
|
|
|
|
|
|
|
|
|
|
(define (assert-node-has-guix node name)
|
|
|
|
|
"Bail out if NODE lacks the (guix) module, or if its daemon is not running."
|
2018-01-12 23:16:53 +01:00
|
|
|
|
(catch 'node-repl-error
|
|
|
|
|
(lambda ()
|
|
|
|
|
(match (node-eval node
|
|
|
|
|
'(begin
|
|
|
|
|
(use-modules (guix))
|
|
|
|
|
(and add-text-to-store 'alright)))
|
|
|
|
|
('alright #t)
|
|
|
|
|
(_ (report-module-error name))))
|
|
|
|
|
(lambda (key . args)
|
|
|
|
|
(report-module-error name)))
|
|
|
|
|
|
2018-01-12 22:51:41 +01:00
|
|
|
|
(catch 'node-repl-error
|
|
|
|
|
(lambda ()
|
|
|
|
|
(match (node-eval node
|
|
|
|
|
'(begin
|
|
|
|
|
(use-modules (guix))
|
|
|
|
|
(with-store store
|
|
|
|
|
(add-text-to-store store "test"
|
|
|
|
|
"Hello, build machine!"))))
|
|
|
|
|
((? string? str)
|
|
|
|
|
(info (G_ "Guix is usable on '~a' (test returned ~s)~%")
|
|
|
|
|
name str))
|
|
|
|
|
(x
|
2018-01-12 23:16:53 +01:00
|
|
|
|
(leave (G_ "failed to talk to guix-daemon on '~a' (test returned ~s)~%")
|
2018-01-12 22:51:41 +01:00
|
|
|
|
name x))))
|
|
|
|
|
(lambda (key . args)
|
2018-06-15 09:02:01 +02:00
|
|
|
|
(leave (G_ "remote evaluation on '~a' failed:~{ ~s~}~%")
|
|
|
|
|
name args))))
|
2016-12-05 18:16:04 +01:00
|
|
|
|
|
|
|
|
|
(define %random-state
|
|
|
|
|
(delay
|
|
|
|
|
(seed->random-state (logxor (getpid) (car (gettimeofday))))))
|
|
|
|
|
|
2016-12-30 23:22:27 +01:00
|
|
|
|
(define* (nonce #:optional (name (gethostname)))
|
|
|
|
|
(string-append name "-"
|
2016-12-05 18:16:04 +01:00
|
|
|
|
(number->string (random 1000000 (force %random-state)))))
|
|
|
|
|
|
|
|
|
|
(define (assert-node-can-import node name daemon-socket)
|
|
|
|
|
"Bail out if NODE refuses to import our archives."
|
|
|
|
|
(let ((session (node-session node)))
|
|
|
|
|
(with-store store
|
|
|
|
|
(let* ((item (add-text-to-store store "export-test" (nonce)))
|
|
|
|
|
(remote (connect-to-remote-daemon session daemon-socket)))
|
2016-12-30 23:22:27 +01:00
|
|
|
|
(with-store local
|
|
|
|
|
(send-files local (list item) remote))
|
|
|
|
|
|
2016-12-05 18:16:04 +01:00
|
|
|
|
(if (valid-path? remote item)
|
ui: Rename '_' to 'G_'.
This avoids collisions with '_' when the latter is used as a 'match'
pattern for instance. See
<https://lists.gnu.org/archive/html/guix-devel/2017-04/msg00464.html>.
* guix/ui.scm: Rename '_' to 'G_'.
* po/guix/Makevars (XGETTEXT_OPTIONS): Adjust accordingly.
* build-aux/compile-all.scm (warnings): Remove 'format'.
* gnu/packages.scm,
gnu/services.scm,
gnu/services/shepherd.scm,
gnu/system.scm,
gnu/system/shadow.scm,
guix/gnupg.scm,
guix/http-client.scm,
guix/import/cpan.scm,
guix/import/elpa.scm,
guix/import/pypi.scm,
guix/nar.scm,
guix/scripts.scm,
guix/scripts/archive.scm,
guix/scripts/authenticate.scm,
guix/scripts/build.scm,
guix/scripts/challenge.scm,
guix/scripts/container.scm,
guix/scripts/container/exec.scm,
guix/scripts/copy.scm,
guix/scripts/download.scm,
guix/scripts/edit.scm,
guix/scripts/environment.scm,
guix/scripts/gc.scm,
guix/scripts/graph.scm,
guix/scripts/hash.scm,
guix/scripts/import.scm,
guix/scripts/import/cpan.scm,
guix/scripts/import/cran.scm,
guix/scripts/import/crate.scm,
guix/scripts/import/elpa.scm,
guix/scripts/import/gem.scm,
guix/scripts/import/gnu.scm,
guix/scripts/import/hackage.scm,
guix/scripts/import/nix.scm,
guix/scripts/import/pypi.scm,
guix/scripts/import/stackage.scm,
guix/scripts/lint.scm,
guix/scripts/offload.scm,
guix/scripts/pack.scm,
guix/scripts/package.scm,
guix/scripts/perform-download.scm,
guix/scripts/publish.scm,
guix/scripts/pull.scm,
guix/scripts/refresh.scm,
guix/scripts/size.scm,
guix/scripts/substitute.scm,
guix/scripts/system.scm,
guix/ssh.scm,
guix/upstream.scm: Use 'G_' instead of '_'. Most of this change was
obtained by running: "sed -i -e's/(_ "/(G_ "/g' `find -name \*.scm`".
2017-05-03 15:57:02 +02:00
|
|
|
|
(info (G_ "'~a' successfully imported '~a'~%")
|
2016-12-05 18:16:04 +01:00
|
|
|
|
name item)
|
ui: Rename '_' to 'G_'.
This avoids collisions with '_' when the latter is used as a 'match'
pattern for instance. See
<https://lists.gnu.org/archive/html/guix-devel/2017-04/msg00464.html>.
* guix/ui.scm: Rename '_' to 'G_'.
* po/guix/Makevars (XGETTEXT_OPTIONS): Adjust accordingly.
* build-aux/compile-all.scm (warnings): Remove 'format'.
* gnu/packages.scm,
gnu/services.scm,
gnu/services/shepherd.scm,
gnu/system.scm,
gnu/system/shadow.scm,
guix/gnupg.scm,
guix/http-client.scm,
guix/import/cpan.scm,
guix/import/elpa.scm,
guix/import/pypi.scm,
guix/nar.scm,
guix/scripts.scm,
guix/scripts/archive.scm,
guix/scripts/authenticate.scm,
guix/scripts/build.scm,
guix/scripts/challenge.scm,
guix/scripts/container.scm,
guix/scripts/container/exec.scm,
guix/scripts/copy.scm,
guix/scripts/download.scm,
guix/scripts/edit.scm,
guix/scripts/environment.scm,
guix/scripts/gc.scm,
guix/scripts/graph.scm,
guix/scripts/hash.scm,
guix/scripts/import.scm,
guix/scripts/import/cpan.scm,
guix/scripts/import/cran.scm,
guix/scripts/import/crate.scm,
guix/scripts/import/elpa.scm,
guix/scripts/import/gem.scm,
guix/scripts/import/gnu.scm,
guix/scripts/import/hackage.scm,
guix/scripts/import/nix.scm,
guix/scripts/import/pypi.scm,
guix/scripts/import/stackage.scm,
guix/scripts/lint.scm,
guix/scripts/offload.scm,
guix/scripts/pack.scm,
guix/scripts/package.scm,
guix/scripts/perform-download.scm,
guix/scripts/publish.scm,
guix/scripts/pull.scm,
guix/scripts/refresh.scm,
guix/scripts/size.scm,
guix/scripts/substitute.scm,
guix/scripts/system.scm,
guix/ssh.scm,
guix/upstream.scm: Use 'G_' instead of '_'. Most of this change was
obtained by running: "sed -i -e's/(_ "/(G_ "/g' `find -name \*.scm`".
2017-05-03 15:57:02 +02:00
|
|
|
|
(leave (G_ "'~a' was not properly imported on '~a'~%")
|
2016-12-05 18:16:04 +01:00
|
|
|
|
item name))))))
|
|
|
|
|
|
|
|
|
|
(define (assert-node-can-export node name daemon-socket)
|
|
|
|
|
"Bail out if we cannot import signed archives from NODE."
|
|
|
|
|
(let* ((session (node-session node))
|
|
|
|
|
(remote (connect-to-remote-daemon session daemon-socket))
|
2016-12-30 23:22:27 +01:00
|
|
|
|
(item (add-text-to-store remote "import-test" (nonce name))))
|
2016-12-05 18:16:04 +01:00
|
|
|
|
(with-store store
|
2016-12-30 23:22:27 +01:00
|
|
|
|
(if (and (retrieve-files store (list item) remote)
|
2016-12-05 18:16:04 +01:00
|
|
|
|
(valid-path? store item))
|
ui: Rename '_' to 'G_'.
This avoids collisions with '_' when the latter is used as a 'match'
pattern for instance. See
<https://lists.gnu.org/archive/html/guix-devel/2017-04/msg00464.html>.
* guix/ui.scm: Rename '_' to 'G_'.
* po/guix/Makevars (XGETTEXT_OPTIONS): Adjust accordingly.
* build-aux/compile-all.scm (warnings): Remove 'format'.
* gnu/packages.scm,
gnu/services.scm,
gnu/services/shepherd.scm,
gnu/system.scm,
gnu/system/shadow.scm,
guix/gnupg.scm,
guix/http-client.scm,
guix/import/cpan.scm,
guix/import/elpa.scm,
guix/import/pypi.scm,
guix/nar.scm,
guix/scripts.scm,
guix/scripts/archive.scm,
guix/scripts/authenticate.scm,
guix/scripts/build.scm,
guix/scripts/challenge.scm,
guix/scripts/container.scm,
guix/scripts/container/exec.scm,
guix/scripts/copy.scm,
guix/scripts/download.scm,
guix/scripts/edit.scm,
guix/scripts/environment.scm,
guix/scripts/gc.scm,
guix/scripts/graph.scm,
guix/scripts/hash.scm,
guix/scripts/import.scm,
guix/scripts/import/cpan.scm,
guix/scripts/import/cran.scm,
guix/scripts/import/crate.scm,
guix/scripts/import/elpa.scm,
guix/scripts/import/gem.scm,
guix/scripts/import/gnu.scm,
guix/scripts/import/hackage.scm,
guix/scripts/import/nix.scm,
guix/scripts/import/pypi.scm,
guix/scripts/import/stackage.scm,
guix/scripts/lint.scm,
guix/scripts/offload.scm,
guix/scripts/pack.scm,
guix/scripts/package.scm,
guix/scripts/perform-download.scm,
guix/scripts/publish.scm,
guix/scripts/pull.scm,
guix/scripts/refresh.scm,
guix/scripts/size.scm,
guix/scripts/substitute.scm,
guix/scripts/system.scm,
guix/ssh.scm,
guix/upstream.scm: Use 'G_' instead of '_'. Most of this change was
obtained by running: "sed -i -e's/(_ "/(G_ "/g' `find -name \*.scm`".
2017-05-03 15:57:02 +02:00
|
|
|
|
(info (G_ "successfully imported '~a' from '~a'~%")
|
2016-12-05 18:16:04 +01:00
|
|
|
|
item name)
|
ui: Rename '_' to 'G_'.
This avoids collisions with '_' when the latter is used as a 'match'
pattern for instance. See
<https://lists.gnu.org/archive/html/guix-devel/2017-04/msg00464.html>.
* guix/ui.scm: Rename '_' to 'G_'.
* po/guix/Makevars (XGETTEXT_OPTIONS): Adjust accordingly.
* build-aux/compile-all.scm (warnings): Remove 'format'.
* gnu/packages.scm,
gnu/services.scm,
gnu/services/shepherd.scm,
gnu/system.scm,
gnu/system/shadow.scm,
guix/gnupg.scm,
guix/http-client.scm,
guix/import/cpan.scm,
guix/import/elpa.scm,
guix/import/pypi.scm,
guix/nar.scm,
guix/scripts.scm,
guix/scripts/archive.scm,
guix/scripts/authenticate.scm,
guix/scripts/build.scm,
guix/scripts/challenge.scm,
guix/scripts/container.scm,
guix/scripts/container/exec.scm,
guix/scripts/copy.scm,
guix/scripts/download.scm,
guix/scripts/edit.scm,
guix/scripts/environment.scm,
guix/scripts/gc.scm,
guix/scripts/graph.scm,
guix/scripts/hash.scm,
guix/scripts/import.scm,
guix/scripts/import/cpan.scm,
guix/scripts/import/cran.scm,
guix/scripts/import/crate.scm,
guix/scripts/import/elpa.scm,
guix/scripts/import/gem.scm,
guix/scripts/import/gnu.scm,
guix/scripts/import/hackage.scm,
guix/scripts/import/nix.scm,
guix/scripts/import/pypi.scm,
guix/scripts/import/stackage.scm,
guix/scripts/lint.scm,
guix/scripts/offload.scm,
guix/scripts/pack.scm,
guix/scripts/package.scm,
guix/scripts/perform-download.scm,
guix/scripts/publish.scm,
guix/scripts/pull.scm,
guix/scripts/refresh.scm,
guix/scripts/size.scm,
guix/scripts/substitute.scm,
guix/scripts/system.scm,
guix/ssh.scm,
guix/upstream.scm: Use 'G_' instead of '_'. Most of this change was
obtained by running: "sed -i -e's/(_ "/(G_ "/g' `find -name \*.scm`".
2017-05-03 15:57:02 +02:00
|
|
|
|
(leave (G_ "failed to import '~a' from '~a'~%")
|
2016-12-05 18:16:04 +01:00
|
|
|
|
item name)))))
|
|
|
|
|
|
2016-12-09 23:12:06 +01:00
|
|
|
|
(define (check-machine-availability machine-file pred)
|
|
|
|
|
"Check that each machine matching PRED in MACHINE-FILE is usable as a build
|
|
|
|
|
machine."
|
2016-12-09 23:00:08 +01:00
|
|
|
|
(define (build-machine=? m1 m2)
|
|
|
|
|
(and (string=? (build-machine-name m1) (build-machine-name m2))
|
|
|
|
|
(= (build-machine-port m1) (build-machine-port m2))))
|
|
|
|
|
|
|
|
|
|
;; A given build machine may appear several times (e.g., once for
|
|
|
|
|
;; "x86_64-linux" and a second time for "i686-linux"); test them only once.
|
2016-12-09 23:12:06 +01:00
|
|
|
|
(let ((machines (filter pred
|
|
|
|
|
(delete-duplicates (build-machines machine-file)
|
|
|
|
|
build-machine=?))))
|
ui: Rename '_' to 'G_'.
This avoids collisions with '_' when the latter is used as a 'match'
pattern for instance. See
<https://lists.gnu.org/archive/html/guix-devel/2017-04/msg00464.html>.
* guix/ui.scm: Rename '_' to 'G_'.
* po/guix/Makevars (XGETTEXT_OPTIONS): Adjust accordingly.
* build-aux/compile-all.scm (warnings): Remove 'format'.
* gnu/packages.scm,
gnu/services.scm,
gnu/services/shepherd.scm,
gnu/system.scm,
gnu/system/shadow.scm,
guix/gnupg.scm,
guix/http-client.scm,
guix/import/cpan.scm,
guix/import/elpa.scm,
guix/import/pypi.scm,
guix/nar.scm,
guix/scripts.scm,
guix/scripts/archive.scm,
guix/scripts/authenticate.scm,
guix/scripts/build.scm,
guix/scripts/challenge.scm,
guix/scripts/container.scm,
guix/scripts/container/exec.scm,
guix/scripts/copy.scm,
guix/scripts/download.scm,
guix/scripts/edit.scm,
guix/scripts/environment.scm,
guix/scripts/gc.scm,
guix/scripts/graph.scm,
guix/scripts/hash.scm,
guix/scripts/import.scm,
guix/scripts/import/cpan.scm,
guix/scripts/import/cran.scm,
guix/scripts/import/crate.scm,
guix/scripts/import/elpa.scm,
guix/scripts/import/gem.scm,
guix/scripts/import/gnu.scm,
guix/scripts/import/hackage.scm,
guix/scripts/import/nix.scm,
guix/scripts/import/pypi.scm,
guix/scripts/import/stackage.scm,
guix/scripts/lint.scm,
guix/scripts/offload.scm,
guix/scripts/pack.scm,
guix/scripts/package.scm,
guix/scripts/perform-download.scm,
guix/scripts/publish.scm,
guix/scripts/pull.scm,
guix/scripts/refresh.scm,
guix/scripts/size.scm,
guix/scripts/substitute.scm,
guix/scripts/system.scm,
guix/ssh.scm,
guix/upstream.scm: Use 'G_' instead of '_'. Most of this change was
obtained by running: "sed -i -e's/(_ "/(G_ "/g' `find -name \*.scm`".
2017-05-03 15:57:02 +02:00
|
|
|
|
(info (G_ "testing ~a build machines defined in '~a'...~%")
|
2016-12-05 18:16:04 +01:00
|
|
|
|
(length machines) machine-file)
|
|
|
|
|
(let* ((names (map build-machine-name machines))
|
|
|
|
|
(sockets (map build-machine-daemon-socket machines))
|
|
|
|
|
(sessions (map open-ssh-session machines))
|
|
|
|
|
(nodes (map make-node sessions)))
|
|
|
|
|
(for-each assert-node-repl nodes names)
|
|
|
|
|
(for-each assert-node-has-guix nodes names)
|
|
|
|
|
(for-each assert-node-can-import nodes names sockets)
|
|
|
|
|
(for-each assert-node-can-export nodes names sockets))))
|
|
|
|
|
|
2017-12-13 23:42:40 +01:00
|
|
|
|
(define (check-machine-status machine-file pred)
|
|
|
|
|
"Print the load of each machine matching PRED in MACHINE-FILE."
|
|
|
|
|
(define (build-machine=? m1 m2)
|
|
|
|
|
(and (string=? (build-machine-name m1) (build-machine-name m2))
|
|
|
|
|
(= (build-machine-port m1) (build-machine-port m2))))
|
|
|
|
|
|
|
|
|
|
;; A given build machine may appear several times (e.g., once for
|
|
|
|
|
;; "x86_64-linux" and a second time for "i686-linux"); test them only once.
|
|
|
|
|
(let ((machines (filter pred
|
|
|
|
|
(delete-duplicates (build-machines machine-file)
|
|
|
|
|
build-machine=?))))
|
|
|
|
|
(info (G_ "getting status of ~a build machines defined in '~a'...~%")
|
|
|
|
|
(length machines) machine-file)
|
|
|
|
|
(for-each (lambda (machine)
|
|
|
|
|
(let* ((node (make-node (open-ssh-session machine)))
|
|
|
|
|
(uts (node-eval node '(uname))))
|
|
|
|
|
(format #t "~a~% kernel: ~a ~a~% architecture: ~a~%\
|
|
|
|
|
host name: ~a~% normalized load: ~a~%"
|
|
|
|
|
(build-machine-name machine)
|
|
|
|
|
(utsname:sysname uts) (utsname:release uts)
|
|
|
|
|
(utsname:machine uts)
|
|
|
|
|
(utsname:nodename uts)
|
|
|
|
|
(parameterize ((current-error-port (%make-void-port "rw+")))
|
|
|
|
|
(machine-load machine)))))
|
|
|
|
|
machines)))
|
|
|
|
|
|
2014-01-23 23:48:34 +01:00
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
;;; Entry point.
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
(define (guix-offload . args)
|
|
|
|
|
(define request-line-rx
|
|
|
|
|
;; The request format. See 'tryBuildHook' method in build.cc.
|
|
|
|
|
(make-regexp "([01]) ([a-z0-9_-]+) (/[[:graph:]]+.drv) ([[:graph:]]*)"))
|
|
|
|
|
|
|
|
|
|
(define not-coma
|
|
|
|
|
(char-set-complement (char-set #\,)))
|
|
|
|
|
|
|
|
|
|
;; Make sure $HOME really corresponds to the current user. This is
|
|
|
|
|
;; necessary since lsh uses that to determine the location of the yarrow
|
|
|
|
|
;; seed file, and fails if it's owned by someone else.
|
|
|
|
|
(and=> (passwd:dir (getpw (getuid)))
|
|
|
|
|
(cut setenv "HOME" <>))
|
|
|
|
|
|
2016-12-01 21:49:16 +01:00
|
|
|
|
;; We rely on protocol-level compression from libssh to optimize large data
|
|
|
|
|
;; transfers. Warn if it's missing.
|
|
|
|
|
(unless (zlib-support?)
|
ui: Rename '_' to 'G_'.
This avoids collisions with '_' when the latter is used as a 'match'
pattern for instance. See
<https://lists.gnu.org/archive/html/guix-devel/2017-04/msg00464.html>.
* guix/ui.scm: Rename '_' to 'G_'.
* po/guix/Makevars (XGETTEXT_OPTIONS): Adjust accordingly.
* build-aux/compile-all.scm (warnings): Remove 'format'.
* gnu/packages.scm,
gnu/services.scm,
gnu/services/shepherd.scm,
gnu/system.scm,
gnu/system/shadow.scm,
guix/gnupg.scm,
guix/http-client.scm,
guix/import/cpan.scm,
guix/import/elpa.scm,
guix/import/pypi.scm,
guix/nar.scm,
guix/scripts.scm,
guix/scripts/archive.scm,
guix/scripts/authenticate.scm,
guix/scripts/build.scm,
guix/scripts/challenge.scm,
guix/scripts/container.scm,
guix/scripts/container/exec.scm,
guix/scripts/copy.scm,
guix/scripts/download.scm,
guix/scripts/edit.scm,
guix/scripts/environment.scm,
guix/scripts/gc.scm,
guix/scripts/graph.scm,
guix/scripts/hash.scm,
guix/scripts/import.scm,
guix/scripts/import/cpan.scm,
guix/scripts/import/cran.scm,
guix/scripts/import/crate.scm,
guix/scripts/import/elpa.scm,
guix/scripts/import/gem.scm,
guix/scripts/import/gnu.scm,
guix/scripts/import/hackage.scm,
guix/scripts/import/nix.scm,
guix/scripts/import/pypi.scm,
guix/scripts/import/stackage.scm,
guix/scripts/lint.scm,
guix/scripts/offload.scm,
guix/scripts/pack.scm,
guix/scripts/package.scm,
guix/scripts/perform-download.scm,
guix/scripts/publish.scm,
guix/scripts/pull.scm,
guix/scripts/refresh.scm,
guix/scripts/size.scm,
guix/scripts/substitute.scm,
guix/scripts/system.scm,
guix/ssh.scm,
guix/upstream.scm: Use 'G_' instead of '_'. Most of this change was
obtained by running: "sed -i -e's/(_ "/(G_ "/g' `find -name \*.scm`".
2017-05-03 15:57:02 +02:00
|
|
|
|
(warning (G_ "Guile-SSH lacks zlib support"))
|
|
|
|
|
(warning (G_ "data transfers will *not* be compressed!")))
|
2016-12-01 21:49:16 +01:00
|
|
|
|
|
2014-01-23 23:48:34 +01:00
|
|
|
|
(match args
|
|
|
|
|
((system max-silent-time print-build-trace? build-timeout)
|
|
|
|
|
(let ((max-silent-time (string->number max-silent-time))
|
|
|
|
|
(build-timeout (string->number build-timeout))
|
|
|
|
|
(print-build-trace? (string=? print-build-trace? "1")))
|
2017-05-28 16:09:32 +02:00
|
|
|
|
(set-thread-name "guix offload")
|
2014-01-23 23:48:34 +01:00
|
|
|
|
(parameterize ((%current-system system))
|
|
|
|
|
(let loop ((line (read-line)))
|
|
|
|
|
(unless (eof-object? line)
|
|
|
|
|
(cond ((regexp-exec request-line-rx line)
|
|
|
|
|
=>
|
|
|
|
|
(lambda (match)
|
2016-11-05 00:46:04 +01:00
|
|
|
|
(with-error-handling
|
2014-01-23 23:48:34 +01:00
|
|
|
|
(process-request (equal? (match:substring match 1) "1")
|
|
|
|
|
(match:substring match 2) ; system
|
2017-06-12 17:11:22 +02:00
|
|
|
|
(read-derivation-from-file
|
|
|
|
|
(match:substring match 3))
|
2014-01-23 23:48:34 +01:00
|
|
|
|
(string-tokenize
|
|
|
|
|
(match:substring match 4) not-coma)
|
|
|
|
|
#:print-build-trace? print-build-trace?
|
|
|
|
|
#:max-silent-time max-silent-time
|
|
|
|
|
#:build-timeout build-timeout))))
|
|
|
|
|
(else
|
ui: Rename '_' to 'G_'.
This avoids collisions with '_' when the latter is used as a 'match'
pattern for instance. See
<https://lists.gnu.org/archive/html/guix-devel/2017-04/msg00464.html>.
* guix/ui.scm: Rename '_' to 'G_'.
* po/guix/Makevars (XGETTEXT_OPTIONS): Adjust accordingly.
* build-aux/compile-all.scm (warnings): Remove 'format'.
* gnu/packages.scm,
gnu/services.scm,
gnu/services/shepherd.scm,
gnu/system.scm,
gnu/system/shadow.scm,
guix/gnupg.scm,
guix/http-client.scm,
guix/import/cpan.scm,
guix/import/elpa.scm,
guix/import/pypi.scm,
guix/nar.scm,
guix/scripts.scm,
guix/scripts/archive.scm,
guix/scripts/authenticate.scm,
guix/scripts/build.scm,
guix/scripts/challenge.scm,
guix/scripts/container.scm,
guix/scripts/container/exec.scm,
guix/scripts/copy.scm,
guix/scripts/download.scm,
guix/scripts/edit.scm,
guix/scripts/environment.scm,
guix/scripts/gc.scm,
guix/scripts/graph.scm,
guix/scripts/hash.scm,
guix/scripts/import.scm,
guix/scripts/import/cpan.scm,
guix/scripts/import/cran.scm,
guix/scripts/import/crate.scm,
guix/scripts/import/elpa.scm,
guix/scripts/import/gem.scm,
guix/scripts/import/gnu.scm,
guix/scripts/import/hackage.scm,
guix/scripts/import/nix.scm,
guix/scripts/import/pypi.scm,
guix/scripts/import/stackage.scm,
guix/scripts/lint.scm,
guix/scripts/offload.scm,
guix/scripts/pack.scm,
guix/scripts/package.scm,
guix/scripts/perform-download.scm,
guix/scripts/publish.scm,
guix/scripts/pull.scm,
guix/scripts/refresh.scm,
guix/scripts/size.scm,
guix/scripts/substitute.scm,
guix/scripts/system.scm,
guix/ssh.scm,
guix/upstream.scm: Use 'G_' instead of '_'. Most of this change was
obtained by running: "sed -i -e's/(_ "/(G_ "/g' `find -name \*.scm`".
2017-05-03 15:57:02 +02:00
|
|
|
|
(leave (G_ "invalid request line: ~s~%") line)))
|
2014-01-23 23:48:34 +01:00
|
|
|
|
(loop (read-line)))))))
|
2016-12-05 18:16:04 +01:00
|
|
|
|
(("test" rest ...)
|
|
|
|
|
(with-error-handling
|
2016-12-09 23:12:06 +01:00
|
|
|
|
(let-values (((file pred)
|
|
|
|
|
(match rest
|
|
|
|
|
((file regexp)
|
|
|
|
|
(values file
|
|
|
|
|
(compose (cut string-match regexp <>)
|
|
|
|
|
build-machine-name)))
|
|
|
|
|
((file) (values file (const #t)))
|
|
|
|
|
(() (values %machine-file (const #t)))
|
ui: Rename '_' to 'G_'.
This avoids collisions with '_' when the latter is used as a 'match'
pattern for instance. See
<https://lists.gnu.org/archive/html/guix-devel/2017-04/msg00464.html>.
* guix/ui.scm: Rename '_' to 'G_'.
* po/guix/Makevars (XGETTEXT_OPTIONS): Adjust accordingly.
* build-aux/compile-all.scm (warnings): Remove 'format'.
* gnu/packages.scm,
gnu/services.scm,
gnu/services/shepherd.scm,
gnu/system.scm,
gnu/system/shadow.scm,
guix/gnupg.scm,
guix/http-client.scm,
guix/import/cpan.scm,
guix/import/elpa.scm,
guix/import/pypi.scm,
guix/nar.scm,
guix/scripts.scm,
guix/scripts/archive.scm,
guix/scripts/authenticate.scm,
guix/scripts/build.scm,
guix/scripts/challenge.scm,
guix/scripts/container.scm,
guix/scripts/container/exec.scm,
guix/scripts/copy.scm,
guix/scripts/download.scm,
guix/scripts/edit.scm,
guix/scripts/environment.scm,
guix/scripts/gc.scm,
guix/scripts/graph.scm,
guix/scripts/hash.scm,
guix/scripts/import.scm,
guix/scripts/import/cpan.scm,
guix/scripts/import/cran.scm,
guix/scripts/import/crate.scm,
guix/scripts/import/elpa.scm,
guix/scripts/import/gem.scm,
guix/scripts/import/gnu.scm,
guix/scripts/import/hackage.scm,
guix/scripts/import/nix.scm,
guix/scripts/import/pypi.scm,
guix/scripts/import/stackage.scm,
guix/scripts/lint.scm,
guix/scripts/offload.scm,
guix/scripts/pack.scm,
guix/scripts/package.scm,
guix/scripts/perform-download.scm,
guix/scripts/publish.scm,
guix/scripts/pull.scm,
guix/scripts/refresh.scm,
guix/scripts/size.scm,
guix/scripts/substitute.scm,
guix/scripts/system.scm,
guix/ssh.scm,
guix/upstream.scm: Use 'G_' instead of '_'. Most of this change was
obtained by running: "sed -i -e's/(_ "/(G_ "/g' `find -name \*.scm`".
2017-05-03 15:57:02 +02:00
|
|
|
|
(x (leave (G_ "wrong number of arguments~%"))))))
|
2016-12-09 23:12:06 +01:00
|
|
|
|
(check-machine-availability (or file %machine-file) pred))))
|
2017-12-13 23:42:40 +01:00
|
|
|
|
(("status" rest ...)
|
|
|
|
|
(with-error-handling
|
|
|
|
|
(let-values (((file pred)
|
|
|
|
|
(match rest
|
|
|
|
|
((file regexp)
|
|
|
|
|
(values file
|
|
|
|
|
(compose (cut string-match regexp <>)
|
|
|
|
|
build-machine-name)))
|
|
|
|
|
((file) (values file (const #t)))
|
|
|
|
|
(() (values %machine-file (const #t)))
|
|
|
|
|
(x (leave (G_ "wrong number of arguments~%"))))))
|
|
|
|
|
(check-machine-status (or file %machine-file) pred))))
|
2014-01-23 23:48:34 +01:00
|
|
|
|
(("--version")
|
|
|
|
|
(show-version-and-exit "guix offload"))
|
|
|
|
|
(("--help")
|
ui: Rename '_' to 'G_'.
This avoids collisions with '_' when the latter is used as a 'match'
pattern for instance. See
<https://lists.gnu.org/archive/html/guix-devel/2017-04/msg00464.html>.
* guix/ui.scm: Rename '_' to 'G_'.
* po/guix/Makevars (XGETTEXT_OPTIONS): Adjust accordingly.
* build-aux/compile-all.scm (warnings): Remove 'format'.
* gnu/packages.scm,
gnu/services.scm,
gnu/services/shepherd.scm,
gnu/system.scm,
gnu/system/shadow.scm,
guix/gnupg.scm,
guix/http-client.scm,
guix/import/cpan.scm,
guix/import/elpa.scm,
guix/import/pypi.scm,
guix/nar.scm,
guix/scripts.scm,
guix/scripts/archive.scm,
guix/scripts/authenticate.scm,
guix/scripts/build.scm,
guix/scripts/challenge.scm,
guix/scripts/container.scm,
guix/scripts/container/exec.scm,
guix/scripts/copy.scm,
guix/scripts/download.scm,
guix/scripts/edit.scm,
guix/scripts/environment.scm,
guix/scripts/gc.scm,
guix/scripts/graph.scm,
guix/scripts/hash.scm,
guix/scripts/import.scm,
guix/scripts/import/cpan.scm,
guix/scripts/import/cran.scm,
guix/scripts/import/crate.scm,
guix/scripts/import/elpa.scm,
guix/scripts/import/gem.scm,
guix/scripts/import/gnu.scm,
guix/scripts/import/hackage.scm,
guix/scripts/import/nix.scm,
guix/scripts/import/pypi.scm,
guix/scripts/import/stackage.scm,
guix/scripts/lint.scm,
guix/scripts/offload.scm,
guix/scripts/pack.scm,
guix/scripts/package.scm,
guix/scripts/perform-download.scm,
guix/scripts/publish.scm,
guix/scripts/pull.scm,
guix/scripts/refresh.scm,
guix/scripts/size.scm,
guix/scripts/substitute.scm,
guix/scripts/system.scm,
guix/ssh.scm,
guix/upstream.scm: Use 'G_' instead of '_'. Most of this change was
obtained by running: "sed -i -e's/(_ "/(G_ "/g' `find -name \*.scm`".
2017-05-03 15:57:02 +02:00
|
|
|
|
(format #t (G_ "Usage: guix offload SYSTEM PRINT-BUILD-TRACE
|
2014-01-23 23:48:34 +01:00
|
|
|
|
Process build offload requests written on the standard input, possibly
|
|
|
|
|
offloading builds to the machines listed in '~a'.~%")
|
|
|
|
|
%machine-file)
|
ui: Rename '_' to 'G_'.
This avoids collisions with '_' when the latter is used as a 'match'
pattern for instance. See
<https://lists.gnu.org/archive/html/guix-devel/2017-04/msg00464.html>.
* guix/ui.scm: Rename '_' to 'G_'.
* po/guix/Makevars (XGETTEXT_OPTIONS): Adjust accordingly.
* build-aux/compile-all.scm (warnings): Remove 'format'.
* gnu/packages.scm,
gnu/services.scm,
gnu/services/shepherd.scm,
gnu/system.scm,
gnu/system/shadow.scm,
guix/gnupg.scm,
guix/http-client.scm,
guix/import/cpan.scm,
guix/import/elpa.scm,
guix/import/pypi.scm,
guix/nar.scm,
guix/scripts.scm,
guix/scripts/archive.scm,
guix/scripts/authenticate.scm,
guix/scripts/build.scm,
guix/scripts/challenge.scm,
guix/scripts/container.scm,
guix/scripts/container/exec.scm,
guix/scripts/copy.scm,
guix/scripts/download.scm,
guix/scripts/edit.scm,
guix/scripts/environment.scm,
guix/scripts/gc.scm,
guix/scripts/graph.scm,
guix/scripts/hash.scm,
guix/scripts/import.scm,
guix/scripts/import/cpan.scm,
guix/scripts/import/cran.scm,
guix/scripts/import/crate.scm,
guix/scripts/import/elpa.scm,
guix/scripts/import/gem.scm,
guix/scripts/import/gnu.scm,
guix/scripts/import/hackage.scm,
guix/scripts/import/nix.scm,
guix/scripts/import/pypi.scm,
guix/scripts/import/stackage.scm,
guix/scripts/lint.scm,
guix/scripts/offload.scm,
guix/scripts/pack.scm,
guix/scripts/package.scm,
guix/scripts/perform-download.scm,
guix/scripts/publish.scm,
guix/scripts/pull.scm,
guix/scripts/refresh.scm,
guix/scripts/size.scm,
guix/scripts/substitute.scm,
guix/scripts/system.scm,
guix/ssh.scm,
guix/upstream.scm: Use 'G_' instead of '_'. Most of this change was
obtained by running: "sed -i -e's/(_ "/(G_ "/g' `find -name \*.scm`".
2017-05-03 15:57:02 +02:00
|
|
|
|
(display (G_ "
|
2014-01-23 23:48:34 +01:00
|
|
|
|
This tool is meant to be used internally by 'guix-daemon'.\n"))
|
|
|
|
|
(show-bug-report-information))
|
|
|
|
|
(x
|
ui: Rename '_' to 'G_'.
This avoids collisions with '_' when the latter is used as a 'match'
pattern for instance. See
<https://lists.gnu.org/archive/html/guix-devel/2017-04/msg00464.html>.
* guix/ui.scm: Rename '_' to 'G_'.
* po/guix/Makevars (XGETTEXT_OPTIONS): Adjust accordingly.
* build-aux/compile-all.scm (warnings): Remove 'format'.
* gnu/packages.scm,
gnu/services.scm,
gnu/services/shepherd.scm,
gnu/system.scm,
gnu/system/shadow.scm,
guix/gnupg.scm,
guix/http-client.scm,
guix/import/cpan.scm,
guix/import/elpa.scm,
guix/import/pypi.scm,
guix/nar.scm,
guix/scripts.scm,
guix/scripts/archive.scm,
guix/scripts/authenticate.scm,
guix/scripts/build.scm,
guix/scripts/challenge.scm,
guix/scripts/container.scm,
guix/scripts/container/exec.scm,
guix/scripts/copy.scm,
guix/scripts/download.scm,
guix/scripts/edit.scm,
guix/scripts/environment.scm,
guix/scripts/gc.scm,
guix/scripts/graph.scm,
guix/scripts/hash.scm,
guix/scripts/import.scm,
guix/scripts/import/cpan.scm,
guix/scripts/import/cran.scm,
guix/scripts/import/crate.scm,
guix/scripts/import/elpa.scm,
guix/scripts/import/gem.scm,
guix/scripts/import/gnu.scm,
guix/scripts/import/hackage.scm,
guix/scripts/import/nix.scm,
guix/scripts/import/pypi.scm,
guix/scripts/import/stackage.scm,
guix/scripts/lint.scm,
guix/scripts/offload.scm,
guix/scripts/pack.scm,
guix/scripts/package.scm,
guix/scripts/perform-download.scm,
guix/scripts/publish.scm,
guix/scripts/pull.scm,
guix/scripts/refresh.scm,
guix/scripts/size.scm,
guix/scripts/substitute.scm,
guix/scripts/system.scm,
guix/ssh.scm,
guix/upstream.scm: Use 'G_' instead of '_'. Most of this change was
obtained by running: "sed -i -e's/(_ "/(G_ "/g' `find -name \*.scm`".
2017-05-03 15:57:02 +02:00
|
|
|
|
(leave (G_ "invalid arguments: ~{~s ~}~%") x))))
|
2014-01-23 23:48:34 +01:00
|
|
|
|
|
2014-03-06 21:38:45 +01:00
|
|
|
|
;;; Local Variables:
|
2014-03-08 11:29:52 +01:00
|
|
|
|
;;; eval: (put 'with-machine-lock 'scheme-indent-function 2)
|
2014-03-08 12:07:57 +01:00
|
|
|
|
;;; eval: (put 'with-file-lock 'scheme-indent-function 1)
|
2014-03-19 23:12:06 +01:00
|
|
|
|
;;; eval: (put 'with-error-to-port 'scheme-indent-function 1)
|
2018-06-11 11:42:59 +02:00
|
|
|
|
;;; eval: (put 'with-timeout 'scheme-indent-function 2)
|
2014-03-06 21:38:45 +01:00
|
|
|
|
;;; End:
|
|
|
|
|
|
2014-01-23 23:48:34 +01:00
|
|
|
|
;;; offload.scm ends here
|