2013-01-05 18:47:50 -05:00
|
|
|
|
;;; GNU Guix --- Functional package management for GNU
|
2022-05-12 17:16:11 -04:00
|
|
|
|
;;; Copyright © 2012-2022 Ludovic Courtès <ludo@gnu.org>
|
2018-07-10 13:00:48 -04:00
|
|
|
|
;;; Copyright © 2018 Jan Nieuwenhuizen <janneke@gnu.org>
|
2020-03-06 04:06:02 -05:00
|
|
|
|
;;; Copyright © 2019, 2020 Mathieu Othacehe <m.othacehe@gmail.com>
|
2020-03-12 06:08:16 -04:00
|
|
|
|
;;; Copyright © 2020 Florian Pelz <pelzflorian@pelzflorian.de>
|
2020-06-05 04:38:32 -04:00
|
|
|
|
;;; Copyright © 2020 Lars-Dominik Braun <ldb@leibniz-psychology.org>
|
2012-04-18 17:34:12 -04:00
|
|
|
|
;;;
|
2013-01-05 18:47:50 -05:00
|
|
|
|
;;; This file is part of GNU Guix.
|
2012-04-18 17:34:12 -04:00
|
|
|
|
;;;
|
2013-01-05 18:47:50 -05:00
|
|
|
|
;;; GNU Guix is free software; you can redistribute it and/or modify it
|
2012-04-18 17:34:12 -04:00
|
|
|
|
;;; 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.
|
|
|
|
|
;;;
|
2013-01-05 18:47:50 -05:00
|
|
|
|
;;; GNU Guix is distributed in the hope that it will be useful, but
|
2012-04-18 17:34:12 -04:00
|
|
|
|
;;; 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
|
2013-01-05 18:47:50 -05:00
|
|
|
|
;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
|
2012-04-18 17:34:12 -04:00
|
|
|
|
|
|
|
|
|
(define-module (guix store)
|
2012-10-24 11:03:45 -04:00
|
|
|
|
#:use-module (guix utils)
|
2012-12-05 17:02:47 -05:00
|
|
|
|
#:use-module (guix config)
|
2019-01-21 09:32:35 -05:00
|
|
|
|
#:use-module (guix deprecation)
|
Add (guix nar) and (guix serialization).
* guix/store.scm (write-int, read-int, write-long-long, read-long-long,
write-padding, write-string, read-string, read-latin1-string,
write-string-list, read-string-list, write-store-path,
read-store-path, write-store-path-list, read-store-path-list): Move to
serialization.scm.
(write-contents, write-file): Move to nar.scm.
* guix/nar.scm, guix/serialization.scm: New files.
* Makefile.am (MODULES): Add them.
2013-04-04 16:29:08 -04:00
|
|
|
|
#:use-module (guix serialization)
|
monads: Move '%store-monad' and related procedures where they belong.
This turns (guix monads) into a generic module for monads, and moves the
store monad and related monadic procedures in their corresponding
module.
* guix/monads.scm (store-return, store-bind, %store-monad, store-lift,
text-file, interned-file, package-file, package->derivation,
package->cross-derivation, origin->derivation, imported-modules,
compiled, modules, built-derivations, run-with-store): Move to...
* guix/store.scm (store-return, store-bind, %store-monad, store-lift,
text-file, interned-file): ... here.
(%guile-for-build): New variable.
(run-with-store): Moved from monads.scm. Remove default value for
#:guile-for-build.
* guix/packages.scm (default-guile): Export.
(set-guile-for-build): New procedure.
(package-file, package->derivation, package->cross-derivation,
origin->derivation): Moved from monads.scm.
* guix/derivations.scm (%guile-for-build): Remove.
(imported-modules): Rename to...
(%imported-modules): ... this.
(compiled-modules): Rename to...
(%compiled-modules): ... this.
(built-derivations, imported-modules, compiled-modules): New
procedures.
* gnu/services/avahi.scm, gnu/services/base.scm, gnu/services/dbus.scm,
gnu/services/dmd.scm, gnu/services/networking.scm,
gnu/services/ssh.scm, gnu/services/xorg.scm, gnu/system/install.scm,
gnu/system/linux-initrd.scm, gnu/system/shadow.scm, guix/download.scm,
guix/gexp.scm, guix/git-download.scm, guix/profiles.scm,
guix/svn-download.scm, tests/monads.scm: Adjust imports accordingly.
* guix/monad-repl.scm (default-guile-derivation): New procedure.
(store-monad-language, run-in-store): Use it.
* build-aux/hydra/gnu-system.scm (qemu-jobs): Add explicit
'set-guile-for-build' call.
* guix/scripts/archive.scm (derivation-from-expression): Likewise.
* guix/scripts/build.scm (options/resolve-packages): Likewise.
* guix/scripts/environment.scm (guix-environment): Likewise.
* guix/scripts/system.scm (guix-system): Likewise.
* doc/guix.texi (The Store Monad): Adjust module names accordingly.
2015-01-14 07:34:52 -05:00
|
|
|
|
#:use-module (guix monads)
|
2015-11-20 12:44:29 -05:00
|
|
|
|
#:use-module (guix records)
|
utils: Move base16 procedures to (guix base16).
* guix/utils.scm (bytevector->base16-string, base16-string->bytevector):
Move to...
* guix/base16.scm: ... here. New file.
* tests/utils.scm ("bytevector->base16-string->bytevector"): Move to...
* tests/base16.scm: ... here. New file.
* Makefile.am (MODULES): Add guix/base16.scm.
(SCM_TESTS): Add tests/base16.scm.
* build-aux/download.scm, guix/derivations.scm,
guix/docker.scm, guix/import/snix.scm, guix/pk-crypto.scm,
guix/scripts/authenticate.scm, guix/scripts/download.scm,
guix/scripts/hash.scm, guix/store.scm, tests/hash.scm,
tests/pk-crypto.scm: Adjust imports accordingly.
2017-03-15 16:54:34 -04:00
|
|
|
|
#:use-module (guix base16)
|
2017-05-04 10:40:00 -04:00
|
|
|
|
#:use-module (guix base32)
|
Switch to Guile-Gcrypt.
This removes (guix hash) and (guix pk-crypto), which now live as part of
Guile-Gcrypt (version 0.1.0.)
* guix/gcrypt.scm, guix/hash.scm, guix/pk-crypto.scm,
tests/hash.scm, tests/pk-crypto.scm: Remove.
* configure.ac: Test for Guile-Gcrypt. Remove LIBGCRYPT and
LIBGCRYPT_LIBDIR assignments.
* m4/guix.m4 (GUIX_ASSERT_LIBGCRYPT_USABLE): Remove.
* README: Add Guile-Gcrypt to the dependencies; move libgcrypt as
"required unless --disable-daemon".
* doc/guix.texi (Requirements): Likewise.
* gnu/packages/bash.scm, guix/derivations.scm, guix/docker.scm,
guix/git.scm, guix/http-client.scm, guix/import/cpan.scm,
guix/import/cran.scm, guix/import/crate.scm, guix/import/elpa.scm,
guix/import/gnu.scm, guix/import/hackage.scm,
guix/import/texlive.scm, guix/import/utils.scm, guix/nar.scm,
guix/pki.scm, guix/scripts/archive.scm,
guix/scripts/authenticate.scm, guix/scripts/download.scm,
guix/scripts/hash.scm, guix/scripts/pack.scm,
guix/scripts/publish.scm, guix/scripts/refresh.scm,
guix/scripts/substitute.scm, guix/store.scm,
guix/store/deduplication.scm, guix/tests.scm, tests/base32.scm,
tests/builders.scm, tests/challenge.scm, tests/cpan.scm,
tests/crate.scm, tests/derivations.scm, tests/gem.scm,
tests/nar.scm, tests/opam.scm, tests/pki.scm,
tests/publish.scm, tests/pypi.scm, tests/store-deduplication.scm,
tests/store.scm, tests/substitute.scm: Adjust imports.
* gnu/system/vm.scm: Likewise.
(guile-sqlite3&co): Rename to...
(gcrypt-sqlite3&co): ... this. Add GUILE-GCRYPT.
(expression->derivation-in-linux-vm)[config]: Remove.
(iso9660-image)[config]: Remove.
(qemu-image)[config]: Remove.
(system-docker-image)[config]: Remove.
* guix/scripts/pack.scm: Adjust imports.
(guile-sqlite3&co): Rename to...
(gcrypt-sqlite3&co): ... this. Add GUILE-GCRYPT.
(self-contained-tarball)[build]: Call 'make-config.scm' without
#:libgcrypt argument.
(squashfs-image)[libgcrypt]: Remove.
[build]: Call 'make-config.scm' without #:libgcrypt.
(docker-image)[config, json]: Remove.
[build]: Add GUILE-GCRYPT to the extensions Remove (guix config) from
the imported modules.
* guix/self.scm (specification->package): Remove "libgcrypt", add
"guile-gcrypt".
(compiled-guix): Remove #:libgcrypt.
[guile-gcrypt]: New variable.
[dependencies]: Add it.
[*core-modules*]: Remove #:libgcrypt from 'make-config.scm' call.
Add #:extensions.
[*config*]: Remove #:libgcrypt from 'make-config.scm' call.
(%dependency-variables): Remove %libgcrypt.
(make-config.scm): Remove #:libgcrypt.
* build-aux/build-self.scm (guile-gcrypt): New variable.
(make-config.scm): Remove #:libgcrypt.
(build-program)[fake-gcrypt-hash]: New variable.
Add (gcrypt hash) to the imported modules. Adjust load path
assignments.
* gnu/packages/package-management.scm (guix)[propagated-inputs]: Add
GUILE-GCRYPT.
[arguments]: In 'wrap-program' phase, add GUILE-GCRYPT to the search
path.
2018-08-31 11:07:07 -04:00
|
|
|
|
#:use-module (gcrypt hash)
|
2017-06-28 04:13:45 -04:00
|
|
|
|
#:use-module (guix profiling)
|
2016-04-14 18:10:22 -04:00
|
|
|
|
#:autoload (guix build syscalls) (terminal-columns)
|
2022-05-20 14:39:48 -04:00
|
|
|
|
#:autoload (guix build utils) (dump-port)
|
2012-04-18 17:34:12 -04:00
|
|
|
|
#:use-module (rnrs bytevectors)
|
2016-10-19 08:28:56 -04:00
|
|
|
|
#:use-module (ice-9 binary-ports)
|
2015-11-20 12:44:29 -05:00
|
|
|
|
#:use-module ((ice-9 control) #:select (let/ec))
|
2021-05-28 11:22:03 -04:00
|
|
|
|
#:use-module (ice-9 atomic)
|
2012-04-18 17:34:12 -04:00
|
|
|
|
#:use-module (srfi srfi-1)
|
|
|
|
|
#:use-module (srfi srfi-9)
|
2013-09-01 13:24:21 -04:00
|
|
|
|
#:use-module (srfi srfi-9 gnu)
|
2016-03-04 11:57:04 -05:00
|
|
|
|
#:use-module (srfi srfi-11)
|
2012-04-18 17:34:12 -04:00
|
|
|
|
#:use-module (srfi srfi-26)
|
2012-06-01 17:29:55 -04:00
|
|
|
|
#:use-module (srfi srfi-34)
|
|
|
|
|
#:use-module (srfi srfi-35)
|
2012-04-18 17:34:12 -04:00
|
|
|
|
#:use-module (ice-9 match)
|
2013-06-13 16:03:42 -04:00
|
|
|
|
#:use-module (ice-9 vlist)
|
2014-01-11 11:11:14 -05:00
|
|
|
|
#:use-module (ice-9 popen)
|
2021-05-28 11:22:03 -04:00
|
|
|
|
#:autoload (ice-9 threads) (current-processor-count)
|
2017-10-07 10:14:16 -04:00
|
|
|
|
#:use-module (ice-9 format)
|
2017-04-21 05:39:49 -04:00
|
|
|
|
#:use-module (web uri)
|
|
|
|
|
#:export (%daemon-socket-uri
|
2014-04-12 16:32:10 -04:00
|
|
|
|
%gc-roots-directory
|
2015-07-13 10:07:59 -04:00
|
|
|
|
%default-substitute-urls
|
2013-02-18 15:53:59 -05:00
|
|
|
|
|
2019-01-21 09:32:35 -05:00
|
|
|
|
store-connection?
|
|
|
|
|
store-connection-version
|
|
|
|
|
store-connection-major-version
|
|
|
|
|
store-connection-minor-version
|
|
|
|
|
store-connection-socket
|
|
|
|
|
|
|
|
|
|
;; Deprecated forms for 'store-connection'.
|
2013-02-18 15:53:59 -05:00
|
|
|
|
nix-server?
|
2017-01-18 17:21:29 -05:00
|
|
|
|
nix-server-version
|
2012-04-18 17:34:12 -04:00
|
|
|
|
nix-server-major-version
|
|
|
|
|
nix-server-minor-version
|
|
|
|
|
nix-server-socket
|
2019-01-21 09:32:35 -05:00
|
|
|
|
|
2017-01-18 17:21:29 -05:00
|
|
|
|
current-store-protocol-version ;for internal use
|
2021-05-28 11:45:11 -04:00
|
|
|
|
cache-lookup-recorder ;for internal use
|
2015-11-20 12:44:29 -05:00
|
|
|
|
mcached
|
2012-04-18 17:34:12 -04:00
|
|
|
|
|
store: Rename '&nix-error' to '&store-error'.
* guix/store.scm (&nix-error): Rename to...
(&store-error): ... this, and adjust users.
(&nix-connection-error): Rename to...
(&store-connection-error): ... this, and adjust users.
(&nix-protocol-error): Rename to...
(&store-protocol-error): ... this, adjust users.
(&nix-error, &nix-connection-error, &nix-protocol-error): Define these
condition types and their getters as deprecrated aliases.
* build-aux/run-system-tests.scm, guix/derivations.scm,
guix/grafts.scm, guix/scripts/challenge.scm,
guix/scripts/graph.scm, guix/scripts/lint.scm,
guix/scripts/offload.scm, guix/serialization.scm,
guix/ssh.scm, guix/tests.scm, guix/ui.scm,
tests/derivations.scm, tests/gexp.scm, tests/guix-daemon.sh,
tests/packages.scm, tests/store.scm, doc/guix.texi: Adjust to use the
new names.
2019-01-21 11:41:11 -05:00
|
|
|
|
&store-error store-error?
|
|
|
|
|
&store-connection-error store-connection-error?
|
|
|
|
|
store-connection-error-file
|
|
|
|
|
store-connection-error-code
|
|
|
|
|
&store-protocol-error store-protocol-error?
|
|
|
|
|
store-protocol-error-message
|
|
|
|
|
store-protocol-error-status
|
|
|
|
|
|
|
|
|
|
;; Deprecated forms for '&store-error' et al.
|
2012-06-01 17:29:55 -04:00
|
|
|
|
&nix-error nix-error?
|
2013-03-07 13:29:12 -05:00
|
|
|
|
&nix-connection-error nix-connection-error?
|
|
|
|
|
nix-connection-error-file
|
|
|
|
|
nix-connection-error-code
|
2012-06-01 17:29:55 -04:00
|
|
|
|
&nix-protocol-error nix-protocol-error?
|
|
|
|
|
nix-protocol-error-message
|
|
|
|
|
nix-protocol-error-status
|
|
|
|
|
|
2021-05-28 11:22:03 -04:00
|
|
|
|
allocate-store-connection-cache
|
|
|
|
|
store-connection-cache
|
|
|
|
|
set-store-connection-cache
|
|
|
|
|
set-store-connection-cache!
|
|
|
|
|
|
2012-06-01 17:29:55 -04:00
|
|
|
|
hash-algo
|
2015-12-03 12:08:35 -05:00
|
|
|
|
build-mode
|
2012-06-01 17:29:55 -04:00
|
|
|
|
|
2021-05-05 17:25:56 -04:00
|
|
|
|
connect-to-daemon
|
2012-04-18 17:34:12 -04:00
|
|
|
|
open-connection
|
2018-06-25 12:40:10 -04:00
|
|
|
|
port->connection
|
2012-08-22 11:22:46 -04:00
|
|
|
|
close-connection
|
2014-01-19 17:03:43 -05:00
|
|
|
|
with-store
|
2012-04-18 17:34:12 -04:00
|
|
|
|
set-build-options
|
2015-09-03 11:33:51 -04:00
|
|
|
|
set-build-options*
|
2012-06-30 18:21:16 -04:00
|
|
|
|
valid-path?
|
2012-10-24 11:03:45 -04:00
|
|
|
|
query-path-hash
|
2014-03-14 12:16:10 -04:00
|
|
|
|
hash-part->path
|
2015-03-17 10:19:36 -04:00
|
|
|
|
query-path-info
|
2017-01-29 06:55:24 -05:00
|
|
|
|
add-data-to-store
|
2012-04-18 17:34:12 -04:00
|
|
|
|
add-text-to-store
|
|
|
|
|
add-to-store
|
2018-07-16 03:55:49 -04:00
|
|
|
|
add-file-tree-to-store
|
2020-01-29 19:17:54 -05:00
|
|
|
|
file-mapping->tree
|
2018-07-10 13:00:48 -04:00
|
|
|
|
binary-file
|
2020-03-18 17:17:39 -04:00
|
|
|
|
with-build-handler
|
2020-03-25 07:41:18 -04:00
|
|
|
|
map/accumulate-builds
|
|
|
|
|
mapm/accumulate-builds
|
2015-02-02 06:25:34 -05:00
|
|
|
|
build-things
|
|
|
|
|
build
|
2015-09-28 15:32:17 -04:00
|
|
|
|
query-failed-paths
|
|
|
|
|
clear-failed-paths
|
2020-11-04 08:39:40 -05:00
|
|
|
|
ensure-path
|
2021-01-21 10:06:10 -05:00
|
|
|
|
find-roots
|
2012-12-09 17:52:59 -05:00
|
|
|
|
add-temp-root
|
2012-10-29 19:20:53 -04:00
|
|
|
|
add-indirect-root
|
2014-04-12 16:32:10 -04:00
|
|
|
|
add-permanent-root
|
|
|
|
|
remove-permanent-root
|
2012-06-01 17:29:55 -04:00
|
|
|
|
|
2013-02-03 17:24:25 -05:00
|
|
|
|
substitutable?
|
|
|
|
|
substitutable-path
|
|
|
|
|
substitutable-deriver
|
|
|
|
|
substitutable-references
|
|
|
|
|
substitutable-download-size
|
|
|
|
|
substitutable-nar-size
|
|
|
|
|
has-substitutes?
|
|
|
|
|
substitutable-paths
|
|
|
|
|
substitutable-path-info
|
|
|
|
|
|
2015-03-17 10:19:36 -04:00
|
|
|
|
path-info?
|
|
|
|
|
path-info-deriver
|
|
|
|
|
path-info-hash
|
|
|
|
|
path-info-references
|
|
|
|
|
path-info-registration-time
|
|
|
|
|
path-info-nar-size
|
|
|
|
|
|
2016-11-13 16:59:54 -05:00
|
|
|
|
built-in-builders
|
2013-02-27 16:40:35 -05:00
|
|
|
|
references
|
2020-03-28 20:21:32 -04:00
|
|
|
|
references/cached
|
2016-11-19 11:05:07 -05:00
|
|
|
|
references*
|
2018-07-02 17:50:38 -04:00
|
|
|
|
query-path-info*
|
2013-06-13 16:03:42 -04:00
|
|
|
|
requisites
|
2013-02-27 16:40:35 -05:00
|
|
|
|
referrers
|
2015-05-19 03:35:52 -04:00
|
|
|
|
optimize-store
|
2015-06-06 13:05:25 -04:00
|
|
|
|
verify-store
|
2014-01-23 16:13:27 -05:00
|
|
|
|
topologically-sorted
|
2013-02-27 16:40:35 -05:00
|
|
|
|
valid-derivers
|
|
|
|
|
query-derivation-outputs
|
2012-12-09 17:52:59 -05:00
|
|
|
|
live-paths
|
|
|
|
|
dead-paths
|
|
|
|
|
collect-garbage
|
|
|
|
|
delete-paths
|
2013-12-20 11:17:42 -05:00
|
|
|
|
import-paths
|
|
|
|
|
export-paths
|
2012-12-09 17:52:59 -05:00
|
|
|
|
|
2012-06-16 10:13:12 -04:00
|
|
|
|
current-build-output-port
|
|
|
|
|
|
monads: Move '%store-monad' and related procedures where they belong.
This turns (guix monads) into a generic module for monads, and moves the
store monad and related monadic procedures in their corresponding
module.
* guix/monads.scm (store-return, store-bind, %store-monad, store-lift,
text-file, interned-file, package-file, package->derivation,
package->cross-derivation, origin->derivation, imported-modules,
compiled, modules, built-derivations, run-with-store): Move to...
* guix/store.scm (store-return, store-bind, %store-monad, store-lift,
text-file, interned-file): ... here.
(%guile-for-build): New variable.
(run-with-store): Moved from monads.scm. Remove default value for
#:guile-for-build.
* guix/packages.scm (default-guile): Export.
(set-guile-for-build): New procedure.
(package-file, package->derivation, package->cross-derivation,
origin->derivation): Moved from monads.scm.
* guix/derivations.scm (%guile-for-build): Remove.
(imported-modules): Rename to...
(%imported-modules): ... this.
(compiled-modules): Rename to...
(%compiled-modules): ... this.
(built-derivations, imported-modules, compiled-modules): New
procedures.
* gnu/services/avahi.scm, gnu/services/base.scm, gnu/services/dbus.scm,
gnu/services/dmd.scm, gnu/services/networking.scm,
gnu/services/ssh.scm, gnu/services/xorg.scm, gnu/system/install.scm,
gnu/system/linux-initrd.scm, gnu/system/shadow.scm, guix/download.scm,
guix/gexp.scm, guix/git-download.scm, guix/profiles.scm,
guix/svn-download.scm, tests/monads.scm: Adjust imports accordingly.
* guix/monad-repl.scm (default-guile-derivation): New procedure.
(store-monad-language, run-in-store): Use it.
* build-aux/hydra/gnu-system.scm (qemu-jobs): Add explicit
'set-guile-for-build' call.
* guix/scripts/archive.scm (derivation-from-expression): Likewise.
* guix/scripts/build.scm (options/resolve-packages): Likewise.
* guix/scripts/environment.scm (guix-environment): Likewise.
* guix/scripts/system.scm (guix-system): Likewise.
* doc/guix.texi (The Store Monad): Adjust module names accordingly.
2015-01-14 07:34:52 -05:00
|
|
|
|
%store-monad
|
|
|
|
|
store-bind
|
|
|
|
|
store-return
|
|
|
|
|
store-lift
|
2015-01-14 08:25:58 -05:00
|
|
|
|
store-lower
|
monads: Move '%store-monad' and related procedures where they belong.
This turns (guix monads) into a generic module for monads, and moves the
store monad and related monadic procedures in their corresponding
module.
* guix/monads.scm (store-return, store-bind, %store-monad, store-lift,
text-file, interned-file, package-file, package->derivation,
package->cross-derivation, origin->derivation, imported-modules,
compiled, modules, built-derivations, run-with-store): Move to...
* guix/store.scm (store-return, store-bind, %store-monad, store-lift,
text-file, interned-file): ... here.
(%guile-for-build): New variable.
(run-with-store): Moved from monads.scm. Remove default value for
#:guile-for-build.
* guix/packages.scm (default-guile): Export.
(set-guile-for-build): New procedure.
(package-file, package->derivation, package->cross-derivation,
origin->derivation): Moved from monads.scm.
* guix/derivations.scm (%guile-for-build): Remove.
(imported-modules): Rename to...
(%imported-modules): ... this.
(compiled-modules): Rename to...
(%compiled-modules): ... this.
(built-derivations, imported-modules, compiled-modules): New
procedures.
* gnu/services/avahi.scm, gnu/services/base.scm, gnu/services/dbus.scm,
gnu/services/dmd.scm, gnu/services/networking.scm,
gnu/services/ssh.scm, gnu/services/xorg.scm, gnu/system/install.scm,
gnu/system/linux-initrd.scm, gnu/system/shadow.scm, guix/download.scm,
guix/gexp.scm, guix/git-download.scm, guix/profiles.scm,
guix/svn-download.scm, tests/monads.scm: Adjust imports accordingly.
* guix/monad-repl.scm (default-guile-derivation): New procedure.
(store-monad-language, run-in-store): Use it.
* build-aux/hydra/gnu-system.scm (qemu-jobs): Add explicit
'set-guile-for-build' call.
* guix/scripts/archive.scm (derivation-from-expression): Likewise.
* guix/scripts/build.scm (options/resolve-packages): Likewise.
* guix/scripts/environment.scm (guix-environment): Likewise.
* guix/scripts/system.scm (guix-system): Likewise.
* doc/guix.texi (The Store Monad): Adjust module names accordingly.
2015-01-14 07:34:52 -05:00
|
|
|
|
run-with-store
|
|
|
|
|
%guile-for-build
|
2016-02-12 12:59:11 -05:00
|
|
|
|
current-system
|
|
|
|
|
set-current-system
|
2019-12-24 09:04:57 -05:00
|
|
|
|
current-target-system
|
2020-03-06 04:06:02 -05:00
|
|
|
|
set-current-target
|
monads: Move '%store-monad' and related procedures where they belong.
This turns (guix monads) into a generic module for monads, and moves the
store monad and related monadic procedures in their corresponding
module.
* guix/monads.scm (store-return, store-bind, %store-monad, store-lift,
text-file, interned-file, package-file, package->derivation,
package->cross-derivation, origin->derivation, imported-modules,
compiled, modules, built-derivations, run-with-store): Move to...
* guix/store.scm (store-return, store-bind, %store-monad, store-lift,
text-file, interned-file): ... here.
(%guile-for-build): New variable.
(run-with-store): Moved from monads.scm. Remove default value for
#:guile-for-build.
* guix/packages.scm (default-guile): Export.
(set-guile-for-build): New procedure.
(package-file, package->derivation, package->cross-derivation,
origin->derivation): Moved from monads.scm.
* guix/derivations.scm (%guile-for-build): Remove.
(imported-modules): Rename to...
(%imported-modules): ... this.
(compiled-modules): Rename to...
(%compiled-modules): ... this.
(built-derivations, imported-modules, compiled-modules): New
procedures.
* gnu/services/avahi.scm, gnu/services/base.scm, gnu/services/dbus.scm,
gnu/services/dmd.scm, gnu/services/networking.scm,
gnu/services/ssh.scm, gnu/services/xorg.scm, gnu/system/install.scm,
gnu/system/linux-initrd.scm, gnu/system/shadow.scm, guix/download.scm,
guix/gexp.scm, guix/git-download.scm, guix/profiles.scm,
guix/svn-download.scm, tests/monads.scm: Adjust imports accordingly.
* guix/monad-repl.scm (default-guile-derivation): New procedure.
(store-monad-language, run-in-store): Use it.
* build-aux/hydra/gnu-system.scm (qemu-jobs): Add explicit
'set-guile-for-build' call.
* guix/scripts/archive.scm (derivation-from-expression): Likewise.
* guix/scripts/build.scm (options/resolve-packages): Likewise.
* guix/scripts/environment.scm (guix-environment): Likewise.
* guix/scripts/system.scm (guix-system): Likewise.
* doc/guix.texi (The Store Monad): Adjust module names accordingly.
2015-01-14 07:34:52 -05:00
|
|
|
|
text-file
|
|
|
|
|
interned-file
|
2018-07-16 03:55:49 -04:00
|
|
|
|
interned-file-tree
|
monads: Move '%store-monad' and related procedures where they belong.
This turns (guix monads) into a generic module for monads, and moves the
store monad and related monadic procedures in their corresponding
module.
* guix/monads.scm (store-return, store-bind, %store-monad, store-lift,
text-file, interned-file, package-file, package->derivation,
package->cross-derivation, origin->derivation, imported-modules,
compiled, modules, built-derivations, run-with-store): Move to...
* guix/store.scm (store-return, store-bind, %store-monad, store-lift,
text-file, interned-file): ... here.
(%guile-for-build): New variable.
(run-with-store): Moved from monads.scm. Remove default value for
#:guile-for-build.
* guix/packages.scm (default-guile): Export.
(set-guile-for-build): New procedure.
(package-file, package->derivation, package->cross-derivation,
origin->derivation): Moved from monads.scm.
* guix/derivations.scm (%guile-for-build): Remove.
(imported-modules): Rename to...
(%imported-modules): ... this.
(compiled-modules): Rename to...
(%compiled-modules): ... this.
(built-derivations, imported-modules, compiled-modules): New
procedures.
* gnu/services/avahi.scm, gnu/services/base.scm, gnu/services/dbus.scm,
gnu/services/dmd.scm, gnu/services/networking.scm,
gnu/services/ssh.scm, gnu/services/xorg.scm, gnu/system/install.scm,
gnu/system/linux-initrd.scm, gnu/system/shadow.scm, guix/download.scm,
guix/gexp.scm, guix/git-download.scm, guix/profiles.scm,
guix/svn-download.scm, tests/monads.scm: Adjust imports accordingly.
* guix/monad-repl.scm (default-guile-derivation): New procedure.
(store-monad-language, run-in-store): Use it.
* build-aux/hydra/gnu-system.scm (qemu-jobs): Add explicit
'set-guile-for-build' call.
* guix/scripts/archive.scm (derivation-from-expression): Likewise.
* guix/scripts/build.scm (options/resolve-packages): Likewise.
* guix/scripts/environment.scm (guix-environment): Likewise.
* guix/scripts/system.scm (guix-system): Likewise.
* doc/guix.texi (The Store Monad): Adjust module names accordingly.
2015-01-14 07:34:52 -05:00
|
|
|
|
|
2022-10-14 15:51:18 -04:00
|
|
|
|
%graft?
|
|
|
|
|
without-grafting
|
|
|
|
|
set-grafting
|
|
|
|
|
grafting?
|
|
|
|
|
|
2012-06-01 17:29:55 -04:00
|
|
|
|
%store-prefix
|
2017-05-04 10:40:00 -04:00
|
|
|
|
store-path
|
|
|
|
|
output-path
|
|
|
|
|
fixed-output-path
|
2012-06-01 17:29:55 -04:00
|
|
|
|
store-path?
|
2013-11-12 17:36:29 -05:00
|
|
|
|
direct-store-path?
|
2012-10-31 20:39:23 -04:00
|
|
|
|
derivation-path?
|
2020-03-12 06:08:16 -04:00
|
|
|
|
store-path-base
|
2013-04-01 10:08:31 -04:00
|
|
|
|
store-path-package-name
|
2013-11-11 18:10:10 -05:00
|
|
|
|
store-path-hash-part
|
2015-05-24 08:04:15 -04:00
|
|
|
|
direct-store-path
|
2018-09-28 17:19:13 -04:00
|
|
|
|
derivation-log-file
|
2013-11-11 18:10:10 -05:00
|
|
|
|
log-file))
|
2012-04-18 17:34:12 -04:00
|
|
|
|
|
2018-10-15 16:40:35 -04:00
|
|
|
|
(define %protocol-version #x163)
|
2012-04-18 17:34:12 -04:00
|
|
|
|
|
2014-02-11 17:16:28 -05:00
|
|
|
|
(define %worker-magic-1 #x6e697863) ; "nixc"
|
|
|
|
|
(define %worker-magic-2 #x6478696f) ; "dxio"
|
2012-04-18 17:34:12 -04:00
|
|
|
|
|
|
|
|
|
(define (protocol-major magic)
|
|
|
|
|
(logand magic #xff00))
|
|
|
|
|
(define (protocol-minor magic)
|
|
|
|
|
(logand magic #x00ff))
|
2017-01-18 17:21:29 -05:00
|
|
|
|
(define (protocol-version major minor)
|
|
|
|
|
(logior major minor))
|
2012-04-18 17:34:12 -04:00
|
|
|
|
|
|
|
|
|
(define-syntax define-enumerate-type
|
|
|
|
|
(syntax-rules ()
|
|
|
|
|
((_ name->int (name id) ...)
|
|
|
|
|
(define-syntax name->int
|
|
|
|
|
(syntax-rules (name ...)
|
|
|
|
|
((_ name) id) ...)))))
|
|
|
|
|
|
|
|
|
|
(define-enumerate-type operation-id
|
|
|
|
|
;; operation numbers from worker-protocol.hh
|
|
|
|
|
(quit 0)
|
|
|
|
|
(valid-path? 1)
|
|
|
|
|
(has-substitutes? 3)
|
|
|
|
|
(query-path-hash 4)
|
|
|
|
|
(query-references 5)
|
|
|
|
|
(query-referrers 6)
|
|
|
|
|
(add-to-store 7)
|
|
|
|
|
(add-text-to-store 8)
|
2015-02-02 06:25:34 -05:00
|
|
|
|
(build-things 9)
|
2012-04-18 17:34:12 -04:00
|
|
|
|
(ensure-path 10)
|
|
|
|
|
(add-temp-root 11)
|
|
|
|
|
(add-indirect-root 12)
|
|
|
|
|
(sync-with-gc 13)
|
|
|
|
|
(find-roots 14)
|
|
|
|
|
(export-path 16)
|
|
|
|
|
(query-deriver 18)
|
|
|
|
|
(set-options 19)
|
|
|
|
|
(collect-garbage 20)
|
2013-02-03 17:02:14 -05:00
|
|
|
|
;;(query-substitutable-path-info 21) ; obsolete as of #x10c
|
2012-04-18 17:34:12 -04:00
|
|
|
|
(query-derivation-outputs 22)
|
2013-02-03 17:02:14 -05:00
|
|
|
|
(query-all-valid-paths 23)
|
2012-04-18 17:34:12 -04:00
|
|
|
|
(query-failed-paths 24)
|
|
|
|
|
(clear-failed-paths 25)
|
|
|
|
|
(query-path-info 26)
|
|
|
|
|
(import-paths 27)
|
2013-02-03 17:02:14 -05:00
|
|
|
|
(query-derivation-output-names 28)
|
|
|
|
|
(query-path-from-hash-part 29)
|
|
|
|
|
(query-substitutable-path-infos 30)
|
|
|
|
|
(query-valid-paths 31)
|
2013-02-27 16:40:35 -05:00
|
|
|
|
(query-substitutable-paths 32)
|
2015-05-19 03:35:52 -04:00
|
|
|
|
(query-valid-derivers 33)
|
2015-06-06 13:05:25 -04:00
|
|
|
|
(optimize-store 34)
|
2016-11-13 16:59:54 -05:00
|
|
|
|
(verify-store 35)
|
|
|
|
|
(built-in-builders 80))
|
2012-04-18 17:34:12 -04:00
|
|
|
|
|
|
|
|
|
(define-enumerate-type hash-algo
|
|
|
|
|
;; hash.hh
|
|
|
|
|
(md5 1)
|
|
|
|
|
(sha1 2)
|
|
|
|
|
(sha256 3))
|
|
|
|
|
|
2015-12-03 12:08:35 -05:00
|
|
|
|
(define-enumerate-type build-mode
|
|
|
|
|
;; store-api.hh
|
|
|
|
|
(normal 0)
|
|
|
|
|
(repair 1)
|
|
|
|
|
(check 2))
|
|
|
|
|
|
2012-12-09 17:52:59 -05:00
|
|
|
|
(define-enumerate-type gc-action
|
|
|
|
|
;; store-api.hh
|
|
|
|
|
(return-live 0)
|
|
|
|
|
(return-dead 1)
|
|
|
|
|
(delete-dead 2)
|
|
|
|
|
(delete-specific 3))
|
|
|
|
|
|
2012-04-18 17:34:12 -04:00
|
|
|
|
(define %default-socket-path
|
2014-01-08 15:12:55 -05:00
|
|
|
|
(string-append %state-directory "/daemon-socket/socket"))
|
2012-04-18 17:34:12 -04:00
|
|
|
|
|
2017-04-21 05:39:49 -04:00
|
|
|
|
(define %daemon-socket-uri
|
|
|
|
|
;; URI or file name of the socket the daemon listens too.
|
2013-02-18 15:53:59 -05:00
|
|
|
|
(make-parameter (or (getenv "GUIX_DAEMON_SOCKET")
|
|
|
|
|
%default-socket-path)))
|
|
|
|
|
|
|
|
|
|
|
2012-04-18 17:34:12 -04:00
|
|
|
|
|
2013-02-03 17:24:25 -05:00
|
|
|
|
;; Information about a substitutable store path.
|
|
|
|
|
(define-record-type <substitutable>
|
|
|
|
|
(substitutable path deriver refs dl-size nar-size)
|
|
|
|
|
substitutable?
|
|
|
|
|
(path substitutable-path)
|
|
|
|
|
(deriver substitutable-deriver)
|
|
|
|
|
(refs substitutable-references)
|
|
|
|
|
(dl-size substitutable-download-size)
|
|
|
|
|
(nar-size substitutable-nar-size))
|
|
|
|
|
|
|
|
|
|
(define (read-substitutable-path-list p)
|
|
|
|
|
(let loop ((len (read-int p))
|
|
|
|
|
(result '()))
|
|
|
|
|
(if (zero? len)
|
|
|
|
|
(reverse result)
|
|
|
|
|
(let ((path (read-store-path p))
|
|
|
|
|
(deriver (read-store-path p))
|
|
|
|
|
(refs (read-store-path-list p))
|
|
|
|
|
(dl-size (read-long-long p))
|
|
|
|
|
(nar-size (read-long-long p)))
|
|
|
|
|
(loop (- len 1)
|
|
|
|
|
(cons (substitutable path deriver refs dl-size nar-size)
|
|
|
|
|
result))))))
|
|
|
|
|
|
2015-03-17 10:19:36 -04:00
|
|
|
|
;; Information about a store path.
|
|
|
|
|
(define-record-type <path-info>
|
|
|
|
|
(path-info deriver hash references registration-time nar-size)
|
|
|
|
|
path-info?
|
2016-02-26 17:14:28 -05:00
|
|
|
|
(deriver path-info-deriver) ;string | #f
|
2015-03-17 10:19:36 -04:00
|
|
|
|
(hash path-info-hash)
|
|
|
|
|
(references path-info-references)
|
|
|
|
|
(registration-time path-info-registration-time)
|
|
|
|
|
(nar-size path-info-nar-size))
|
|
|
|
|
|
|
|
|
|
(define (read-path-info p)
|
2016-02-26 17:14:28 -05:00
|
|
|
|
(let ((deriver (match (read-store-path p)
|
|
|
|
|
("" #f)
|
|
|
|
|
(x x)))
|
2015-03-17 10:19:36 -04:00
|
|
|
|
(hash (base16-string->bytevector (read-string p)))
|
|
|
|
|
(refs (read-store-path-list p))
|
|
|
|
|
(registration-time (read-int p))
|
|
|
|
|
(nar-size (read-long-long p)))
|
|
|
|
|
(path-info deriver hash refs registration-time nar-size)))
|
|
|
|
|
|
2012-04-18 17:34:12 -04:00
|
|
|
|
(define-syntax write-arg
|
2017-01-29 06:55:24 -05:00
|
|
|
|
(syntax-rules (integer boolean bytevector
|
|
|
|
|
string string-list string-pairs
|
2012-12-09 17:52:59 -05:00
|
|
|
|
store-path store-path-list base16)
|
2012-04-18 17:34:12 -04:00
|
|
|
|
((_ integer arg p)
|
|
|
|
|
(write-int arg p))
|
|
|
|
|
((_ boolean arg p)
|
|
|
|
|
(write-int (if arg 1 0) p))
|
2017-01-29 06:55:24 -05:00
|
|
|
|
((_ bytevector arg p)
|
|
|
|
|
(write-bytevector arg p))
|
2012-04-18 17:34:12 -04:00
|
|
|
|
((_ string arg p)
|
|
|
|
|
(write-string arg p))
|
|
|
|
|
((_ string-list arg p)
|
2012-10-24 11:03:45 -04:00
|
|
|
|
(write-string-list arg p))
|
2014-03-09 18:01:18 -04:00
|
|
|
|
((_ string-pairs arg p)
|
|
|
|
|
(write-string-pairs arg p))
|
2012-12-09 17:52:59 -05:00
|
|
|
|
((_ store-path arg p)
|
|
|
|
|
(write-store-path arg p))
|
|
|
|
|
((_ store-path-list arg p)
|
|
|
|
|
(write-store-path-list arg p))
|
2012-10-24 11:03:45 -04:00
|
|
|
|
((_ base16 arg p)
|
|
|
|
|
(write-string (bytevector->base16-string arg) p))))
|
2012-04-18 17:34:12 -04:00
|
|
|
|
|
|
|
|
|
(define-syntax read-arg
|
2021-01-21 10:06:10 -05:00
|
|
|
|
(syntax-rules (integer boolean string store-path
|
|
|
|
|
store-path-list string-list string-pairs
|
2015-03-17 10:19:36 -04:00
|
|
|
|
substitutable-path-list path-info base16)
|
2012-04-18 17:34:12 -04:00
|
|
|
|
((_ integer p)
|
|
|
|
|
(read-int p))
|
|
|
|
|
((_ boolean p)
|
|
|
|
|
(not (zero? (read-int p))))
|
|
|
|
|
((_ string p)
|
|
|
|
|
(read-string p))
|
|
|
|
|
((_ store-path p)
|
2012-10-24 11:03:45 -04:00
|
|
|
|
(read-store-path p))
|
2012-12-09 17:52:59 -05:00
|
|
|
|
((_ store-path-list p)
|
|
|
|
|
(read-store-path-list p))
|
2016-11-13 16:59:54 -05:00
|
|
|
|
((_ string-list p)
|
|
|
|
|
(read-string-list p))
|
2021-01-21 10:06:10 -05:00
|
|
|
|
((_ string-pairs p)
|
|
|
|
|
(read-string-pairs p))
|
2013-02-03 17:24:25 -05:00
|
|
|
|
((_ substitutable-path-list p)
|
|
|
|
|
(read-substitutable-path-list p))
|
2015-03-17 10:19:36 -04:00
|
|
|
|
((_ path-info p)
|
|
|
|
|
(read-path-info p))
|
2013-02-03 17:24:25 -05:00
|
|
|
|
((_ base16 p)
|
2012-10-24 11:03:45 -04:00
|
|
|
|
(base16-string->bytevector (read-string p)))))
|
2012-04-18 17:34:12 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; remote-store.cc
|
|
|
|
|
|
2019-01-21 09:32:35 -05:00
|
|
|
|
(define-record-type* <store-connection> store-connection %make-store-connection
|
|
|
|
|
store-connection?
|
|
|
|
|
(socket store-connection-socket)
|
|
|
|
|
(major store-connection-major-version)
|
|
|
|
|
(minor store-connection-minor-version)
|
2013-01-29 17:34:50 -05:00
|
|
|
|
|
2019-01-21 09:32:35 -05:00
|
|
|
|
(buffer store-connection-output-port) ;output port
|
|
|
|
|
(flush store-connection-flush-output) ;thunk
|
2017-06-19 15:47:22 -04:00
|
|
|
|
|
2013-01-29 17:34:50 -05:00
|
|
|
|
;; Caches. We keep them per-connection, because store paths build
|
|
|
|
|
;; during the session are temporary GC roots kept for the duration of
|
|
|
|
|
;; the session.
|
2019-01-21 09:32:35 -05:00
|
|
|
|
(ats-cache store-connection-add-to-store-cache)
|
|
|
|
|
(atts-cache store-connection-add-text-to-store-cache)
|
2021-05-28 11:22:03 -04:00
|
|
|
|
(caches store-connection-caches
|
|
|
|
|
(default '#())) ;vector
|
2019-04-16 04:26:46 -04:00
|
|
|
|
(built-in-builders store-connection-built-in-builders
|
|
|
|
|
(default (delay '())))) ;promise
|
2012-04-18 17:34:12 -04:00
|
|
|
|
|
2019-01-21 09:32:35 -05:00
|
|
|
|
(set-record-type-printer! <store-connection>
|
2013-09-01 13:24:21 -04:00
|
|
|
|
(lambda (obj port)
|
2019-01-21 09:32:35 -05:00
|
|
|
|
(format port "#<store-connection ~a.~a ~a>"
|
|
|
|
|
(store-connection-major-version obj)
|
|
|
|
|
(store-connection-minor-version obj)
|
2013-09-01 13:24:21 -04:00
|
|
|
|
(number->string (object-address obj)
|
|
|
|
|
16))))
|
|
|
|
|
|
2019-01-21 09:32:35 -05:00
|
|
|
|
(define-deprecated/alias nix-server? store-connection?)
|
|
|
|
|
(define-deprecated/alias nix-server-major-version
|
|
|
|
|
store-connection-major-version)
|
|
|
|
|
(define-deprecated/alias nix-server-minor-version
|
|
|
|
|
store-connection-minor-version)
|
|
|
|
|
(define-deprecated/alias nix-server-socket store-connection-socket)
|
|
|
|
|
|
|
|
|
|
|
store: Rename '&nix-error' to '&store-error'.
* guix/store.scm (&nix-error): Rename to...
(&store-error): ... this, and adjust users.
(&nix-connection-error): Rename to...
(&store-connection-error): ... this, and adjust users.
(&nix-protocol-error): Rename to...
(&store-protocol-error): ... this, adjust users.
(&nix-error, &nix-connection-error, &nix-protocol-error): Define these
condition types and their getters as deprecrated aliases.
* build-aux/run-system-tests.scm, guix/derivations.scm,
guix/grafts.scm, guix/scripts/challenge.scm,
guix/scripts/graph.scm, guix/scripts/lint.scm,
guix/scripts/offload.scm, guix/serialization.scm,
guix/ssh.scm, guix/tests.scm, guix/ui.scm,
tests/derivations.scm, tests/gexp.scm, tests/guix-daemon.sh,
tests/packages.scm, tests/store.scm, doc/guix.texi: Adjust to use the
new names.
2019-01-21 11:41:11 -05:00
|
|
|
|
(define-condition-type &store-error &error
|
|
|
|
|
store-error?)
|
2012-06-01 17:29:55 -04:00
|
|
|
|
|
store: Rename '&nix-error' to '&store-error'.
* guix/store.scm (&nix-error): Rename to...
(&store-error): ... this, and adjust users.
(&nix-connection-error): Rename to...
(&store-connection-error): ... this, and adjust users.
(&nix-protocol-error): Rename to...
(&store-protocol-error): ... this, adjust users.
(&nix-error, &nix-connection-error, &nix-protocol-error): Define these
condition types and their getters as deprecrated aliases.
* build-aux/run-system-tests.scm, guix/derivations.scm,
guix/grafts.scm, guix/scripts/challenge.scm,
guix/scripts/graph.scm, guix/scripts/lint.scm,
guix/scripts/offload.scm, guix/serialization.scm,
guix/ssh.scm, guix/tests.scm, guix/ui.scm,
tests/derivations.scm, tests/gexp.scm, tests/guix-daemon.sh,
tests/packages.scm, tests/store.scm, doc/guix.texi: Adjust to use the
new names.
2019-01-21 11:41:11 -05:00
|
|
|
|
(define-condition-type &store-connection-error &store-error
|
|
|
|
|
store-connection-error?
|
|
|
|
|
(file store-connection-error-file)
|
|
|
|
|
(errno store-connection-error-code))
|
|
|
|
|
|
|
|
|
|
(define-condition-type &store-protocol-error &store-error
|
|
|
|
|
store-protocol-error?
|
|
|
|
|
(message store-protocol-error-message)
|
|
|
|
|
(status store-protocol-error-status))
|
|
|
|
|
|
|
|
|
|
(define-deprecated/alias &nix-error &store-error)
|
|
|
|
|
(define-deprecated/alias nix-error? store-error?)
|
|
|
|
|
(define-deprecated/alias &nix-connection-error &store-connection-error)
|
|
|
|
|
(define-deprecated/alias nix-connection-error? store-connection-error?)
|
|
|
|
|
(define-deprecated/alias nix-connection-error-file
|
|
|
|
|
store-connection-error-file)
|
|
|
|
|
(define-deprecated/alias nix-connection-error-code
|
|
|
|
|
store-connection-error-code)
|
|
|
|
|
(define-deprecated/alias &nix-protocol-error &store-protocol-error)
|
|
|
|
|
(define-deprecated/alias nix-protocol-error? store-protocol-error?)
|
|
|
|
|
(define-deprecated/alias nix-protocol-error-message
|
|
|
|
|
store-protocol-error-message)
|
|
|
|
|
(define-deprecated/alias nix-protocol-error-status
|
|
|
|
|
store-protocol-error-status)
|
2013-03-07 13:29:12 -05:00
|
|
|
|
|
2012-06-01 17:29:55 -04:00
|
|
|
|
|
2017-04-21 05:48:57 -04:00
|
|
|
|
(define-syntax-rule (system-error-to-connection-error file exp ...)
|
|
|
|
|
"Catch 'system-error' exceptions and translate them to
|
store: Rename '&nix-error' to '&store-error'.
* guix/store.scm (&nix-error): Rename to...
(&store-error): ... this, and adjust users.
(&nix-connection-error): Rename to...
(&store-connection-error): ... this, and adjust users.
(&nix-protocol-error): Rename to...
(&store-protocol-error): ... this, adjust users.
(&nix-error, &nix-connection-error, &nix-protocol-error): Define these
condition types and their getters as deprecrated aliases.
* build-aux/run-system-tests.scm, guix/derivations.scm,
guix/grafts.scm, guix/scripts/challenge.scm,
guix/scripts/graph.scm, guix/scripts/lint.scm,
guix/scripts/offload.scm, guix/serialization.scm,
guix/ssh.scm, guix/tests.scm, guix/ui.scm,
tests/derivations.scm, tests/gexp.scm, tests/guix-daemon.sh,
tests/packages.scm, tests/store.scm, doc/guix.texi: Adjust to use the
new names.
2019-01-21 11:41:11 -05:00
|
|
|
|
'&store-connection-error'."
|
2017-04-21 05:48:57 -04:00
|
|
|
|
(catch 'system-error
|
|
|
|
|
(lambda ()
|
|
|
|
|
exp ...)
|
|
|
|
|
(lambda args
|
|
|
|
|
(let ((errno (system-error-errno args)))
|
store: Rename '&nix-error' to '&store-error'.
* guix/store.scm (&nix-error): Rename to...
(&store-error): ... this, and adjust users.
(&nix-connection-error): Rename to...
(&store-connection-error): ... this, and adjust users.
(&nix-protocol-error): Rename to...
(&store-protocol-error): ... this, adjust users.
(&nix-error, &nix-connection-error, &nix-protocol-error): Define these
condition types and their getters as deprecrated aliases.
* build-aux/run-system-tests.scm, guix/derivations.scm,
guix/grafts.scm, guix/scripts/challenge.scm,
guix/scripts/graph.scm, guix/scripts/lint.scm,
guix/scripts/offload.scm, guix/serialization.scm,
guix/ssh.scm, guix/tests.scm, guix/ui.scm,
tests/derivations.scm, tests/gexp.scm, tests/guix-daemon.sh,
tests/packages.scm, tests/store.scm, doc/guix.texi: Adjust to use the
new names.
2019-01-21 11:41:11 -05:00
|
|
|
|
(raise (condition (&store-connection-error
|
2017-04-21 05:48:57 -04:00
|
|
|
|
(file file)
|
|
|
|
|
(errno errno))))))))
|
|
|
|
|
|
2016-11-02 17:50:31 -04:00
|
|
|
|
(define (open-unix-domain-socket file)
|
|
|
|
|
"Connect to the Unix-domain socket at FILE and return it. Raise a
|
store: Rename '&nix-error' to '&store-error'.
* guix/store.scm (&nix-error): Rename to...
(&store-error): ... this, and adjust users.
(&nix-connection-error): Rename to...
(&store-connection-error): ... this, and adjust users.
(&nix-protocol-error): Rename to...
(&store-protocol-error): ... this, adjust users.
(&nix-error, &nix-connection-error, &nix-protocol-error): Define these
condition types and their getters as deprecrated aliases.
* build-aux/run-system-tests.scm, guix/derivations.scm,
guix/grafts.scm, guix/scripts/challenge.scm,
guix/scripts/graph.scm, guix/scripts/lint.scm,
guix/scripts/offload.scm, guix/serialization.scm,
guix/ssh.scm, guix/tests.scm, guix/ui.scm,
tests/derivations.scm, tests/gexp.scm, tests/guix-daemon.sh,
tests/packages.scm, tests/store.scm, doc/guix.texi: Adjust to use the
new names.
2019-01-21 11:41:11 -05:00
|
|
|
|
'&store-connection-error' upon error."
|
2012-04-18 17:34:12 -04:00
|
|
|
|
(let ((s (with-fluids ((%default-port-encoding #f))
|
|
|
|
|
;; This trick allows use of the `scm_c_read' optimization.
|
2022-09-04 10:04:31 -04:00
|
|
|
|
(socket PF_UNIX (logior SOCK_STREAM SOCK_CLOEXEC) 0)))
|
2012-04-18 17:34:12 -04:00
|
|
|
|
(a (make-socket-address PF_UNIX file)))
|
2012-10-13 16:36:39 -04:00
|
|
|
|
|
2017-04-21 05:48:57 -04:00
|
|
|
|
(system-error-to-connection-error file
|
|
|
|
|
(connect s a)
|
|
|
|
|
s)))
|
2013-03-07 13:29:12 -05:00
|
|
|
|
|
2017-06-19 11:50:28 -04:00
|
|
|
|
(define %default-guix-port
|
|
|
|
|
;; Default port when connecting to a daemon over TCP/IP.
|
|
|
|
|
44146)
|
|
|
|
|
|
2017-04-21 08:57:02 -04:00
|
|
|
|
(define (open-inet-socket host port)
|
|
|
|
|
"Connect to the Unix-domain socket at HOST:PORT and return it. Raise a
|
store: Rename '&nix-error' to '&store-error'.
* guix/store.scm (&nix-error): Rename to...
(&store-error): ... this, and adjust users.
(&nix-connection-error): Rename to...
(&store-connection-error): ... this, and adjust users.
(&nix-protocol-error): Rename to...
(&store-protocol-error): ... this, adjust users.
(&nix-error, &nix-connection-error, &nix-protocol-error): Define these
condition types and their getters as deprecrated aliases.
* build-aux/run-system-tests.scm, guix/derivations.scm,
guix/grafts.scm, guix/scripts/challenge.scm,
guix/scripts/graph.scm, guix/scripts/lint.scm,
guix/scripts/offload.scm, guix/serialization.scm,
guix/ssh.scm, guix/tests.scm, guix/ui.scm,
tests/derivations.scm, tests/gexp.scm, tests/guix-daemon.sh,
tests/packages.scm, tests/store.scm, doc/guix.texi: Adjust to use the
new names.
2019-01-21 11:41:11 -05:00
|
|
|
|
'&store-connection-error' upon error."
|
2022-09-03 12:44:32 -04:00
|
|
|
|
(define addresses
|
|
|
|
|
(getaddrinfo host
|
|
|
|
|
(if (number? port) (number->string port) port)
|
|
|
|
|
(if (number? port)
|
|
|
|
|
(logior AI_ADDRCONFIG AI_NUMERICSERV)
|
|
|
|
|
AI_ADDRCONFIG)
|
|
|
|
|
0 ;any address family
|
|
|
|
|
SOCK_STREAM)) ;TCP only
|
|
|
|
|
|
|
|
|
|
(let loop ((addresses addresses))
|
|
|
|
|
(match addresses
|
|
|
|
|
((ai rest ...)
|
|
|
|
|
(let ((s (socket (addrinfo:fam ai)
|
|
|
|
|
;; TCP/IP only
|
2022-09-04 10:04:31 -04:00
|
|
|
|
(logior SOCK_STREAM SOCK_CLOEXEC) IPPROTO_IP)))
|
2022-09-03 12:44:32 -04:00
|
|
|
|
|
|
|
|
|
(catch 'system-error
|
|
|
|
|
(lambda ()
|
|
|
|
|
(connect s (addrinfo:addr ai))
|
|
|
|
|
|
|
|
|
|
;; Setting this option makes a dramatic difference because it
|
|
|
|
|
;; avoids the "ACK delay" on our RPC messages.
|
|
|
|
|
(setsockopt s IPPROTO_TCP TCP_NODELAY 1)
|
|
|
|
|
s)
|
|
|
|
|
(lambda args
|
|
|
|
|
;; Connection failed, so try one of the other addresses.
|
|
|
|
|
(close s)
|
|
|
|
|
(if (null? rest)
|
|
|
|
|
(raise (condition (&store-connection-error
|
|
|
|
|
(file host)
|
|
|
|
|
(errno (system-error-errno args)))))
|
|
|
|
|
(loop rest)))))))))
|
2017-04-21 08:57:02 -04:00
|
|
|
|
|
2017-04-21 05:39:49 -04:00
|
|
|
|
(define (connect-to-daemon uri)
|
|
|
|
|
"Connect to the daemon at URI, a string that may be an actual URI or a file
|
2021-05-05 17:25:56 -04:00
|
|
|
|
name, and return an input/output port.
|
|
|
|
|
|
|
|
|
|
This is a low-level procedure that does not perform the initial handshake with
|
|
|
|
|
the daemon. Use 'open-connection' for that."
|
2017-04-21 13:13:32 -04:00
|
|
|
|
(define (not-supported)
|
store: Rename '&nix-error' to '&store-error'.
* guix/store.scm (&nix-error): Rename to...
(&store-error): ... this, and adjust users.
(&nix-connection-error): Rename to...
(&store-connection-error): ... this, and adjust users.
(&nix-protocol-error): Rename to...
(&store-protocol-error): ... this, adjust users.
(&nix-error, &nix-connection-error, &nix-protocol-error): Define these
condition types and their getters as deprecrated aliases.
* build-aux/run-system-tests.scm, guix/derivations.scm,
guix/grafts.scm, guix/scripts/challenge.scm,
guix/scripts/graph.scm, guix/scripts/lint.scm,
guix/scripts/offload.scm, guix/serialization.scm,
guix/ssh.scm, guix/tests.scm, guix/ui.scm,
tests/derivations.scm, tests/gexp.scm, tests/guix-daemon.sh,
tests/packages.scm, tests/store.scm, doc/guix.texi: Adjust to use the
new names.
2019-01-21 11:41:11 -05:00
|
|
|
|
(raise (condition (&store-connection-error
|
2017-04-21 13:13:32 -04:00
|
|
|
|
(file uri)
|
|
|
|
|
(errno ENOTSUP)))))
|
|
|
|
|
|
2017-04-21 05:39:49 -04:00
|
|
|
|
(define connect
|
|
|
|
|
(match (string->uri uri)
|
|
|
|
|
(#f ;URI is a file name
|
|
|
|
|
open-unix-domain-socket)
|
|
|
|
|
((? uri? uri)
|
|
|
|
|
(match (uri-scheme uri)
|
|
|
|
|
((or #f 'file 'unix)
|
|
|
|
|
(lambda (_)
|
|
|
|
|
(open-unix-domain-socket (uri-path uri))))
|
2017-04-21 08:57:02 -04:00
|
|
|
|
('guix
|
|
|
|
|
(lambda (_)
|
2017-06-19 11:50:28 -04:00
|
|
|
|
(open-inet-socket (uri-host uri)
|
|
|
|
|
(or (uri-port uri) %default-guix-port))))
|
2017-04-21 13:13:32 -04:00
|
|
|
|
((? symbol? scheme)
|
|
|
|
|
;; Try to dynamically load a module for SCHEME.
|
|
|
|
|
;; XXX: Errors are swallowed.
|
|
|
|
|
(match (false-if-exception
|
|
|
|
|
(resolve-interface `(guix store ,scheme)))
|
|
|
|
|
((? module? module)
|
|
|
|
|
(match (false-if-exception
|
|
|
|
|
(module-ref module 'connect-to-daemon))
|
|
|
|
|
((? procedure? connect)
|
|
|
|
|
(lambda (_)
|
|
|
|
|
(connect uri)))
|
|
|
|
|
(x (not-supported))))
|
|
|
|
|
(#f (not-supported))))
|
2017-04-21 05:39:49 -04:00
|
|
|
|
(x
|
2017-04-21 13:13:32 -04:00
|
|
|
|
(not-supported))))))
|
2017-04-21 05:39:49 -04:00
|
|
|
|
|
|
|
|
|
(connect uri))
|
|
|
|
|
|
|
|
|
|
(define* (open-connection #:optional (uri (%daemon-socket-uri))
|
2016-11-02 17:50:31 -04:00
|
|
|
|
#:key port (reserve-space? #t) cpu-affinity)
|
2017-04-21 05:39:49 -04:00
|
|
|
|
"Connect to the daemon at URI (a string), or, if PORT is not #f, use it as
|
|
|
|
|
the I/O port over which to communicate to a build daemon.
|
2016-11-02 17:50:31 -04:00
|
|
|
|
|
|
|
|
|
When RESERVE-SPACE? is true, instruct it to reserve a little bit of extra
|
|
|
|
|
space on the file system so that the garbage collector can still operate,
|
|
|
|
|
should the disk become full. When CPU-AFFINITY is true, it must be an integer
|
|
|
|
|
corresponding to an OS-level CPU number to which the daemon's worker process
|
|
|
|
|
for this connection will be pinned. Return a server object."
|
2021-05-05 17:03:40 -04:00
|
|
|
|
(define (handshake-error)
|
|
|
|
|
(raise (condition
|
|
|
|
|
(&store-connection-error (file (or port uri))
|
|
|
|
|
(errno EPROTO))
|
|
|
|
|
(&message (message "build daemon handshake failed")))))
|
|
|
|
|
|
2016-12-08 08:03:33 -05:00
|
|
|
|
(guard (c ((nar-error? c)
|
|
|
|
|
;; One of the 'write-' or 'read-' calls below failed, but this is
|
|
|
|
|
;; really a connection error.
|
2021-05-05 17:03:40 -04:00
|
|
|
|
(handshake-error)))
|
2017-06-19 15:47:22 -04:00
|
|
|
|
(let*-values (((port)
|
|
|
|
|
(or port (connect-to-daemon uri)))
|
|
|
|
|
((output flush)
|
|
|
|
|
(buffering-output-port port
|
|
|
|
|
(make-bytevector 8192))))
|
2016-12-08 08:03:33 -05:00
|
|
|
|
(write-int %worker-magic-1 port)
|
|
|
|
|
(let ((r (read-int port)))
|
2021-05-05 17:03:40 -04:00
|
|
|
|
(unless (= r %worker-magic-2)
|
|
|
|
|
(handshake-error))
|
|
|
|
|
|
|
|
|
|
(let ((v (read-int port)))
|
|
|
|
|
(unless (= (protocol-major %protocol-version)
|
|
|
|
|
(protocol-major v))
|
|
|
|
|
(handshake-error))
|
|
|
|
|
|
|
|
|
|
(write-int %protocol-version port)
|
|
|
|
|
(when (>= (protocol-minor v) 14)
|
|
|
|
|
(write-int (if cpu-affinity 1 0) port)
|
|
|
|
|
(when cpu-affinity
|
|
|
|
|
(write-int cpu-affinity port)))
|
|
|
|
|
(when (>= (protocol-minor v) 11)
|
|
|
|
|
(write-int (if reserve-space? 1 0) port))
|
|
|
|
|
(letrec* ((built-in-builders
|
|
|
|
|
(delay (%built-in-builders conn)))
|
2021-05-28 11:22:03 -04:00
|
|
|
|
(caches
|
|
|
|
|
(make-vector
|
|
|
|
|
(atomic-box-ref %store-connection-caches)
|
|
|
|
|
vlist-null))
|
2021-05-05 17:03:40 -04:00
|
|
|
|
(conn
|
|
|
|
|
(%make-store-connection port
|
|
|
|
|
(protocol-major v)
|
|
|
|
|
(protocol-minor v)
|
|
|
|
|
output flush
|
|
|
|
|
(make-hash-table 100)
|
|
|
|
|
(make-hash-table 100)
|
2021-05-28 11:22:03 -04:00
|
|
|
|
caches
|
2021-05-05 17:03:40 -04:00
|
|
|
|
built-in-builders)))
|
|
|
|
|
(let loop ((done? (process-stderr conn)))
|
|
|
|
|
(or done? (process-stderr conn)))
|
|
|
|
|
conn))))))
|
2012-04-18 17:34:12 -04:00
|
|
|
|
|
2018-06-25 12:40:10 -04:00
|
|
|
|
(define* (port->connection port
|
|
|
|
|
#:key (version %protocol-version))
|
|
|
|
|
"Assimilate PORT, an input/output port, and return a connection to the
|
|
|
|
|
daemon, assuming the given protocol VERSION.
|
|
|
|
|
|
|
|
|
|
Warning: this procedure assumes that the initial handshake with the daemon has
|
|
|
|
|
already taken place on PORT and that we're just continuing on this established
|
|
|
|
|
connection. Use with care."
|
|
|
|
|
(let-values (((output flush)
|
|
|
|
|
(buffering-output-port port (make-bytevector 8192))))
|
2019-04-16 04:26:46 -04:00
|
|
|
|
(define connection
|
|
|
|
|
(%make-store-connection port
|
|
|
|
|
(protocol-major version)
|
|
|
|
|
(protocol-minor version)
|
|
|
|
|
output flush
|
|
|
|
|
(make-hash-table 100)
|
|
|
|
|
(make-hash-table 100)
|
2021-05-28 11:22:03 -04:00
|
|
|
|
(make-vector
|
|
|
|
|
(atomic-box-ref %store-connection-caches)
|
|
|
|
|
vlist-null)
|
2019-04-16 04:26:46 -04:00
|
|
|
|
(delay (%built-in-builders connection))))
|
|
|
|
|
|
|
|
|
|
connection))
|
2019-01-21 09:32:35 -05:00
|
|
|
|
|
|
|
|
|
(define (store-connection-version store)
|
2017-01-18 17:21:29 -05:00
|
|
|
|
"Return the protocol version of STORE as an integer."
|
2019-01-21 09:32:35 -05:00
|
|
|
|
(protocol-version (store-connection-major-version store)
|
|
|
|
|
(store-connection-minor-version store)))
|
|
|
|
|
|
|
|
|
|
(define-deprecated/alias nix-server-version store-connection-version)
|
2017-01-18 17:21:29 -05:00
|
|
|
|
|
2017-06-19 15:47:22 -04:00
|
|
|
|
(define (write-buffered-output server)
|
|
|
|
|
"Flush SERVER's output port."
|
2019-01-21 09:32:35 -05:00
|
|
|
|
(force-output (store-connection-output-port server))
|
|
|
|
|
((store-connection-flush-output server)))
|
2017-06-19 15:47:22 -04:00
|
|
|
|
|
2012-08-22 11:22:46 -04:00
|
|
|
|
(define (close-connection server)
|
|
|
|
|
"Close the connection to SERVER."
|
2019-01-21 09:32:35 -05:00
|
|
|
|
(close (store-connection-socket server)))
|
2012-08-22 11:22:46 -04:00
|
|
|
|
|
2019-04-09 03:52:48 -04:00
|
|
|
|
(define (call-with-store proc)
|
|
|
|
|
"Call PROC with an open store connection."
|
2014-01-19 17:03:43 -05:00
|
|
|
|
(let ((store (open-connection)))
|
2020-04-04 17:58:05 -04:00
|
|
|
|
(define (thunk)
|
|
|
|
|
(parameterize ((current-store-protocol-version
|
|
|
|
|
(store-connection-version store)))
|
2020-08-28 09:05:17 -04:00
|
|
|
|
(call-with-values (lambda () (proc store))
|
|
|
|
|
(lambda results
|
|
|
|
|
(close-connection store)
|
|
|
|
|
(apply values results)))))
|
2020-04-04 17:58:05 -04:00
|
|
|
|
|
2021-05-26 16:30:31 -04:00
|
|
|
|
(with-exception-handler (lambda (exception)
|
|
|
|
|
(close-connection store)
|
|
|
|
|
(raise-exception exception))
|
|
|
|
|
thunk)))
|
2014-01-19 17:03:43 -05:00
|
|
|
|
|
2019-04-09 03:52:48 -04:00
|
|
|
|
(define-syntax-rule (with-store store exp ...)
|
|
|
|
|
"Bind STORE to an open connection to the store and evaluate EXPs;
|
|
|
|
|
automatically close the store when the dynamic extent of EXP is left."
|
|
|
|
|
(call-with-store (lambda (store) exp ...)))
|
|
|
|
|
|
2017-01-18 17:21:29 -05:00
|
|
|
|
(define current-store-protocol-version
|
|
|
|
|
;; Protocol version of the store currently used. XXX: This is a hack to
|
|
|
|
|
;; communicate the protocol version to the build output port. It's a hack
|
|
|
|
|
;; because it could be inaccurrate, for instance if there's code that
|
|
|
|
|
;; manipulates several store connections at once; it works well for the
|
|
|
|
|
;; purposes of (guix status) though.
|
|
|
|
|
(make-parameter #f))
|
|
|
|
|
|
2012-06-16 10:13:12 -04:00
|
|
|
|
(define current-build-output-port
|
|
|
|
|
;; The port where build output is sent.
|
|
|
|
|
(make-parameter (current-error-port)))
|
|
|
|
|
|
2014-05-21 09:29:23 -04:00
|
|
|
|
(define %newlines
|
|
|
|
|
;; Newline characters triggering a flush of 'current-build-output-port'.
|
2019-01-07 04:57:18 -05:00
|
|
|
|
;; Unlike Guile's 'line, we flush upon #\return so that progress reports
|
2014-05-21 09:29:23 -04:00
|
|
|
|
;; that use that trick are correctly displayed.
|
|
|
|
|
(char-set #\newline #\return))
|
|
|
|
|
|
2013-12-20 11:17:42 -05:00
|
|
|
|
(define* (process-stderr server #:optional user-port)
|
2012-06-16 10:13:12 -04:00
|
|
|
|
"Read standard output and standard error from SERVER, writing it to
|
|
|
|
|
CURRENT-BUILD-OUTPUT-PORT. Return #t when SERVER is done sending data, and
|
|
|
|
|
#f otherwise; in the latter case, the caller should call `process-stderr'
|
2013-01-31 08:05:10 -05:00
|
|
|
|
again until #t is returned or an error is raised.
|
|
|
|
|
|
|
|
|
|
Since the build process's output cannot be assumed to be UTF-8, we
|
|
|
|
|
conservatively consider it to be Latin-1, thereby avoiding possible
|
|
|
|
|
encoding conversion errors."
|
2012-04-18 17:34:12 -04:00
|
|
|
|
(define p
|
2019-01-21 09:32:35 -05:00
|
|
|
|
(store-connection-socket server))
|
2012-04-18 17:34:12 -04:00
|
|
|
|
|
|
|
|
|
;; magic cookies from worker-protocol.hh
|
2014-01-09 17:59:07 -05:00
|
|
|
|
(define %stderr-next #x6f6c6d67) ; "olmg", build log
|
|
|
|
|
(define %stderr-read #x64617461) ; "data", data needed from source
|
|
|
|
|
(define %stderr-write #x64617416) ; "dat\x16", data for sink
|
|
|
|
|
(define %stderr-last #x616c7473) ; "alts", we're done
|
|
|
|
|
(define %stderr-error #x63787470) ; "cxtp", error reporting
|
2012-04-18 17:34:12 -04:00
|
|
|
|
|
|
|
|
|
(let ((k (read-int p)))
|
|
|
|
|
(cond ((= k %stderr-write)
|
2013-12-20 11:17:42 -05:00
|
|
|
|
;; Write a byte stream to USER-PORT.
|
|
|
|
|
(let* ((len (read-int p))
|
|
|
|
|
(m (modulo len 8)))
|
2016-12-01 17:09:34 -05:00
|
|
|
|
(dump-port p user-port len
|
|
|
|
|
#:buffer-size (if (<= len 16384) 16384 65536))
|
2013-12-20 11:17:42 -05:00
|
|
|
|
(unless (zero? m)
|
|
|
|
|
;; Consume padding, as for strings.
|
|
|
|
|
(get-bytevector-n p (- 8 m))))
|
2012-06-16 10:13:12 -04:00
|
|
|
|
#f)
|
2012-04-18 17:34:12 -04:00
|
|
|
|
((= k %stderr-read)
|
2013-12-20 11:17:42 -05:00
|
|
|
|
;; Read a byte stream from USER-PORT.
|
2014-05-27 16:01:51 -04:00
|
|
|
|
;; Note: Avoid 'get-bytevector-n' to work around
|
|
|
|
|
;; <http://bugs.gnu.org/17591> in Guile up to 2.0.11.
|
2013-12-20 11:17:42 -05:00
|
|
|
|
(let* ((max-len (read-int p))
|
2014-05-27 16:01:51 -04:00
|
|
|
|
(data (make-bytevector max-len))
|
|
|
|
|
(len (get-bytevector-n! user-port data 0 max-len)))
|
2018-01-10 15:38:08 -05:00
|
|
|
|
(write-bytevector data p len)
|
2012-06-16 10:13:12 -04:00
|
|
|
|
#f))
|
2012-04-18 17:34:12 -04:00
|
|
|
|
((= k %stderr-next)
|
2015-03-05 16:00:11 -05:00
|
|
|
|
;; Log a string. Build logs are usually UTF-8-encoded, but they
|
|
|
|
|
;; may also contain arbitrary byte sequences that should not cause
|
|
|
|
|
;; this to fail. Thus, use the permissive
|
|
|
|
|
;; 'read-maybe-utf8-string'.
|
|
|
|
|
(let ((s (read-maybe-utf8-string p)))
|
2012-06-16 10:13:12 -04:00
|
|
|
|
(display s (current-build-output-port))
|
2014-05-21 09:29:23 -04:00
|
|
|
|
(when (string-any %newlines s)
|
2016-10-19 08:28:56 -04:00
|
|
|
|
(force-output (current-build-output-port)))
|
2012-06-16 10:13:12 -04:00
|
|
|
|
#f))
|
2012-04-18 17:34:12 -04:00
|
|
|
|
((= k %stderr-error)
|
2013-12-20 11:17:42 -05:00
|
|
|
|
;; Report an error.
|
2015-03-05 16:00:11 -05:00
|
|
|
|
(let ((error (read-maybe-utf8-string p))
|
2013-04-20 04:53:31 -04:00
|
|
|
|
;; Currently the daemon fails to send a status code for early
|
|
|
|
|
;; errors like DB schema version mismatches, so check for EOF.
|
2019-01-21 09:32:35 -05:00
|
|
|
|
(status (if (and (>= (store-connection-minor-version server) 8)
|
2013-04-20 04:53:31 -04:00
|
|
|
|
(not (eof-object? (lookahead-u8 p))))
|
2012-04-18 17:34:12 -04:00
|
|
|
|
(read-int p)
|
|
|
|
|
1)))
|
store: Rename '&nix-error' to '&store-error'.
* guix/store.scm (&nix-error): Rename to...
(&store-error): ... this, and adjust users.
(&nix-connection-error): Rename to...
(&store-connection-error): ... this, and adjust users.
(&nix-protocol-error): Rename to...
(&store-protocol-error): ... this, adjust users.
(&nix-error, &nix-connection-error, &nix-protocol-error): Define these
condition types and their getters as deprecrated aliases.
* build-aux/run-system-tests.scm, guix/derivations.scm,
guix/grafts.scm, guix/scripts/challenge.scm,
guix/scripts/graph.scm, guix/scripts/lint.scm,
guix/scripts/offload.scm, guix/serialization.scm,
guix/ssh.scm, guix/tests.scm, guix/ui.scm,
tests/derivations.scm, tests/gexp.scm, tests/guix-daemon.sh,
tests/packages.scm, tests/store.scm, doc/guix.texi: Adjust to use the
new names.
2019-01-21 11:41:11 -05:00
|
|
|
|
(raise (condition (&store-protocol-error
|
2012-06-01 17:29:55 -04:00
|
|
|
|
(message error)
|
|
|
|
|
(status status))))))
|
2012-04-18 17:34:12 -04:00
|
|
|
|
((= k %stderr-last)
|
2012-06-16 10:13:12 -04:00
|
|
|
|
;; The daemon is done (see `stopWork' in `nix-worker.cc'.)
|
2012-04-18 17:34:12 -04:00
|
|
|
|
#t)
|
|
|
|
|
(else
|
store: Rename '&nix-error' to '&store-error'.
* guix/store.scm (&nix-error): Rename to...
(&store-error): ... this, and adjust users.
(&nix-connection-error): Rename to...
(&store-connection-error): ... this, and adjust users.
(&nix-protocol-error): Rename to...
(&store-protocol-error): ... this, adjust users.
(&nix-error, &nix-connection-error, &nix-protocol-error): Define these
condition types and their getters as deprecrated aliases.
* build-aux/run-system-tests.scm, guix/derivations.scm,
guix/grafts.scm, guix/scripts/challenge.scm,
guix/scripts/graph.scm, guix/scripts/lint.scm,
guix/scripts/offload.scm, guix/serialization.scm,
guix/ssh.scm, guix/tests.scm, guix/ui.scm,
tests/derivations.scm, tests/gexp.scm, tests/guix-daemon.sh,
tests/packages.scm, tests/store.scm, doc/guix.texi: Adjust to use the
new names.
2019-01-21 11:41:11 -05:00
|
|
|
|
(raise (condition (&store-protocol-error
|
2012-06-01 17:29:55 -04:00
|
|
|
|
(message "invalid error code")
|
|
|
|
|
(status k))))))))
|
2012-04-18 17:34:12 -04:00
|
|
|
|
|
2015-03-22 18:43:25 -04:00
|
|
|
|
(define %default-substitute-urls
|
2016-03-28 16:18:17 -04:00
|
|
|
|
;; Default list of substituters. This is *not* the list baked in
|
|
|
|
|
;; 'guix-daemon', but it is used by 'guix-service-type' and and a couple of
|
|
|
|
|
;; clients ('guix build --log-file' uses it.)
|
2016-03-16 05:35:24 -04:00
|
|
|
|
(map (if (false-if-exception (resolve-interface '(gnutls)))
|
|
|
|
|
(cut string-append "https://" <>)
|
|
|
|
|
(cut string-append "http://" <>))
|
2021-05-15 06:02:36 -04:00
|
|
|
|
'("ci.guix.gnu.org"
|
|
|
|
|
"bordeaux.guix.gnu.org")))
|
2015-03-22 18:43:25 -04:00
|
|
|
|
|
2019-10-16 05:51:42 -04:00
|
|
|
|
(define (current-user-name)
|
|
|
|
|
"Return the name of the calling user."
|
|
|
|
|
(catch #t
|
|
|
|
|
(lambda ()
|
|
|
|
|
(passwd:name (getpwuid (getuid))))
|
|
|
|
|
(lambda _
|
|
|
|
|
(getenv "USER"))))
|
|
|
|
|
|
2012-04-18 17:34:12 -04:00
|
|
|
|
(define* (set-build-options server
|
2013-05-29 17:04:15 -04:00
|
|
|
|
#:key keep-failed? keep-going? fallback?
|
2012-04-18 17:34:12 -04:00
|
|
|
|
(verbosity 0)
|
2015-12-08 16:58:32 -05:00
|
|
|
|
rounds ;number of build rounds
|
2017-01-15 09:13:07 -05:00
|
|
|
|
max-build-jobs
|
2014-03-09 18:01:18 -04:00
|
|
|
|
timeout
|
2017-01-15 09:13:07 -05:00
|
|
|
|
max-silent-time
|
2019-11-21 09:28:13 -05:00
|
|
|
|
(offload? #t)
|
|
|
|
|
(use-build-hook? *unspecified*) ;deprecated
|
2012-04-18 17:34:12 -04:00
|
|
|
|
(build-verbosity 0)
|
|
|
|
|
(log-type 0)
|
2012-06-30 18:09:47 -04:00
|
|
|
|
(print-build-trace #t)
|
2019-10-16 05:51:42 -04:00
|
|
|
|
(user-name (current-user-name))
|
2017-01-18 17:21:29 -05:00
|
|
|
|
|
|
|
|
|
;; When true, provide machine-readable "build
|
|
|
|
|
;; traces" for use by (guix status). Old clients
|
|
|
|
|
;; are unable to make sense, which is why it's
|
|
|
|
|
;; disabled by default.
|
|
|
|
|
print-extended-build-trace?
|
|
|
|
|
|
2018-10-15 16:40:35 -04:00
|
|
|
|
;; When true, the daemon prefixes builder output
|
|
|
|
|
;; with "@ build-log" traces so we can
|
|
|
|
|
;; distinguish it from daemon output, and we can
|
|
|
|
|
;; distinguish each builder's output
|
|
|
|
|
;; (PRINT-BUILD-TRACE must be true as well.) The
|
|
|
|
|
;; latter is particularly useful when
|
|
|
|
|
;; MAX-BUILD-JOBS > 1.
|
|
|
|
|
multiplexed-build-output?
|
|
|
|
|
|
2017-01-15 09:13:07 -05:00
|
|
|
|
build-cores
|
2013-02-03 17:02:14 -05:00
|
|
|
|
(use-substitutes? #t)
|
2015-03-22 18:43:25 -04:00
|
|
|
|
|
2015-10-28 10:20:06 -04:00
|
|
|
|
;; Client-provided substitute URLs. If it is #f,
|
|
|
|
|
;; the daemon's settings are used. Otherwise, it
|
|
|
|
|
;; overrides the daemons settings; see 'guix
|
|
|
|
|
;; substitute'.
|
2016-04-14 18:10:22 -04:00
|
|
|
|
(substitute-urls #f)
|
|
|
|
|
|
|
|
|
|
;; Number of columns in the client's terminal.
|
2016-04-20 17:16:47 -04:00
|
|
|
|
(terminal-columns (terminal-columns))
|
|
|
|
|
|
|
|
|
|
;; Locale of the client.
|
2020-09-02 09:56:47 -04:00
|
|
|
|
(locale (false-if-exception (setlocale LC_MESSAGES))))
|
2012-04-18 17:34:12 -04:00
|
|
|
|
;; Must be called after `open-connection'.
|
|
|
|
|
|
2020-06-05 04:38:32 -04:00
|
|
|
|
(define buffered
|
|
|
|
|
(store-connection-output-port server))
|
2012-04-18 17:34:12 -04:00
|
|
|
|
|
2019-11-21 09:28:13 -05:00
|
|
|
|
(unless (unspecified? use-build-hook?)
|
|
|
|
|
(warn-about-deprecation #:use-build-hook? #f
|
|
|
|
|
#:replacement #:offload?))
|
|
|
|
|
|
2012-04-18 17:34:12 -04:00
|
|
|
|
(let-syntax ((send (syntax-rules ()
|
2012-06-30 18:09:47 -04:00
|
|
|
|
((_ (type option) ...)
|
|
|
|
|
(begin
|
2020-06-05 04:38:32 -04:00
|
|
|
|
(write-arg type option buffered)
|
2012-06-30 18:09:47 -04:00
|
|
|
|
...)))))
|
2020-06-05 04:38:32 -04:00
|
|
|
|
(write-int (operation-id set-options) buffered)
|
2012-06-30 18:09:47 -04:00
|
|
|
|
(send (boolean keep-failed?) (boolean keep-going?)
|
2017-01-15 09:13:07 -05:00
|
|
|
|
(boolean fallback?) (integer verbosity))
|
2019-01-21 09:32:35 -05:00
|
|
|
|
(when (< (store-connection-minor-version server) #x61)
|
2017-01-15 09:13:07 -05:00
|
|
|
|
(let ((max-build-jobs (or max-build-jobs 1))
|
|
|
|
|
(max-silent-time (or max-silent-time 3600)))
|
|
|
|
|
(send (integer max-build-jobs) (integer max-silent-time))))
|
2019-01-21 09:32:35 -05:00
|
|
|
|
(when (>= (store-connection-minor-version server) 2)
|
2019-11-21 09:28:13 -05:00
|
|
|
|
(send (boolean (if (unspecified? use-build-hook?)
|
|
|
|
|
offload?
|
|
|
|
|
use-build-hook?))))
|
2019-01-21 09:32:35 -05:00
|
|
|
|
(when (>= (store-connection-minor-version server) 4)
|
2014-02-27 13:17:10 -05:00
|
|
|
|
(send (integer build-verbosity) (integer log-type)
|
|
|
|
|
(boolean print-build-trace)))
|
2019-01-21 09:32:35 -05:00
|
|
|
|
(when (and (>= (store-connection-minor-version server) 6)
|
|
|
|
|
(< (store-connection-minor-version server) #x61))
|
2017-01-15 09:13:07 -05:00
|
|
|
|
(let ((build-cores (or build-cores (current-processor-count))))
|
|
|
|
|
(send (integer build-cores))))
|
2019-01-21 09:32:35 -05:00
|
|
|
|
(when (>= (store-connection-minor-version server) 10)
|
2014-02-27 13:17:10 -05:00
|
|
|
|
(send (boolean use-substitutes?)))
|
2019-01-21 09:32:35 -05:00
|
|
|
|
(when (>= (store-connection-minor-version server) 12)
|
2017-01-18 17:21:29 -05:00
|
|
|
|
(let ((pairs `(;; This option is honored by 'guix substitute' et al.
|
|
|
|
|
,@(if print-build-trace
|
|
|
|
|
`(("print-extended-build-trace"
|
|
|
|
|
. ,(if print-extended-build-trace? "1" "0")))
|
|
|
|
|
'())
|
2018-10-15 16:40:35 -04:00
|
|
|
|
,@(if multiplexed-build-output?
|
|
|
|
|
`(("multiplexed-build-output"
|
|
|
|
|
. ,(if multiplexed-build-output? "true" "false")))
|
|
|
|
|
'())
|
2017-01-18 17:21:29 -05:00
|
|
|
|
,@(if timeout
|
2015-03-18 09:39:53 -04:00
|
|
|
|
`(("build-timeout" . ,(number->string timeout)))
|
|
|
|
|
'())
|
2017-01-15 09:13:07 -05:00
|
|
|
|
,@(if max-silent-time
|
|
|
|
|
`(("build-max-silent-time"
|
|
|
|
|
. ,(number->string max-silent-time)))
|
|
|
|
|
'())
|
|
|
|
|
,@(if max-build-jobs
|
|
|
|
|
`(("build-max-jobs"
|
|
|
|
|
. ,(number->string max-build-jobs)))
|
|
|
|
|
'())
|
|
|
|
|
,@(if build-cores
|
|
|
|
|
`(("build-cores" . ,(number->string build-cores)))
|
|
|
|
|
'())
|
2015-10-28 10:20:06 -04:00
|
|
|
|
,@(if substitute-urls
|
|
|
|
|
`(("substitute-urls"
|
|
|
|
|
. ,(string-join substitute-urls)))
|
2015-12-08 16:58:32 -05:00
|
|
|
|
'())
|
|
|
|
|
,@(if rounds
|
|
|
|
|
`(("build-repeat"
|
|
|
|
|
. ,(number->string (max 0 (1- rounds)))))
|
2016-04-14 18:10:22 -04:00
|
|
|
|
'())
|
2019-10-16 05:51:42 -04:00
|
|
|
|
,@(if user-name
|
|
|
|
|
`(("user-name" . ,user-name))
|
|
|
|
|
'())
|
2016-04-14 18:10:22 -04:00
|
|
|
|
,@(if terminal-columns
|
|
|
|
|
`(("terminal-columns"
|
|
|
|
|
. ,(number->string terminal-columns)))
|
2016-04-20 17:16:47 -04:00
|
|
|
|
'())
|
|
|
|
|
,@(if locale
|
|
|
|
|
`(("locale" . ,locale))
|
2015-10-28 10:20:06 -04:00
|
|
|
|
'()))))
|
2015-03-18 13:10:16 -04:00
|
|
|
|
(send (string-pairs pairs))))
|
2020-06-05 04:38:32 -04:00
|
|
|
|
(write-buffered-output server)
|
2012-06-16 10:13:12 -04:00
|
|
|
|
(let loop ((done? (process-stderr server)))
|
|
|
|
|
(or done? (process-stderr server)))))
|
2012-04-18 17:34:12 -04:00
|
|
|
|
|
2017-06-19 15:47:22 -04:00
|
|
|
|
(define (buffering-output-port port buffer)
|
|
|
|
|
"Return two value: an output port wrapped around PORT that uses BUFFER (a
|
|
|
|
|
bytevector) as its internal buffer, and a thunk to flush this output port."
|
|
|
|
|
;; Note: In Guile 2.2.2, custom binary output ports already have their own
|
|
|
|
|
;; 4K internal buffer.
|
|
|
|
|
(define size
|
|
|
|
|
(bytevector-length buffer))
|
|
|
|
|
|
|
|
|
|
(define total 0)
|
|
|
|
|
|
|
|
|
|
(define (flush)
|
|
|
|
|
(put-bytevector port buffer 0 total)
|
2018-09-17 16:00:26 -04:00
|
|
|
|
(force-output port)
|
2017-06-19 15:47:22 -04:00
|
|
|
|
(set! total 0))
|
|
|
|
|
|
|
|
|
|
(define (write bv offset count)
|
|
|
|
|
(if (zero? count) ;end of file
|
|
|
|
|
(flush)
|
|
|
|
|
(let loop ((offset offset)
|
|
|
|
|
(count count)
|
|
|
|
|
(written 0))
|
|
|
|
|
(cond ((= total size)
|
|
|
|
|
(flush)
|
|
|
|
|
(loop offset count written))
|
|
|
|
|
((zero? count)
|
|
|
|
|
written)
|
|
|
|
|
(else
|
|
|
|
|
(let ((to-copy (min count (- size total))))
|
|
|
|
|
(bytevector-copy! bv offset buffer total to-copy)
|
|
|
|
|
(set! total (+ total to-copy))
|
|
|
|
|
(loop (+ offset to-copy) (- count to-copy)
|
|
|
|
|
(+ written to-copy))))))))
|
|
|
|
|
|
|
|
|
|
;; Note: We need to return FLUSH because the custom binary port has no way
|
|
|
|
|
;; to be notified of a 'force-output' call on itself.
|
|
|
|
|
(values (make-custom-binary-output-port "buffering-output-port"
|
|
|
|
|
write #f #f flush)
|
|
|
|
|
flush))
|
|
|
|
|
|
2017-06-28 04:13:45 -04:00
|
|
|
|
(define profiled?
|
|
|
|
|
(let ((profiled
|
|
|
|
|
(or (and=> (getenv "GUIX_PROFILING") string-tokenize)
|
|
|
|
|
'())))
|
|
|
|
|
(lambda (component)
|
|
|
|
|
"Return true if COMPONENT profiling is active."
|
|
|
|
|
(member component profiled))))
|
|
|
|
|
|
2017-06-16 08:23:51 -04:00
|
|
|
|
(define %rpc-calls
|
|
|
|
|
;; Mapping from RPC names (symbols) to invocation counts.
|
|
|
|
|
(make-hash-table))
|
|
|
|
|
|
|
|
|
|
(define* (show-rpc-profile #:optional (port (current-error-port)))
|
|
|
|
|
"Write to PORT a summary of the RPCs that have been made."
|
|
|
|
|
(let ((profile (sort (hash-fold alist-cons '() %rpc-calls)
|
|
|
|
|
(lambda (rpc1 rpc2)
|
|
|
|
|
(< (cdr rpc1) (cdr rpc2))))))
|
|
|
|
|
(format port "Remote procedure call summary: ~a RPCs~%"
|
|
|
|
|
(match profile
|
|
|
|
|
(((names . counts) ...)
|
|
|
|
|
(reduce + 0 counts))))
|
|
|
|
|
(for-each (match-lambda
|
|
|
|
|
((rpc . count)
|
|
|
|
|
(format port " ~30a ... ~5@a~%" rpc count)))
|
|
|
|
|
profile)))
|
|
|
|
|
|
|
|
|
|
(define record-operation
|
|
|
|
|
;; Optionally, increment the number of calls of the given RPC.
|
2017-06-28 04:13:45 -04:00
|
|
|
|
(if (profiled? "rpc")
|
|
|
|
|
(begin
|
|
|
|
|
(register-profiling-hook! "rpc" show-rpc-profile)
|
|
|
|
|
(lambda (name)
|
|
|
|
|
(let ((count (or (hashq-ref %rpc-calls name) 0)))
|
|
|
|
|
(hashq-set! %rpc-calls name (+ count 1)))))
|
|
|
|
|
(lambda (_)
|
|
|
|
|
#t)))
|
2017-06-16 08:23:51 -04:00
|
|
|
|
|
2013-01-30 10:22:33 -05:00
|
|
|
|
(define-syntax operation
|
2012-04-18 17:34:12 -04:00
|
|
|
|
(syntax-rules ()
|
2013-01-30 10:22:33 -05:00
|
|
|
|
"Define a client-side RPC stub for the given operation."
|
2012-12-09 17:52:59 -05:00
|
|
|
|
((_ (name (type arg) ...) docstring return ...)
|
2013-01-30 10:22:33 -05:00
|
|
|
|
(lambda (server arg ...)
|
2012-04-18 17:34:12 -04:00
|
|
|
|
docstring
|
2019-01-21 09:32:35 -05:00
|
|
|
|
(let* ((s (store-connection-socket server))
|
|
|
|
|
(buffered (store-connection-output-port server)))
|
2017-06-16 08:23:51 -04:00
|
|
|
|
(record-operation 'name)
|
2017-06-19 15:47:22 -04:00
|
|
|
|
(write-int (operation-id name) buffered)
|
|
|
|
|
(write-arg type arg buffered)
|
2012-04-18 17:34:12 -04:00
|
|
|
|
...
|
2017-06-19 15:47:22 -04:00
|
|
|
|
(write-buffered-output server)
|
|
|
|
|
|
2012-06-16 10:13:12 -04:00
|
|
|
|
;; Loop until the server is done sending error output.
|
|
|
|
|
(let loop ((done? (process-stderr server)))
|
|
|
|
|
(or done? (loop (process-stderr server))))
|
2012-12-09 17:52:59 -05:00
|
|
|
|
(values (read-arg return s) ...))))))
|
2012-04-18 17:34:12 -04:00
|
|
|
|
|
2013-01-30 10:22:33 -05:00
|
|
|
|
(define-syntax-rule (define-operation (name args ...)
|
|
|
|
|
docstring return ...)
|
|
|
|
|
(define name
|
|
|
|
|
(operation (name args ...) docstring return ...)))
|
|
|
|
|
|
2012-06-30 18:21:16 -04:00
|
|
|
|
(define-operation (valid-path? (string path))
|
2016-02-25 06:12:50 -05:00
|
|
|
|
"Return #t when PATH designates a valid store item and #f otherwise (an
|
|
|
|
|
invalid item may exist on disk but still be invalid, for instance because it
|
|
|
|
|
is the result of an aborted or failed build.)
|
|
|
|
|
|
store: Rename '&nix-error' to '&store-error'.
* guix/store.scm (&nix-error): Rename to...
(&store-error): ... this, and adjust users.
(&nix-connection-error): Rename to...
(&store-connection-error): ... this, and adjust users.
(&nix-protocol-error): Rename to...
(&store-protocol-error): ... this, adjust users.
(&nix-error, &nix-connection-error, &nix-protocol-error): Define these
condition types and their getters as deprecrated aliases.
* build-aux/run-system-tests.scm, guix/derivations.scm,
guix/grafts.scm, guix/scripts/challenge.scm,
guix/scripts/graph.scm, guix/scripts/lint.scm,
guix/scripts/offload.scm, guix/serialization.scm,
guix/ssh.scm, guix/tests.scm, guix/ui.scm,
tests/derivations.scm, tests/gexp.scm, tests/guix-daemon.sh,
tests/packages.scm, tests/store.scm, doc/guix.texi: Adjust to use the
new names.
2019-01-21 11:41:11 -05:00
|
|
|
|
A '&store-protocol-error' condition is raised if PATH is not prefixed by the
|
2016-02-25 06:12:50 -05:00
|
|
|
|
store directory (/gnu/store)."
|
2012-06-30 18:21:16 -04:00
|
|
|
|
boolean)
|
|
|
|
|
|
2013-02-03 17:02:14 -05:00
|
|
|
|
(define-operation (query-path-hash (store-path path))
|
2016-05-17 07:50:10 -04:00
|
|
|
|
"Return the SHA256 hash of the nar serialization of PATH as a bytevector."
|
2012-10-24 11:03:45 -04:00
|
|
|
|
base16)
|
|
|
|
|
|
2014-03-14 12:16:10 -04:00
|
|
|
|
(define hash-part->path
|
|
|
|
|
(let ((query-path-from-hash-part
|
|
|
|
|
(operation (query-path-from-hash-part (string hash))
|
|
|
|
|
#f
|
|
|
|
|
store-path)))
|
|
|
|
|
(lambda (server hash-part)
|
|
|
|
|
"Return the store path whose hash part is HASH-PART (a nix-base32
|
2019-05-25 19:33:39 -04:00
|
|
|
|
string). Return the empty string if no such path exists."
|
2014-03-14 12:16:10 -04:00
|
|
|
|
;; This RPC is primarily used by Hydra to reply to HTTP GETs of
|
|
|
|
|
;; /HASH.narinfo.
|
|
|
|
|
(query-path-from-hash-part server hash-part))))
|
|
|
|
|
|
2015-03-17 10:19:36 -04:00
|
|
|
|
(define-operation (query-path-info (store-path path))
|
|
|
|
|
"Return the info (hash, references, etc.) for PATH."
|
|
|
|
|
path-info)
|
|
|
|
|
|
2017-01-29 06:55:24 -05:00
|
|
|
|
(define add-data-to-store
|
2013-01-30 10:22:33 -05:00
|
|
|
|
;; A memoizing version of `add-to-store', to avoid repeated RPCs with
|
|
|
|
|
;; the very same arguments during a given session.
|
|
|
|
|
(let ((add-text-to-store
|
2017-01-29 06:55:24 -05:00
|
|
|
|
(operation (add-text-to-store (string name) (bytevector text)
|
2013-01-30 10:22:33 -05:00
|
|
|
|
(string-list references))
|
|
|
|
|
#f
|
2019-04-16 05:46:17 -04:00
|
|
|
|
store-path))
|
|
|
|
|
(lookup (if (profiled? "add-data-to-store-cache")
|
|
|
|
|
(let ((lookups 0)
|
|
|
|
|
(hits 0)
|
|
|
|
|
(drv 0)
|
|
|
|
|
(scheme 0))
|
|
|
|
|
(define (show-stats)
|
|
|
|
|
(define (% n)
|
|
|
|
|
(if (zero? lookups)
|
|
|
|
|
100.
|
|
|
|
|
(* 100. (/ n lookups))))
|
|
|
|
|
|
|
|
|
|
(format (current-error-port) "
|
|
|
|
|
'add-data-to-store' cache:
|
|
|
|
|
lookups: ~5@a
|
|
|
|
|
hits: ~5@a (~,1f%)
|
|
|
|
|
.drv files: ~5@a (~,1f%)
|
|
|
|
|
Scheme files: ~5@a (~,1f%)~%"
|
|
|
|
|
lookups hits (% hits)
|
|
|
|
|
drv (% drv)
|
|
|
|
|
scheme (% scheme)))
|
|
|
|
|
|
|
|
|
|
(register-profiling-hook! "add-data-to-store-cache"
|
|
|
|
|
show-stats)
|
|
|
|
|
(lambda (cache args)
|
|
|
|
|
(let ((result (hash-ref cache args)))
|
|
|
|
|
(set! lookups (+ 1 lookups))
|
|
|
|
|
(when result
|
|
|
|
|
(set! hits (+ 1 hits)))
|
|
|
|
|
(match args
|
|
|
|
|
((_ name _)
|
|
|
|
|
(cond ((string-suffix? ".drv" name)
|
|
|
|
|
(set! drv (+ drv 1)))
|
|
|
|
|
((string-suffix? "-builder" name)
|
|
|
|
|
(set! scheme (+ scheme 1)))
|
|
|
|
|
((string-suffix? ".scm" name)
|
|
|
|
|
(set! scheme (+ scheme 1))))))
|
|
|
|
|
result)))
|
|
|
|
|
hash-ref)))
|
2017-01-29 06:55:24 -05:00
|
|
|
|
(lambda* (server name bytes #:optional (references '()))
|
|
|
|
|
"Add BYTES under file NAME in the store, and return its store path.
|
2013-01-29 17:53:09 -05:00
|
|
|
|
REFERENCES is the list of store paths referred to by the resulting store
|
|
|
|
|
path."
|
2017-01-29 06:55:24 -05:00
|
|
|
|
(let* ((args `(,bytes ,name ,references))
|
2019-01-21 09:32:35 -05:00
|
|
|
|
(cache (store-connection-add-text-to-store-cache server)))
|
2019-04-16 05:46:17 -04:00
|
|
|
|
(or (lookup cache args)
|
2017-01-29 06:55:24 -05:00
|
|
|
|
(let ((path (add-text-to-store server name bytes references)))
|
2013-01-29 17:53:09 -05:00
|
|
|
|
(hash-set! cache args path)
|
|
|
|
|
path))))))
|
|
|
|
|
|
2017-01-29 06:55:24 -05:00
|
|
|
|
(define* (add-text-to-store store name text #:optional (references '()))
|
|
|
|
|
"Add TEXT under file NAME in the store, and return its store path.
|
|
|
|
|
REFERENCES is the list of store paths referred to by the resulting store
|
|
|
|
|
path."
|
|
|
|
|
(add-data-to-store store name (string->utf8 text) references))
|
|
|
|
|
|
2016-06-15 05:51:16 -04:00
|
|
|
|
(define true
|
|
|
|
|
;; Define it once and for all since we use it as a default value for
|
|
|
|
|
;; 'add-to-store' and want to make sure two default values are 'eq?' for the
|
|
|
|
|
;; purposes or memoization.
|
|
|
|
|
(lambda (file stat)
|
|
|
|
|
#t))
|
|
|
|
|
|
2013-01-30 10:22:33 -05:00
|
|
|
|
(define add-to-store
|
2013-01-28 18:16:18 -05:00
|
|
|
|
;; A memoizing version of `add-to-store'. This is important because
|
|
|
|
|
;; `add-to-store' leads to huge data transfers to the server, and
|
|
|
|
|
;; because it's often called many times with the very same argument.
|
2016-06-15 05:51:16 -04:00
|
|
|
|
(let ((add-to-store
|
|
|
|
|
(lambda* (server basename recursive? hash-algo file-name
|
|
|
|
|
#:key (select? true))
|
|
|
|
|
;; We don't use the 'operation' macro so we can pass SELECT? to
|
|
|
|
|
;; 'write-file'.
|
2017-07-10 10:56:19 -04:00
|
|
|
|
(record-operation 'add-to-store)
|
2020-06-05 04:38:32 -04:00
|
|
|
|
(let ((port (store-connection-socket server))
|
|
|
|
|
(buffered (store-connection-output-port server)))
|
|
|
|
|
(write-int (operation-id add-to-store) buffered)
|
|
|
|
|
(write-string basename buffered)
|
|
|
|
|
(write-int 1 buffered) ;obsolete, must be #t
|
|
|
|
|
(write-int (if recursive? 1 0) buffered)
|
|
|
|
|
(write-string hash-algo buffered)
|
|
|
|
|
(write-file file-name buffered #:select? select?)
|
2018-09-17 16:00:26 -04:00
|
|
|
|
(write-buffered-output server)
|
2016-06-15 05:51:16 -04:00
|
|
|
|
(let loop ((done? (process-stderr server)))
|
|
|
|
|
(or done? (loop (process-stderr server))))
|
|
|
|
|
(read-store-path port)))))
|
|
|
|
|
(lambda* (server basename recursive? hash-algo file-name
|
|
|
|
|
#:key (select? true))
|
2013-01-30 10:30:49 -05:00
|
|
|
|
"Add the contents of FILE-NAME under BASENAME to the store. When
|
2015-06-19 04:17:37 -04:00
|
|
|
|
RECURSIVE? is false, FILE-NAME must designate a regular file--not a directory
|
|
|
|
|
nor a symlink. When RECURSIVE? is true and FILE-NAME designates a directory,
|
|
|
|
|
the contents of FILE-NAME are added recursively; if FILE-NAME designates a
|
|
|
|
|
flat file and RECURSIVE? is true, its contents are added, and its permission
|
2016-06-15 05:51:16 -04:00
|
|
|
|
bits are kept. HASH-ALGO must be a string such as \"sha256\".
|
|
|
|
|
|
|
|
|
|
When RECURSIVE? is true, call (SELECT? FILE STAT) for each directory entry,
|
|
|
|
|
where FILE is the entry's absolute file name and STAT is the result of
|
|
|
|
|
'lstat'; exclude entries for which SELECT? does not return true."
|
2017-06-12 09:38:49 -04:00
|
|
|
|
;; Note: We don't stat FILE-NAME at each call, and thus we assume that
|
|
|
|
|
;; the file remains unchanged for the lifetime of SERVER.
|
|
|
|
|
(let* ((args `(,file-name ,basename ,recursive? ,hash-algo ,select?))
|
2019-01-21 09:32:35 -05:00
|
|
|
|
(cache (store-connection-add-to-store-cache server)))
|
2017-06-12 09:38:49 -04:00
|
|
|
|
(or (hash-ref cache args)
|
2016-06-15 05:51:16 -04:00
|
|
|
|
(let ((path (add-to-store server basename recursive?
|
|
|
|
|
hash-algo file-name
|
|
|
|
|
#:select? select?)))
|
2013-01-28 18:16:18 -05:00
|
|
|
|
(hash-set! cache args path)
|
|
|
|
|
path))))))
|
|
|
|
|
|
2018-07-16 03:55:49 -04:00
|
|
|
|
(define %not-slash
|
|
|
|
|
(char-set-complement (char-set #\/)))
|
|
|
|
|
|
|
|
|
|
(define* (add-file-tree-to-store server tree
|
|
|
|
|
#:key
|
|
|
|
|
(hash-algo "sha256")
|
|
|
|
|
(recursive? #t))
|
|
|
|
|
"Add the given TREE to the store on SERVER. TREE must be an entry such as:
|
|
|
|
|
|
|
|
|
|
(\"my-tree\" directory
|
|
|
|
|
(\"a\" regular (data \"hello\"))
|
|
|
|
|
(\"b\" symlink \"a\")
|
|
|
|
|
(\"c\" directory
|
|
|
|
|
(\"d\" executable (file \"/bin/sh\"))))
|
|
|
|
|
|
|
|
|
|
This is a generalized version of 'add-to-store'. It allows you to reproduce
|
|
|
|
|
an arbitrary directory layout in the store without creating a derivation."
|
|
|
|
|
|
|
|
|
|
;; Note: The format of TREE was chosen to allow trees to be compared with
|
|
|
|
|
;; 'equal?', which in turn allows us to memoize things.
|
|
|
|
|
|
|
|
|
|
(define root
|
|
|
|
|
;; TREE is a single entry.
|
|
|
|
|
(list tree))
|
|
|
|
|
|
|
|
|
|
(define basename
|
|
|
|
|
(match tree
|
|
|
|
|
((name . _) name)))
|
|
|
|
|
|
|
|
|
|
(define (lookup file)
|
|
|
|
|
(let loop ((components (string-tokenize file %not-slash))
|
|
|
|
|
(tree root))
|
|
|
|
|
(match components
|
|
|
|
|
((basename)
|
|
|
|
|
(assoc basename tree))
|
|
|
|
|
((head . rest)
|
|
|
|
|
(loop rest
|
|
|
|
|
(match (assoc-ref tree head)
|
|
|
|
|
(('directory . entries) entries)))))))
|
|
|
|
|
|
|
|
|
|
(define (file-type+size file)
|
|
|
|
|
(match (lookup file)
|
|
|
|
|
((_ (and type (or 'directory 'symlink)) . _)
|
|
|
|
|
(values type 0))
|
|
|
|
|
((_ type ('file file))
|
|
|
|
|
(values type (stat:size (stat file))))
|
|
|
|
|
((_ type ('data (? string? data)))
|
|
|
|
|
(values type (string-length data)))
|
|
|
|
|
((_ type ('data (? bytevector? data)))
|
|
|
|
|
(values type (bytevector-length data)))))
|
|
|
|
|
|
|
|
|
|
(define (file-port file)
|
|
|
|
|
(match (lookup file)
|
|
|
|
|
((_ (or 'regular 'executable) content)
|
|
|
|
|
(match content
|
|
|
|
|
(('file (? string? file))
|
|
|
|
|
(open-file file "r0b"))
|
|
|
|
|
(('data (? string? str))
|
|
|
|
|
(open-input-string str))
|
|
|
|
|
(('data (? bytevector? bv))
|
|
|
|
|
(open-bytevector-input-port bv))))))
|
|
|
|
|
|
|
|
|
|
(define (symlink-target file)
|
|
|
|
|
(match (lookup file)
|
|
|
|
|
((_ 'symlink target) target)))
|
|
|
|
|
|
|
|
|
|
(define (directory-entries directory)
|
|
|
|
|
(match (lookup directory)
|
|
|
|
|
((_ 'directory (names . _) ...) names)))
|
|
|
|
|
|
|
|
|
|
(define cache
|
2019-01-21 09:32:35 -05:00
|
|
|
|
(store-connection-add-to-store-cache server))
|
2018-07-16 03:55:49 -04:00
|
|
|
|
|
|
|
|
|
(or (hash-ref cache tree)
|
|
|
|
|
(begin
|
|
|
|
|
;; We don't use the 'operation' macro so we can use 'write-file-tree'
|
|
|
|
|
;; instead of 'write-file'.
|
|
|
|
|
(record-operation 'add-to-store/tree)
|
2020-06-05 04:38:32 -04:00
|
|
|
|
(let ((port (store-connection-socket server))
|
|
|
|
|
(buffered (store-connection-output-port server)))
|
|
|
|
|
(write-int (operation-id add-to-store) buffered)
|
|
|
|
|
(write-string basename buffered)
|
|
|
|
|
(write-int 1 buffered) ;obsolete, must be #t
|
|
|
|
|
(write-int (if recursive? 1 0) buffered)
|
|
|
|
|
(write-string hash-algo buffered)
|
|
|
|
|
(write-file-tree basename buffered
|
2018-07-16 03:55:49 -04:00
|
|
|
|
#:file-type+size file-type+size
|
|
|
|
|
#:file-port file-port
|
|
|
|
|
#:symlink-target symlink-target
|
|
|
|
|
#:directory-entries directory-entries)
|
2018-09-18 15:37:23 -04:00
|
|
|
|
(write-buffered-output server)
|
2018-07-16 03:55:49 -04:00
|
|
|
|
(let loop ((done? (process-stderr server)))
|
|
|
|
|
(or done? (loop (process-stderr server))))
|
|
|
|
|
(let ((result (read-store-path port)))
|
|
|
|
|
(hash-set! cache tree result)
|
|
|
|
|
result)))))
|
|
|
|
|
|
2020-01-29 19:17:54 -05:00
|
|
|
|
(define (file-mapping->tree mapping)
|
|
|
|
|
"Convert MAPPING, an alist like:
|
|
|
|
|
|
|
|
|
|
((\"guix/build/utils.scm\" . \"…/utils.scm\"))
|
|
|
|
|
|
|
|
|
|
to a tree suitable for 'add-file-tree-to-store' and 'interned-file-tree'."
|
|
|
|
|
(let ((mapping (map (match-lambda
|
|
|
|
|
((destination . source)
|
|
|
|
|
(cons (string-tokenize destination %not-slash)
|
|
|
|
|
source)))
|
|
|
|
|
mapping)))
|
|
|
|
|
(fold (lambda (pair result)
|
|
|
|
|
(match pair
|
|
|
|
|
((destination . source)
|
|
|
|
|
(let loop ((destination destination)
|
|
|
|
|
(result result))
|
|
|
|
|
(match destination
|
|
|
|
|
((file)
|
|
|
|
|
(let* ((mode (stat:mode (stat source)))
|
|
|
|
|
(type (if (zero? (logand mode #o100))
|
|
|
|
|
'regular
|
|
|
|
|
'executable)))
|
|
|
|
|
(alist-cons file
|
|
|
|
|
`(,type (file ,source))
|
|
|
|
|
result)))
|
|
|
|
|
((file rest ...)
|
|
|
|
|
(let ((directory (assoc-ref result file)))
|
|
|
|
|
(alist-cons file
|
|
|
|
|
`(directory
|
|
|
|
|
,@(loop rest
|
|
|
|
|
(match directory
|
|
|
|
|
(('directory . entries) entries)
|
|
|
|
|
(#f '()))))
|
|
|
|
|
(if directory
|
|
|
|
|
(alist-delete file result)
|
|
|
|
|
result)))))))))
|
|
|
|
|
'()
|
|
|
|
|
mapping)))
|
|
|
|
|
|
2020-03-18 17:17:39 -04:00
|
|
|
|
(define current-build-prompt
|
|
|
|
|
;; When true, this is the prompt to abort to when 'build-things' is called.
|
|
|
|
|
(make-parameter #f))
|
|
|
|
|
|
|
|
|
|
(define (call-with-build-handler handler thunk)
|
|
|
|
|
"Register HANDLER as a \"build handler\" and invoke THUNK."
|
|
|
|
|
(define tag
|
|
|
|
|
(make-prompt-tag "build handler"))
|
|
|
|
|
|
|
|
|
|
(parameterize ((current-build-prompt tag))
|
|
|
|
|
(call-with-prompt tag
|
|
|
|
|
thunk
|
|
|
|
|
(lambda (k . args)
|
|
|
|
|
;; Since HANDLER may call K, which in turn may call 'build-things'
|
|
|
|
|
;; again, reinstate a prompt (thus, it's not a tail call.)
|
|
|
|
|
(call-with-build-handler handler
|
|
|
|
|
(lambda ()
|
|
|
|
|
(apply handler k args)))))))
|
|
|
|
|
|
|
|
|
|
(define (invoke-build-handler store things mode)
|
|
|
|
|
"Abort to 'current-build-prompt' if it is set."
|
|
|
|
|
(or (not (current-build-prompt))
|
|
|
|
|
(abort-to-prompt (current-build-prompt) store things mode)))
|
|
|
|
|
|
|
|
|
|
(define-syntax-rule (with-build-handler handler exp ...)
|
|
|
|
|
"Register HANDLER as a \"build handler\" and invoke THUNK. When
|
|
|
|
|
'build-things' is called within the dynamic extent of the call to THUNK,
|
|
|
|
|
HANDLER is invoked like so:
|
|
|
|
|
|
|
|
|
|
(HANDLER CONTINUE STORE THINGS MODE)
|
|
|
|
|
|
|
|
|
|
where CONTINUE is the continuation, and the remaining arguments are those that
|
|
|
|
|
were passed to 'build-things'.
|
|
|
|
|
|
|
|
|
|
Build handlers are useful to announce a build plan with 'show-what-to-build'
|
|
|
|
|
and to implement dry runs (by not invoking CONTINUE) in a way that gracefully
|
|
|
|
|
deals with \"dynamic dependencies\" such as grafts---derivations that depend
|
|
|
|
|
on the build output of a previous derivation."
|
|
|
|
|
(call-with-build-handler handler (lambda () exp ...)))
|
|
|
|
|
|
2020-03-25 07:41:18 -04:00
|
|
|
|
;; Unresolved dynamic dependency.
|
|
|
|
|
(define-record-type <unresolved>
|
|
|
|
|
(unresolved things continuation)
|
|
|
|
|
unresolved?
|
|
|
|
|
(things unresolved-things)
|
|
|
|
|
(continuation unresolved-continuation))
|
|
|
|
|
|
2021-10-28 13:21:50 -04:00
|
|
|
|
(define (build-accumulator expected-store)
|
|
|
|
|
"Return a build handler that accumulates THINGS and returns an <unresolved>
|
|
|
|
|
object, only for build requests on EXPECTED-STORE."
|
|
|
|
|
(lambda (continue store things mode)
|
2021-11-09 18:39:10 -05:00
|
|
|
|
;; Note: Do not compare STORE and EXPECTED-STORE with 'eq?' because
|
|
|
|
|
;; 'cache-object-mapping' and similar functional "setters" change the
|
|
|
|
|
;; store's object identity.
|
|
|
|
|
(if (and (eq? (store-connection-socket store)
|
|
|
|
|
(store-connection-socket expected-store))
|
2021-10-28 13:21:50 -04:00
|
|
|
|
(= mode (build-mode normal)))
|
2022-05-30 09:58:05 -04:00
|
|
|
|
(begin
|
|
|
|
|
;; Preserve caches accumulated up to this handler invocation.
|
|
|
|
|
(set-store-connection-caches! expected-store
|
|
|
|
|
(store-connection-caches store))
|
|
|
|
|
|
|
|
|
|
(unresolved things
|
|
|
|
|
(lambda (new-store value)
|
|
|
|
|
;; Borrow caches from NEW-STORE.
|
|
|
|
|
(set-store-connection-caches!
|
|
|
|
|
store (store-connection-caches new-store))
|
|
|
|
|
(continue value))))
|
2021-10-28 13:21:50 -04:00
|
|
|
|
(continue #t))))
|
2020-03-25 07:41:18 -04:00
|
|
|
|
|
2022-05-13 10:47:49 -04:00
|
|
|
|
(define default-cutoff
|
|
|
|
|
;; Default cutoff parameter for 'map/accumulate-builds'.
|
|
|
|
|
(make-parameter 32))
|
|
|
|
|
|
2021-09-15 10:23:48 -04:00
|
|
|
|
(define* (map/accumulate-builds store proc lst
|
2022-05-13 10:47:49 -04:00
|
|
|
|
#:key (cutoff (default-cutoff)))
|
2020-03-25 07:41:18 -04:00
|
|
|
|
"Apply PROC over each element of LST, accumulating 'build-things' calls and
|
2021-09-15 10:23:48 -04:00
|
|
|
|
coalescing them into a single call.
|
|
|
|
|
|
|
|
|
|
CUTOFF is the threshold above which we stop accumulating unresolved nodes."
|
|
|
|
|
|
|
|
|
|
;; The CUTOFF parameter helps avoid pessimal behavior where we keep
|
|
|
|
|
;; stumbling upon the same .drv build requests with many incoming edges.
|
|
|
|
|
;; See <https://bugs.gnu.org/49439>.
|
2021-08-10 06:24:44 -04:00
|
|
|
|
|
2021-10-28 13:21:50 -04:00
|
|
|
|
(define accumulator
|
|
|
|
|
(build-accumulator store))
|
|
|
|
|
|
2021-08-10 06:24:44 -04:00
|
|
|
|
(define-values (result rest)
|
2022-05-13 10:47:49 -04:00
|
|
|
|
;; Have the default cutoff decay as we go deeper in the call stack to
|
|
|
|
|
;; avoid pessimal behavior.
|
|
|
|
|
(parameterize ((default-cutoff (quotient cutoff 2)))
|
|
|
|
|
(let loop ((lst lst)
|
|
|
|
|
(result '())
|
|
|
|
|
(unresolved 0))
|
|
|
|
|
(match lst
|
|
|
|
|
((head . tail)
|
|
|
|
|
(match (with-build-handler accumulator
|
|
|
|
|
(proc head))
|
|
|
|
|
((? unresolved? obj)
|
|
|
|
|
(if (>= unresolved cutoff)
|
|
|
|
|
(values (reverse (cons obj result)) tail)
|
|
|
|
|
(loop tail (cons obj result) (+ 1 unresolved))))
|
|
|
|
|
(obj
|
|
|
|
|
(loop tail (cons obj result) unresolved))))
|
|
|
|
|
(()
|
|
|
|
|
(values (reverse result) lst))))))
|
2020-03-25 07:41:18 -04:00
|
|
|
|
|
|
|
|
|
(match (append-map (lambda (obj)
|
|
|
|
|
(if (unresolved? obj)
|
|
|
|
|
(unresolved-things obj)
|
|
|
|
|
'()))
|
|
|
|
|
result)
|
|
|
|
|
(()
|
2021-08-10 06:24:44 -04:00
|
|
|
|
;; REST is necessarily empty.
|
2020-03-25 07:41:18 -04:00
|
|
|
|
result)
|
|
|
|
|
(to-build
|
2021-09-15 10:23:48 -04:00
|
|
|
|
;; We've accumulated things TO-BUILD; build them.
|
2020-03-25 07:41:18 -04:00
|
|
|
|
(build-things store (delete-duplicates to-build))
|
2021-09-15 10:23:48 -04:00
|
|
|
|
|
|
|
|
|
;; Resume the continuations corresponding to TO-BUILD, and then process
|
|
|
|
|
;; REST.
|
|
|
|
|
(append (map/accumulate-builds store
|
|
|
|
|
(lambda (obj)
|
|
|
|
|
(if (unresolved? obj)
|
|
|
|
|
;; Pass #f because 'build-things' is now
|
|
|
|
|
;; unnecessary.
|
2022-05-30 09:58:05 -04:00
|
|
|
|
((unresolved-continuation obj)
|
|
|
|
|
store #f)
|
2021-09-15 10:23:48 -04:00
|
|
|
|
obj))
|
|
|
|
|
result #:cutoff cutoff)
|
|
|
|
|
(map/accumulate-builds store proc rest #:cutoff cutoff)))))
|
2020-03-25 07:41:18 -04:00
|
|
|
|
|
2015-12-03 12:08:35 -05:00
|
|
|
|
(define build-things
|
|
|
|
|
(let ((build (operation (build-things (string-list things)
|
|
|
|
|
(integer mode))
|
|
|
|
|
"Do it!"
|
2015-12-04 04:32:50 -05:00
|
|
|
|
boolean))
|
|
|
|
|
(build/old (operation (build-things (string-list things))
|
|
|
|
|
"Do it!"
|
|
|
|
|
boolean)))
|
2015-12-03 12:08:35 -05:00
|
|
|
|
(lambda* (store things #:optional (mode (build-mode normal)))
|
|
|
|
|
"Build THINGS, a list of store items which may be either '.drv' files or
|
2015-02-02 06:25:34 -05:00
|
|
|
|
outputs, and return when the worker is done building them. Elements of THINGS
|
|
|
|
|
that are not derivations can only be substituted and not built locally.
|
2019-06-10 16:10:21 -04:00
|
|
|
|
Alternately, an element of THING can be a derivation/output name pair, in
|
|
|
|
|
which case the daemon will attempt to substitute just the requested output of
|
2020-03-18 17:17:39 -04:00
|
|
|
|
the derivation. Return #t on success.
|
|
|
|
|
|
|
|
|
|
When a handler is installed with 'with-build-handler', it is called any time
|
|
|
|
|
'build-things' is called."
|
|
|
|
|
(or (not (invoke-build-handler store things mode))
|
|
|
|
|
(let ((things (map (match-lambda
|
|
|
|
|
((drv . output) (string-append drv "!" output))
|
|
|
|
|
(thing thing))
|
|
|
|
|
things)))
|
|
|
|
|
(parameterize ((current-store-protocol-version
|
|
|
|
|
(store-connection-version store)))
|
2022-02-08 21:01:04 -05:00
|
|
|
|
(when (< (current-store-protocol-version) #x163)
|
|
|
|
|
;; This corresponds to the first version bump of the daemon
|
|
|
|
|
;; since the introduction of lzip compression support. The
|
|
|
|
|
;; version change happened with commit 6ef61cc4c30 on the
|
|
|
|
|
;; 2018/10/15).
|
2022-02-08 08:28:56 -05:00
|
|
|
|
(warn-about-old-daemon))
|
2020-03-18 17:17:39 -04:00
|
|
|
|
(if (>= (store-connection-minor-version store) 15)
|
|
|
|
|
(build store things mode)
|
|
|
|
|
(if (= mode (build-mode normal))
|
|
|
|
|
(build/old store things)
|
|
|
|
|
(raise (condition (&store-protocol-error
|
|
|
|
|
(message "unsupported build mode")
|
|
|
|
|
(status 1))))))))))))
|
2012-06-01 17:29:55 -04:00
|
|
|
|
|
2020-11-04 08:39:40 -05:00
|
|
|
|
(define-operation (ensure-path (store-path path))
|
2020-11-23 08:10:34 -05:00
|
|
|
|
"Ensure that a path is valid. If it is not valid, it may be made valid by
|
|
|
|
|
running a substitute. As a GC root is not created by the daemon, you may want
|
|
|
|
|
to call ADD-TEMP-ROOT on that store path."
|
2020-11-04 08:39:40 -05:00
|
|
|
|
boolean)
|
|
|
|
|
|
2021-01-21 10:06:10 -05:00
|
|
|
|
(define-operation (find-roots)
|
|
|
|
|
"Return a list of root/target pairs: for each pair, the first element is the
|
|
|
|
|
GC root file name and the second element is its target in the store.
|
|
|
|
|
|
|
|
|
|
When talking to a local daemon, this operation is equivalent to the 'gc-roots'
|
|
|
|
|
procedure in (guix store roots), except that the 'find-roots' excludes
|
|
|
|
|
potential roots that do not point to store items."
|
|
|
|
|
string-pairs)
|
|
|
|
|
|
2012-12-09 17:50:17 -05:00
|
|
|
|
(define-operation (add-temp-root (store-path path))
|
|
|
|
|
"Make PATH a temporary root for the duration of the current session.
|
|
|
|
|
Return #t."
|
|
|
|
|
boolean)
|
|
|
|
|
|
2012-10-29 19:20:53 -04:00
|
|
|
|
(define-operation (add-indirect-root (string file-name))
|
2014-04-12 16:32:10 -04:00
|
|
|
|
"Make the symlink FILE-NAME an indirect root for the garbage collector:
|
|
|
|
|
whatever store item FILE-NAME points to will not be collected. Return #t on
|
|
|
|
|
success.
|
|
|
|
|
|
|
|
|
|
FILE-NAME can be anywhere on the file system, but it must be an absolute file
|
|
|
|
|
name--it is the caller's responsibility to ensure that it is an absolute file
|
|
|
|
|
name."
|
2012-10-29 19:20:53 -04:00
|
|
|
|
boolean)
|
|
|
|
|
|
2014-04-12 16:32:10 -04:00
|
|
|
|
(define %gc-roots-directory
|
|
|
|
|
;; The place where garbage collector roots (symlinks) are kept.
|
|
|
|
|
(string-append %state-directory "/gcroots"))
|
|
|
|
|
|
|
|
|
|
(define (add-permanent-root target)
|
|
|
|
|
"Add a garbage collector root pointing to TARGET, an element of the store,
|
|
|
|
|
preventing TARGET from even being collected. This can also be used if TARGET
|
|
|
|
|
does not exist yet.
|
|
|
|
|
|
|
|
|
|
Raise an error if the caller does not have write access to the GC root
|
|
|
|
|
directory."
|
|
|
|
|
(let* ((root (string-append %gc-roots-directory "/" (basename target))))
|
|
|
|
|
(catch 'system-error
|
|
|
|
|
(lambda ()
|
|
|
|
|
(symlink target root))
|
|
|
|
|
(lambda args
|
|
|
|
|
;; If ROOT already exists, this is fine; otherwise, re-throw.
|
|
|
|
|
(unless (= EEXIST (system-error-errno args))
|
|
|
|
|
(apply throw args))))))
|
|
|
|
|
|
|
|
|
|
(define (remove-permanent-root target)
|
|
|
|
|
"Remove the permanent garbage collector root pointing to TARGET. Raise an
|
|
|
|
|
error if there is no such root."
|
|
|
|
|
(delete-file (string-append %gc-roots-directory "/" (basename target))))
|
|
|
|
|
|
2013-02-27 16:40:35 -05:00
|
|
|
|
(define references
|
|
|
|
|
(operation (query-references (store-path path))
|
|
|
|
|
"Return the list of references of PATH."
|
|
|
|
|
store-path-list))
|
|
|
|
|
|
2016-05-24 17:27:07 -04:00
|
|
|
|
(define* (fold-path store proc seed paths
|
2013-06-13 16:03:42 -04:00
|
|
|
|
#:optional (relatives (cut references store <>)))
|
2016-05-24 17:27:07 -04:00
|
|
|
|
"Call PROC for each of the RELATIVES of PATHS, exactly once, and return the
|
2013-06-13 16:03:42 -04:00
|
|
|
|
result formed from the successive calls to PROC, the first of which is passed
|
|
|
|
|
SEED."
|
2016-05-24 17:27:07 -04:00
|
|
|
|
(let loop ((paths paths)
|
2013-06-13 16:03:42 -04:00
|
|
|
|
(result seed)
|
|
|
|
|
(seen vlist-null))
|
|
|
|
|
(match paths
|
|
|
|
|
((path rest ...)
|
|
|
|
|
(if (vhash-assoc path seen)
|
|
|
|
|
(loop rest result seen)
|
|
|
|
|
(let ((seen (vhash-cons path #t seen))
|
|
|
|
|
(rest (append rest (relatives path)))
|
|
|
|
|
(result (proc path result)))
|
|
|
|
|
(loop rest result seen))))
|
|
|
|
|
(()
|
|
|
|
|
result))))
|
|
|
|
|
|
2016-05-24 17:27:07 -04:00
|
|
|
|
(define (requisites store paths)
|
|
|
|
|
"Return the requisites of PATHS, including PATHS---i.e., their closures (all
|
|
|
|
|
its references, recursively)."
|
|
|
|
|
(fold-path store cons '() paths))
|
2013-06-13 16:03:42 -04:00
|
|
|
|
|
2014-01-23 16:13:27 -05:00
|
|
|
|
(define (topologically-sorted store paths)
|
|
|
|
|
"Return a list containing PATHS and all their references sorted in
|
|
|
|
|
topological order."
|
|
|
|
|
(define (traverse)
|
|
|
|
|
;; Do a simple depth-first traversal of all of PATHS.
|
|
|
|
|
(let loop ((paths paths)
|
|
|
|
|
(visited vlist-null)
|
|
|
|
|
(result '()))
|
|
|
|
|
(define (visit n)
|
|
|
|
|
(vhash-cons n #t visited))
|
|
|
|
|
|
|
|
|
|
(define (visited? n)
|
|
|
|
|
(vhash-assoc n visited))
|
|
|
|
|
|
|
|
|
|
(match paths
|
|
|
|
|
((head tail ...)
|
|
|
|
|
(if (visited? head)
|
|
|
|
|
(loop tail visited result)
|
|
|
|
|
(call-with-values
|
|
|
|
|
(lambda ()
|
|
|
|
|
(loop (references store head)
|
|
|
|
|
(visit head)
|
|
|
|
|
result))
|
|
|
|
|
(lambda (visited result)
|
|
|
|
|
(loop tail
|
|
|
|
|
visited
|
|
|
|
|
(cons head result))))))
|
|
|
|
|
(()
|
|
|
|
|
(values visited result)))))
|
|
|
|
|
|
|
|
|
|
(call-with-values traverse
|
|
|
|
|
(lambda (_ result)
|
|
|
|
|
(reverse result))))
|
|
|
|
|
|
2013-02-27 16:40:35 -05:00
|
|
|
|
(define referrers
|
|
|
|
|
(operation (query-referrers (store-path path))
|
|
|
|
|
"Return the list of path that refer to PATH."
|
|
|
|
|
store-path-list))
|
|
|
|
|
|
|
|
|
|
(define valid-derivers
|
|
|
|
|
(operation (query-valid-derivers (store-path path))
|
|
|
|
|
"Return the list of valid \"derivers\" of PATH---i.e., all the
|
|
|
|
|
.drv present in the store that have PATH among their outputs."
|
|
|
|
|
store-path-list))
|
|
|
|
|
|
|
|
|
|
(define query-derivation-outputs ; avoid name clash with `derivation-outputs'
|
|
|
|
|
(operation (query-derivation-outputs (store-path path))
|
|
|
|
|
"Return the list of outputs of PATH, a .drv file."
|
|
|
|
|
store-path-list))
|
|
|
|
|
|
2013-02-03 17:24:25 -05:00
|
|
|
|
(define-operation (has-substitutes? (store-path path))
|
|
|
|
|
"Return #t if binary substitutes are available for PATH, and #f otherwise."
|
|
|
|
|
boolean)
|
|
|
|
|
|
|
|
|
|
(define substitutable-paths
|
|
|
|
|
(operation (query-substitutable-paths (store-path-list paths))
|
|
|
|
|
"Return the subset of PATHS that is substitutable."
|
|
|
|
|
store-path-list))
|
|
|
|
|
|
|
|
|
|
(define substitutable-path-info
|
2013-04-02 04:44:20 -04:00
|
|
|
|
(operation (query-substitutable-path-infos (store-path-list paths))
|
2013-02-03 17:24:25 -05:00
|
|
|
|
"Return information about the subset of PATHS that is
|
|
|
|
|
substitutable. For each substitutable path, a `substitutable?' object is
|
2016-03-05 16:01:33 -05:00
|
|
|
|
returned; thus, the resulting list can be shorter than PATHS. Furthermore,
|
|
|
|
|
that there is no guarantee that the order of the resulting list matches the
|
|
|
|
|
order of PATHS."
|
2013-02-03 17:24:25 -05:00
|
|
|
|
substitutable-path-list))
|
|
|
|
|
|
2019-04-16 04:26:46 -04:00
|
|
|
|
(define %built-in-builders
|
2016-11-13 16:59:54 -05:00
|
|
|
|
(let ((builders (operation (built-in-builders)
|
|
|
|
|
"Return the built-in builders."
|
|
|
|
|
string-list)))
|
|
|
|
|
(lambda (store)
|
|
|
|
|
"Return the names of the supported built-in derivation builders
|
2019-04-16 04:26:46 -04:00
|
|
|
|
supported by STORE. The result is memoized for STORE."
|
2016-11-13 16:59:54 -05:00
|
|
|
|
;; Check whether STORE's version supports this RPC and built-in
|
|
|
|
|
;; derivation builders in general, which appeared in Guix > 0.11.0.
|
|
|
|
|
;; Return the empty list if it doesn't. Note that this RPC does not
|
|
|
|
|
;; exist in 'nix-daemon'.
|
2019-01-21 09:32:35 -05:00
|
|
|
|
(if (or (> (store-connection-major-version store) #x100)
|
|
|
|
|
(and (= (store-connection-major-version store) #x100)
|
|
|
|
|
(>= (store-connection-minor-version store) #x60)))
|
2016-11-13 16:59:54 -05:00
|
|
|
|
(builders store)
|
|
|
|
|
'()))))
|
|
|
|
|
|
2019-04-16 04:26:46 -04:00
|
|
|
|
(define (built-in-builders store)
|
|
|
|
|
"Return the names of the supported built-in derivation builders
|
|
|
|
|
supported by STORE."
|
|
|
|
|
(force (store-connection-built-in-builders store)))
|
|
|
|
|
|
2015-05-19 03:35:52 -04:00
|
|
|
|
(define-operation (optimize-store)
|
|
|
|
|
"Optimize the store by hard-linking identical files (\"deduplication\".)
|
|
|
|
|
Return #t on success."
|
|
|
|
|
;; Note: the daemon in Guix <= 0.8.2 does not implement this RPC.
|
|
|
|
|
boolean)
|
|
|
|
|
|
2015-06-06 13:05:25 -04:00
|
|
|
|
(define verify-store
|
|
|
|
|
(let ((verify (operation (verify-store (boolean check-contents?)
|
|
|
|
|
(boolean repair?))
|
|
|
|
|
"Verify the store."
|
|
|
|
|
boolean)))
|
|
|
|
|
(lambda* (store #:key check-contents? repair?)
|
|
|
|
|
"Verify the integrity of the store and return false if errors remain,
|
|
|
|
|
and true otherwise. When REPAIR? is true, repair any missing or altered store
|
|
|
|
|
items by substituting them (this typically requires root privileges because it
|
|
|
|
|
is not an atomic operation.) When CHECK-CONTENTS? is true, check the contents
|
|
|
|
|
of store items; this can take a lot of time."
|
|
|
|
|
(not (verify store check-contents? repair?)))))
|
|
|
|
|
|
2012-12-09 17:52:59 -05:00
|
|
|
|
(define (run-gc server action to-delete min-freed)
|
|
|
|
|
"Perform the garbage-collector operation ACTION, one of the
|
|
|
|
|
`gc-action' values. When ACTION is `delete-specific', the TO-DELETE is
|
|
|
|
|
the list of store paths to delete. IGNORE-LIVENESS? should always be
|
|
|
|
|
#f. MIN-FREED is the minimum amount of disk space to be freed, in
|
|
|
|
|
bytes, before the GC can stop. Return the list of store paths delete,
|
|
|
|
|
and the number of bytes freed."
|
2020-06-05 04:38:32 -04:00
|
|
|
|
(let ((s (store-connection-socket server))
|
|
|
|
|
(buffered (store-connection-output-port server)))
|
|
|
|
|
(write-int (operation-id collect-garbage) buffered)
|
|
|
|
|
(write-int action buffered)
|
|
|
|
|
(write-store-path-list to-delete buffered)
|
|
|
|
|
(write-arg boolean #f buffered) ; ignore-liveness?
|
|
|
|
|
(write-long-long min-freed buffered)
|
|
|
|
|
(write-int 0 buffered) ; obsolete
|
2019-01-21 09:32:35 -05:00
|
|
|
|
(when (>= (store-connection-minor-version server) 5)
|
2012-12-09 17:52:59 -05:00
|
|
|
|
;; Obsolete `use-atime' and `max-atime' parameters.
|
2020-06-05 04:38:32 -04:00
|
|
|
|
(write-int 0 buffered)
|
|
|
|
|
(write-int 0 buffered))
|
|
|
|
|
(write-buffered-output server)
|
2012-12-09 17:52:59 -05:00
|
|
|
|
|
|
|
|
|
;; Loop until the server is done sending error output.
|
|
|
|
|
(let loop ((done? (process-stderr server)))
|
|
|
|
|
(or done? (loop (process-stderr server))))
|
|
|
|
|
|
|
|
|
|
(let ((paths (read-store-path-list s))
|
|
|
|
|
(freed (read-long-long s))
|
|
|
|
|
(obsolete (read-long-long s)))
|
2014-11-04 14:55:48 -05:00
|
|
|
|
(unless (null? paths)
|
|
|
|
|
;; To be on the safe side, completely invalidate both caches.
|
|
|
|
|
;; Otherwise we could end up returning store paths that are no longer
|
|
|
|
|
;; valid.
|
2019-01-21 09:32:35 -05:00
|
|
|
|
(hash-clear! (store-connection-add-to-store-cache server))
|
|
|
|
|
(hash-clear! (store-connection-add-text-to-store-cache server)))
|
2014-11-04 14:55:48 -05:00
|
|
|
|
|
2012-12-09 17:52:59 -05:00
|
|
|
|
(values paths freed))))
|
|
|
|
|
|
|
|
|
|
(define-syntax-rule (%long-long-max)
|
|
|
|
|
;; Maximum unsigned 64-bit integer.
|
|
|
|
|
(- (expt 2 64) 1))
|
|
|
|
|
|
|
|
|
|
(define (live-paths server)
|
|
|
|
|
"Return the list of live store paths---i.e., store paths still
|
|
|
|
|
referenced, and thus not subject to being garbage-collected."
|
|
|
|
|
(run-gc server (gc-action return-live) '() (%long-long-max)))
|
|
|
|
|
|
|
|
|
|
(define (dead-paths server)
|
|
|
|
|
"Return the list of dead store paths---i.e., store paths no longer
|
|
|
|
|
referenced, and thus subject to being garbage-collected."
|
|
|
|
|
(run-gc server (gc-action return-dead) '() (%long-long-max)))
|
|
|
|
|
|
|
|
|
|
(define* (collect-garbage server #:optional (min-freed (%long-long-max)))
|
|
|
|
|
"Collect garbage from the store at SERVER. If MIN-FREED is non-zero,
|
|
|
|
|
then collect at least MIN-FREED bytes. Return the paths that were
|
|
|
|
|
collected, and the number of bytes freed."
|
|
|
|
|
(run-gc server (gc-action delete-dead) '() min-freed))
|
|
|
|
|
|
|
|
|
|
(define* (delete-paths server paths #:optional (min-freed (%long-long-max)))
|
|
|
|
|
"Delete PATHS from the store at SERVER, if they are no longer
|
|
|
|
|
referenced. If MIN-FREED is non-zero, then stop after at least
|
|
|
|
|
MIN-FREED bytes have been collected. Return the paths that were
|
|
|
|
|
collected, and the number of bytes freed."
|
|
|
|
|
(run-gc server (gc-action delete-specific) paths min-freed))
|
|
|
|
|
|
2013-12-20 11:17:42 -05:00
|
|
|
|
(define (import-paths server port)
|
|
|
|
|
"Import the set of store paths read from PORT into SERVER's store. An error
|
|
|
|
|
is raised if the set of paths read from PORT is not signed (as per
|
|
|
|
|
'export-path #:sign? #t'.) Return the list of store paths imported."
|
2019-01-21 09:32:35 -05:00
|
|
|
|
(let ((s (store-connection-socket server)))
|
2013-12-20 11:17:42 -05:00
|
|
|
|
(write-int (operation-id import-paths) s)
|
|
|
|
|
(let loop ((done? (process-stderr server port)))
|
|
|
|
|
(or done? (loop (process-stderr server port))))
|
|
|
|
|
(read-store-path-list s)))
|
|
|
|
|
|
|
|
|
|
(define* (export-path server path port #:key (sign? #t))
|
|
|
|
|
"Export PATH to PORT. When SIGN? is true, sign it."
|
2020-06-05 04:38:32 -04:00
|
|
|
|
(let ((s (store-connection-socket server))
|
|
|
|
|
(buffered (store-connection-output-port server)))
|
|
|
|
|
(write-int (operation-id export-path) buffered)
|
|
|
|
|
(write-store-path path buffered)
|
|
|
|
|
(write-arg boolean sign? buffered)
|
|
|
|
|
(write-buffered-output server)
|
2013-12-20 11:17:42 -05:00
|
|
|
|
(let loop ((done? (process-stderr server port)))
|
|
|
|
|
(or done? (loop (process-stderr server port))))
|
|
|
|
|
(= 1 (read-int s))))
|
|
|
|
|
|
2020-08-31 05:36:26 -04:00
|
|
|
|
(define* (export-paths server paths port #:key (sign? #t) recursive?
|
|
|
|
|
(start (const #f))
|
|
|
|
|
(progress (const #f))
|
|
|
|
|
(finish (const #f)))
|
2014-02-10 17:30:09 -05:00
|
|
|
|
"Export the store paths listed in PATHS to PORT, in topological order,
|
2015-01-17 09:59:00 -05:00
|
|
|
|
signing them if SIGN? is true. When RECURSIVE? is true, export the closure of
|
2020-08-31 05:36:26 -04:00
|
|
|
|
PATHS---i.e., PATHS and all their dependencies.
|
|
|
|
|
|
|
|
|
|
START, PROGRESS, and FINISH are used to track progress of the data transfer.
|
|
|
|
|
START is a one-argument that is passed the list of store items that will be
|
|
|
|
|
transferred; it returns values that are then used as the initial state
|
|
|
|
|
threaded through PROGRESS calls. PROGRESS is passed the store item about to
|
|
|
|
|
be sent, along with the values previously return by START or by PROGRESS
|
|
|
|
|
itself. FINISH is called when the last store item has been called."
|
2014-03-06 18:18:28 -05:00
|
|
|
|
(define ordered
|
2015-01-17 09:59:00 -05:00
|
|
|
|
(let ((sorted (topologically-sorted server paths)))
|
|
|
|
|
;; When RECURSIVE? is #f, filter out the references of PATHS.
|
|
|
|
|
(if recursive?
|
|
|
|
|
sorted
|
|
|
|
|
(filter (cut member <> paths) sorted))))
|
2014-03-06 18:18:28 -05:00
|
|
|
|
|
2020-08-31 05:36:26 -04:00
|
|
|
|
(let loop ((paths ordered)
|
|
|
|
|
(state (call-with-values (lambda () (start ordered))
|
|
|
|
|
list)))
|
2015-01-17 10:03:35 -05:00
|
|
|
|
(match paths
|
|
|
|
|
(()
|
2020-08-31 05:36:26 -04:00
|
|
|
|
(apply finish state)
|
2015-01-17 10:03:35 -05:00
|
|
|
|
(write-int 0 port))
|
|
|
|
|
((head tail ...)
|
|
|
|
|
(write-int 1 port)
|
|
|
|
|
(and (export-path server head port #:sign? sign?)
|
2020-08-31 05:36:26 -04:00
|
|
|
|
(loop tail
|
|
|
|
|
(call-with-values
|
|
|
|
|
(lambda () (apply progress head state))
|
|
|
|
|
list)))))))
|
2013-12-20 11:17:42 -05:00
|
|
|
|
|
2015-09-28 15:32:17 -04:00
|
|
|
|
(define-operation (query-failed-paths)
|
|
|
|
|
"Return the list of store items for which a build failure is cached.
|
|
|
|
|
|
|
|
|
|
The result is always the empty list unless the daemon was started with
|
|
|
|
|
'--cache-failures'."
|
|
|
|
|
store-path-list)
|
|
|
|
|
|
|
|
|
|
(define-operation (clear-failed-paths (store-path-list items))
|
|
|
|
|
"Remove ITEMS from the list of cached build failures.
|
|
|
|
|
|
|
|
|
|
This makes sense only when the daemon was started with '--cache-failures'."
|
|
|
|
|
boolean)
|
|
|
|
|
|
2021-05-28 11:22:03 -04:00
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
;;; Per-connection caches.
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
;; Number of currently allocated store connection caches--things that go in
|
|
|
|
|
;; the 'caches' vector of <store-connection>.
|
|
|
|
|
(define %store-connection-caches (make-atomic-box 0))
|
|
|
|
|
|
2022-05-12 17:16:11 -04:00
|
|
|
|
(define %max-store-connection-caches
|
|
|
|
|
;; Maximum number of caches returned by 'allocate-store-connection-cache'.
|
|
|
|
|
32)
|
|
|
|
|
|
|
|
|
|
(define %store-connection-cache-names
|
|
|
|
|
;; Mapping of cache ID to symbol.
|
|
|
|
|
(make-vector %max-store-connection-caches))
|
|
|
|
|
|
2021-05-28 11:22:03 -04:00
|
|
|
|
(define (allocate-store-connection-cache name)
|
|
|
|
|
"Allocate a new cache for store connections and return its identifier. Said
|
|
|
|
|
identifier can be passed as an argument to "
|
|
|
|
|
(let loop ((current (atomic-box-ref %store-connection-caches)))
|
|
|
|
|
(let ((previous (atomic-box-compare-and-swap! %store-connection-caches
|
|
|
|
|
current (+ current 1))))
|
|
|
|
|
(if (= previous current)
|
2022-05-12 17:16:11 -04:00
|
|
|
|
(begin
|
|
|
|
|
(vector-set! %store-connection-cache-names current name)
|
|
|
|
|
current)
|
2021-05-28 11:22:03 -04:00
|
|
|
|
(loop current)))))
|
|
|
|
|
|
|
|
|
|
(define %object-cache-id
|
|
|
|
|
;; The "object cache", mapping lowerable objects such as <package> records
|
|
|
|
|
;; to derivations.
|
|
|
|
|
(allocate-store-connection-cache 'object-cache))
|
|
|
|
|
|
|
|
|
|
(define (vector-set vector index value)
|
|
|
|
|
(let ((new (vector-copy vector)))
|
|
|
|
|
(vector-set! new index value)
|
|
|
|
|
new))
|
|
|
|
|
|
|
|
|
|
(define (store-connection-cache store cache)
|
|
|
|
|
"Return the cache of STORE identified by CACHE, an identifier as returned by
|
|
|
|
|
'allocate-store-connection-cache'."
|
|
|
|
|
(vector-ref (store-connection-caches store) cache))
|
|
|
|
|
|
|
|
|
|
(define (set-store-connection-cache store cache value)
|
|
|
|
|
"Return a copy of STORE where CACHE has the given VALUE. CACHE must be a
|
|
|
|
|
value returned by 'allocate-store-connection-cache'."
|
|
|
|
|
(store-connection
|
|
|
|
|
(inherit store)
|
|
|
|
|
(caches (vector-set (store-connection-caches store) cache value))))
|
|
|
|
|
|
|
|
|
|
(define set-store-connection-caches! ;private
|
|
|
|
|
(record-modifier <store-connection> 'caches))
|
|
|
|
|
|
|
|
|
|
(define (set-store-connection-cache! store cache value)
|
|
|
|
|
"Set STORE's CACHE to VALUE.
|
|
|
|
|
|
|
|
|
|
This is a mutating version that should be avoided. Prefer the functional
|
|
|
|
|
'set-store-connection-cache' instead, together with using %STORE-MONAD."
|
|
|
|
|
(vector-set! (store-connection-caches store) cache value))
|
|
|
|
|
|
2021-05-31 16:38:03 -04:00
|
|
|
|
|
|
|
|
|
(define %reference-cache-id
|
|
|
|
|
;; Cache mapping store items to their list of references. Caching matters
|
|
|
|
|
;; because when building a profile in the presence of grafts, we keep
|
|
|
|
|
;; calling 'graft-derivation', which in turn calls 'references/cached' many
|
|
|
|
|
;; times with the same arguments.
|
|
|
|
|
(allocate-store-connection-cache 'reference-cache))
|
|
|
|
|
|
|
|
|
|
(define (references/cached store item)
|
|
|
|
|
"Like 'references', but cache results."
|
2022-05-29 16:58:56 -04:00
|
|
|
|
(let* ((cache (store-connection-cache store %reference-cache-id))
|
|
|
|
|
(value (vhash-assoc item cache)))
|
|
|
|
|
(record-cache-lookup! %reference-cache-id value cache)
|
|
|
|
|
(match value
|
2021-05-31 16:38:03 -04:00
|
|
|
|
((_ . references)
|
|
|
|
|
references)
|
|
|
|
|
(#f
|
|
|
|
|
(let* ((references (references store item))
|
|
|
|
|
(cache (vhash-cons item references cache)))
|
|
|
|
|
(set-store-connection-cache! store %reference-cache-id cache)
|
|
|
|
|
references)))))
|
|
|
|
|
|
monads: Move '%store-monad' and related procedures where they belong.
This turns (guix monads) into a generic module for monads, and moves the
store monad and related monadic procedures in their corresponding
module.
* guix/monads.scm (store-return, store-bind, %store-monad, store-lift,
text-file, interned-file, package-file, package->derivation,
package->cross-derivation, origin->derivation, imported-modules,
compiled, modules, built-derivations, run-with-store): Move to...
* guix/store.scm (store-return, store-bind, %store-monad, store-lift,
text-file, interned-file): ... here.
(%guile-for-build): New variable.
(run-with-store): Moved from monads.scm. Remove default value for
#:guile-for-build.
* guix/packages.scm (default-guile): Export.
(set-guile-for-build): New procedure.
(package-file, package->derivation, package->cross-derivation,
origin->derivation): Moved from monads.scm.
* guix/derivations.scm (%guile-for-build): Remove.
(imported-modules): Rename to...
(%imported-modules): ... this.
(compiled-modules): Rename to...
(%compiled-modules): ... this.
(built-derivations, imported-modules, compiled-modules): New
procedures.
* gnu/services/avahi.scm, gnu/services/base.scm, gnu/services/dbus.scm,
gnu/services/dmd.scm, gnu/services/networking.scm,
gnu/services/ssh.scm, gnu/services/xorg.scm, gnu/system/install.scm,
gnu/system/linux-initrd.scm, gnu/system/shadow.scm, guix/download.scm,
guix/gexp.scm, guix/git-download.scm, guix/profiles.scm,
guix/svn-download.scm, tests/monads.scm: Adjust imports accordingly.
* guix/monad-repl.scm (default-guile-derivation): New procedure.
(store-monad-language, run-in-store): Use it.
* build-aux/hydra/gnu-system.scm (qemu-jobs): Add explicit
'set-guile-for-build' call.
* guix/scripts/archive.scm (derivation-from-expression): Likewise.
* guix/scripts/build.scm (options/resolve-packages): Likewise.
* guix/scripts/environment.scm (guix-environment): Likewise.
* guix/scripts/system.scm (guix-system): Likewise.
* doc/guix.texi (The Store Monad): Adjust module names accordingly.
2015-01-14 07:34:52 -05:00
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
;;; Store monad.
|
|
|
|
|
;;;
|
|
|
|
|
|
2015-01-17 17:19:13 -05:00
|
|
|
|
(define-syntax-rule (define-alias new old)
|
|
|
|
|
(define-syntax new (identifier-syntax old)))
|
monads: Move '%store-monad' and related procedures where they belong.
This turns (guix monads) into a generic module for monads, and moves the
store monad and related monadic procedures in their corresponding
module.
* guix/monads.scm (store-return, store-bind, %store-monad, store-lift,
text-file, interned-file, package-file, package->derivation,
package->cross-derivation, origin->derivation, imported-modules,
compiled, modules, built-derivations, run-with-store): Move to...
* guix/store.scm (store-return, store-bind, %store-monad, store-lift,
text-file, interned-file): ... here.
(%guile-for-build): New variable.
(run-with-store): Moved from monads.scm. Remove default value for
#:guile-for-build.
* guix/packages.scm (default-guile): Export.
(set-guile-for-build): New procedure.
(package-file, package->derivation, package->cross-derivation,
origin->derivation): Moved from monads.scm.
* guix/derivations.scm (%guile-for-build): Remove.
(imported-modules): Rename to...
(%imported-modules): ... this.
(compiled-modules): Rename to...
(%compiled-modules): ... this.
(built-derivations, imported-modules, compiled-modules): New
procedures.
* gnu/services/avahi.scm, gnu/services/base.scm, gnu/services/dbus.scm,
gnu/services/dmd.scm, gnu/services/networking.scm,
gnu/services/ssh.scm, gnu/services/xorg.scm, gnu/system/install.scm,
gnu/system/linux-initrd.scm, gnu/system/shadow.scm, guix/download.scm,
guix/gexp.scm, guix/git-download.scm, guix/profiles.scm,
guix/svn-download.scm, tests/monads.scm: Adjust imports accordingly.
* guix/monad-repl.scm (default-guile-derivation): New procedure.
(store-monad-language, run-in-store): Use it.
* build-aux/hydra/gnu-system.scm (qemu-jobs): Add explicit
'set-guile-for-build' call.
* guix/scripts/archive.scm (derivation-from-expression): Likewise.
* guix/scripts/build.scm (options/resolve-packages): Likewise.
* guix/scripts/environment.scm (guix-environment): Likewise.
* guix/scripts/system.scm (guix-system): Likewise.
* doc/guix.texi (The Store Monad): Adjust module names accordingly.
2015-01-14 07:34:52 -05:00
|
|
|
|
|
2015-01-17 17:19:13 -05:00
|
|
|
|
;; The store monad allows us to (1) build sequences of operations in the
|
|
|
|
|
;; store, and (2) make the store an implicit part of the execution context,
|
|
|
|
|
;; rather than a parameter of every single function.
|
|
|
|
|
(define-alias %store-monad %state-monad)
|
|
|
|
|
(define-alias store-return state-return)
|
|
|
|
|
(define-alias store-bind state-bind)
|
monads: Move '%store-monad' and related procedures where they belong.
This turns (guix monads) into a generic module for monads, and moves the
store monad and related monadic procedures in their corresponding
module.
* guix/monads.scm (store-return, store-bind, %store-monad, store-lift,
text-file, interned-file, package-file, package->derivation,
package->cross-derivation, origin->derivation, imported-modules,
compiled, modules, built-derivations, run-with-store): Move to...
* guix/store.scm (store-return, store-bind, %store-monad, store-lift,
text-file, interned-file): ... here.
(%guile-for-build): New variable.
(run-with-store): Moved from monads.scm. Remove default value for
#:guile-for-build.
* guix/packages.scm (default-guile): Export.
(set-guile-for-build): New procedure.
(package-file, package->derivation, package->cross-derivation,
origin->derivation): Moved from monads.scm.
* guix/derivations.scm (%guile-for-build): Remove.
(imported-modules): Rename to...
(%imported-modules): ... this.
(compiled-modules): Rename to...
(%compiled-modules): ... this.
(built-derivations, imported-modules, compiled-modules): New
procedures.
* gnu/services/avahi.scm, gnu/services/base.scm, gnu/services/dbus.scm,
gnu/services/dmd.scm, gnu/services/networking.scm,
gnu/services/ssh.scm, gnu/services/xorg.scm, gnu/system/install.scm,
gnu/system/linux-initrd.scm, gnu/system/shadow.scm, guix/download.scm,
guix/gexp.scm, guix/git-download.scm, guix/profiles.scm,
guix/svn-download.scm, tests/monads.scm: Adjust imports accordingly.
* guix/monad-repl.scm (default-guile-derivation): New procedure.
(store-monad-language, run-in-store): Use it.
* build-aux/hydra/gnu-system.scm (qemu-jobs): Add explicit
'set-guile-for-build' call.
* guix/scripts/archive.scm (derivation-from-expression): Likewise.
* guix/scripts/build.scm (options/resolve-packages): Likewise.
* guix/scripts/environment.scm (guix-environment): Likewise.
* guix/scripts/system.scm (guix-system): Likewise.
* doc/guix.texi (The Store Monad): Adjust module names accordingly.
2015-01-14 07:34:52 -05:00
|
|
|
|
|
2017-05-02 16:47:36 -04:00
|
|
|
|
;; Instantiate templates for %STORE-MONAD since it's syntactically different
|
|
|
|
|
;; from %STATE-MONAD.
|
|
|
|
|
(template-directory instantiations %store-monad)
|
|
|
|
|
|
2019-10-27 14:08:15 -04:00
|
|
|
|
(define* (cache-object-mapping object keys result
|
2021-05-28 11:22:03 -04:00
|
|
|
|
#:key
|
|
|
|
|
(cache %object-cache-id)
|
|
|
|
|
(vhash-cons vhash-consq))
|
2015-11-20 12:44:29 -05:00
|
|
|
|
"Augment the store's object cache with a mapping from OBJECT/KEYS to RESULT.
|
|
|
|
|
KEYS is a list of additional keys to match against, for instance a (SYSTEM
|
2019-10-27 14:08:15 -04:00
|
|
|
|
TARGET) tuple. Use VHASH-CONS to insert OBJECT into the cache.
|
2015-11-20 12:44:29 -05:00
|
|
|
|
|
|
|
|
|
OBJECT is typically a high-level object such as a <package> or an <origin>,
|
|
|
|
|
and RESULT is typically its derivation."
|
|
|
|
|
(lambda (store)
|
|
|
|
|
(values result
|
2021-05-28 11:22:03 -04:00
|
|
|
|
(set-store-connection-cache
|
|
|
|
|
store cache
|
|
|
|
|
(vhash-cons object (cons result keys)
|
|
|
|
|
(store-connection-cache store cache))))))
|
2015-11-20 12:44:29 -05:00
|
|
|
|
|
2021-05-28 11:45:11 -04:00
|
|
|
|
(define (cache-lookup-recorder component title)
|
|
|
|
|
"Return a procedure of two arguments to record cache lookups, hits, and
|
|
|
|
|
misses for COMPONENT. The procedure must be passed a Boolean indicating
|
|
|
|
|
whether the cache lookup was a hit, and the actual cache (a vhash)."
|
|
|
|
|
(if (profiled? component)
|
2017-06-28 04:13:45 -04:00
|
|
|
|
(let ((fresh 0)
|
|
|
|
|
(lookups 0)
|
2021-02-18 16:25:18 -05:00
|
|
|
|
(hits 0)
|
|
|
|
|
(size 0))
|
2017-06-28 04:13:45 -04:00
|
|
|
|
(register-profiling-hook!
|
2021-05-28 11:45:11 -04:00
|
|
|
|
component
|
2017-06-28 04:13:45 -04:00
|
|
|
|
(lambda ()
|
2021-05-28 11:45:11 -04:00
|
|
|
|
(format (current-error-port) "~a:
|
2017-06-28 04:13:45 -04:00
|
|
|
|
fresh caches: ~5@a
|
|
|
|
|
lookups: ~5@a
|
2021-02-18 16:25:18 -05:00
|
|
|
|
hits: ~5@a (~,1f%)
|
|
|
|
|
cache size: ~5@a entries~%"
|
2021-05-28 11:45:11 -04:00
|
|
|
|
title fresh lookups hits
|
2017-06-28 04:13:45 -04:00
|
|
|
|
(if (zero? lookups)
|
|
|
|
|
100.
|
2021-02-18 16:25:18 -05:00
|
|
|
|
(* 100. (/ hits lookups)))
|
|
|
|
|
size)))
|
2017-06-28 04:13:45 -04:00
|
|
|
|
|
|
|
|
|
(lambda (hit? cache)
|
|
|
|
|
(set! fresh
|
2021-05-28 11:45:11 -04:00
|
|
|
|
(if (eq? cache vlist-null)
|
|
|
|
|
(+ 1 fresh)
|
|
|
|
|
fresh))
|
2017-06-28 04:13:45 -04:00
|
|
|
|
(set! lookups (+ 1 lookups))
|
2021-02-18 16:25:18 -05:00
|
|
|
|
(set! hits (if hit? (+ hits 1) hits))
|
|
|
|
|
(set! size (+ (if hit? 0 1)
|
|
|
|
|
(vlist-length cache)))))
|
2017-06-28 04:13:45 -04:00
|
|
|
|
(lambda (x y)
|
|
|
|
|
#t)))
|
|
|
|
|
|
2022-05-12 17:16:11 -04:00
|
|
|
|
(define recorder-for-cache
|
|
|
|
|
(let ((recorders (make-vector %max-store-connection-caches)))
|
|
|
|
|
(lambda (cache-id)
|
|
|
|
|
"Return a procedure to record lookup stats for CACHE-ID."
|
|
|
|
|
(match (vector-ref recorders cache-id)
|
|
|
|
|
((? unspecified?)
|
|
|
|
|
(let* ((name (symbol->string
|
|
|
|
|
(vector-ref %store-connection-cache-names cache-id)))
|
|
|
|
|
(description
|
|
|
|
|
(string-titlecase
|
|
|
|
|
(string-map (match-lambda
|
|
|
|
|
(#\- #\space)
|
|
|
|
|
(chr chr))
|
|
|
|
|
name))))
|
|
|
|
|
(let ((proc (cache-lookup-recorder name description)))
|
|
|
|
|
(vector-set! recorders cache-id proc)
|
|
|
|
|
proc)))
|
|
|
|
|
(proc proc)))))
|
|
|
|
|
|
|
|
|
|
(define (record-cache-lookup! cache-id value cache)
|
|
|
|
|
"Record the lookup of VALUE in CACHE-ID, whose current value is CACHE."
|
|
|
|
|
(let ((record! (recorder-for-cache cache-id)))
|
|
|
|
|
(record! value cache)))
|
|
|
|
|
|
|
|
|
|
(define-inlinable (lookup-cached-object cache-id object keys vhash-fold*)
|
|
|
|
|
"Return the object in store cache CACHE-ID corresponding to OBJECT
|
2019-10-27 14:08:15 -04:00
|
|
|
|
and KEYS; use VHASH-FOLD* to look for OBJECT in the cache. KEYS is a list of
|
|
|
|
|
additional keys to match against, and which are compared with 'equal?'.
|
|
|
|
|
Return #f on failure and the cached result otherwise."
|
2015-11-20 12:44:29 -05:00
|
|
|
|
(lambda (store)
|
2022-05-12 17:16:11 -04:00
|
|
|
|
(let* ((cache (store-connection-cache store cache-id))
|
2017-06-28 04:13:45 -04:00
|
|
|
|
|
|
|
|
|
;; Escape as soon as we find the result. This avoids traversing
|
|
|
|
|
;; the whole vlist chain and significantly reduces the number of
|
|
|
|
|
;; 'hashq' calls.
|
|
|
|
|
(value (let/ec return
|
2019-10-27 14:08:15 -04:00
|
|
|
|
(vhash-fold* (lambda (item result)
|
|
|
|
|
(match item
|
|
|
|
|
((value . keys*)
|
|
|
|
|
(if (equal? keys keys*)
|
|
|
|
|
(return value)
|
|
|
|
|
result))))
|
|
|
|
|
#f object
|
|
|
|
|
cache))))
|
2022-05-12 17:16:11 -04:00
|
|
|
|
(record-cache-lookup! cache-id value cache)
|
2017-06-28 04:13:45 -04:00
|
|
|
|
(values value store))))
|
2015-11-20 12:44:29 -05:00
|
|
|
|
|
2019-10-27 14:08:15 -04:00
|
|
|
|
(define* (%mcached mthunk object #:optional (keys '())
|
|
|
|
|
#:key
|
2022-05-12 17:16:11 -04:00
|
|
|
|
(cache %object-cache-id)
|
2019-10-27 14:08:15 -04:00
|
|
|
|
(vhash-cons vhash-consq)
|
|
|
|
|
(vhash-fold* vhash-foldq*))
|
2015-11-20 12:44:29 -05:00
|
|
|
|
"Bind the monadic value returned by MTHUNK, which supposedly corresponds to
|
2019-10-27 14:08:15 -04:00
|
|
|
|
OBJECT/KEYS, or return its cached value. Use VHASH-CONS to insert OBJECT into
|
|
|
|
|
the cache, and VHASH-FOLD* to look it up."
|
2022-05-12 17:16:11 -04:00
|
|
|
|
(mlet %store-monad ((cached (lookup-cached-object cache object keys
|
2021-02-19 16:30:30 -05:00
|
|
|
|
vhash-fold*)))
|
2015-11-20 12:44:29 -05:00
|
|
|
|
(if cached
|
|
|
|
|
(return cached)
|
|
|
|
|
(>>= (mthunk)
|
|
|
|
|
(lambda (result)
|
2019-10-27 14:08:15 -04:00
|
|
|
|
(cache-object-mapping object keys result
|
2022-05-12 17:16:11 -04:00
|
|
|
|
#:cache cache
|
2019-10-27 14:08:15 -04:00
|
|
|
|
#:vhash-cons vhash-cons))))))
|
2015-11-20 12:44:29 -05:00
|
|
|
|
|
2019-10-27 14:08:15 -04:00
|
|
|
|
(define-syntax mcached
|
2022-05-12 17:16:11 -04:00
|
|
|
|
(syntax-rules (eq? equal? =>)
|
2019-10-27 14:08:15 -04:00
|
|
|
|
"Run MVALUE, which corresponds to OBJECT/KEYS, and cache it; or return the
|
2015-11-20 12:44:29 -05:00
|
|
|
|
value associated with OBJECT/KEYS in the store's object cache if there is
|
|
|
|
|
one."
|
2022-05-12 17:16:11 -04:00
|
|
|
|
((_ eq? (=> cache) mvalue object keys ...)
|
2019-10-27 14:08:15 -04:00
|
|
|
|
(%mcached (lambda () mvalue)
|
|
|
|
|
object (list keys ...)
|
2022-05-12 17:16:11 -04:00
|
|
|
|
#:cache cache
|
2019-10-27 14:08:15 -04:00
|
|
|
|
#:vhash-cons vhash-consq
|
|
|
|
|
#:vhash-fold* vhash-foldq*))
|
2022-05-12 17:16:11 -04:00
|
|
|
|
((_ equal? (=> cache) mvalue object keys ...)
|
2019-10-27 14:08:15 -04:00
|
|
|
|
(%mcached (lambda () mvalue)
|
|
|
|
|
object (list keys ...)
|
2022-05-12 17:16:11 -04:00
|
|
|
|
#:cache cache
|
2019-10-27 14:08:15 -04:00
|
|
|
|
#:vhash-cons vhash-cons
|
|
|
|
|
#:vhash-fold* vhash-fold*))
|
2022-05-12 17:16:11 -04:00
|
|
|
|
((_ eq? mvalue object keys ...)
|
|
|
|
|
(mcached eq? (=> %object-cache-id)
|
|
|
|
|
mvalue object keys ...))
|
|
|
|
|
((_ equal? mvalue object keys ...)
|
|
|
|
|
(mcached equal? (=> %object-cache-id)
|
|
|
|
|
mvalue object keys ...))
|
2019-10-27 14:08:15 -04:00
|
|
|
|
((_ mvalue object keys ...)
|
|
|
|
|
(mcached eq? mvalue object keys ...))))
|
2015-11-20 12:44:29 -05:00
|
|
|
|
|
2015-01-18 11:38:15 -05:00
|
|
|
|
(define (preserve-documentation original proc)
|
|
|
|
|
"Return PROC with documentation taken from ORIGINAL."
|
|
|
|
|
(set-object-property! proc 'documentation
|
|
|
|
|
(procedure-property original 'documentation))
|
|
|
|
|
proc)
|
|
|
|
|
|
monads: Move '%store-monad' and related procedures where they belong.
This turns (guix monads) into a generic module for monads, and moves the
store monad and related monadic procedures in their corresponding
module.
* guix/monads.scm (store-return, store-bind, %store-monad, store-lift,
text-file, interned-file, package-file, package->derivation,
package->cross-derivation, origin->derivation, imported-modules,
compiled, modules, built-derivations, run-with-store): Move to...
* guix/store.scm (store-return, store-bind, %store-monad, store-lift,
text-file, interned-file): ... here.
(%guile-for-build): New variable.
(run-with-store): Moved from monads.scm. Remove default value for
#:guile-for-build.
* guix/packages.scm (default-guile): Export.
(set-guile-for-build): New procedure.
(package-file, package->derivation, package->cross-derivation,
origin->derivation): Moved from monads.scm.
* guix/derivations.scm (%guile-for-build): Remove.
(imported-modules): Rename to...
(%imported-modules): ... this.
(compiled-modules): Rename to...
(%compiled-modules): ... this.
(built-derivations, imported-modules, compiled-modules): New
procedures.
* gnu/services/avahi.scm, gnu/services/base.scm, gnu/services/dbus.scm,
gnu/services/dmd.scm, gnu/services/networking.scm,
gnu/services/ssh.scm, gnu/services/xorg.scm, gnu/system/install.scm,
gnu/system/linux-initrd.scm, gnu/system/shadow.scm, guix/download.scm,
guix/gexp.scm, guix/git-download.scm, guix/profiles.scm,
guix/svn-download.scm, tests/monads.scm: Adjust imports accordingly.
* guix/monad-repl.scm (default-guile-derivation): New procedure.
(store-monad-language, run-in-store): Use it.
* build-aux/hydra/gnu-system.scm (qemu-jobs): Add explicit
'set-guile-for-build' call.
* guix/scripts/archive.scm (derivation-from-expression): Likewise.
* guix/scripts/build.scm (options/resolve-packages): Likewise.
* guix/scripts/environment.scm (guix-environment): Likewise.
* guix/scripts/system.scm (guix-system): Likewise.
* doc/guix.texi (The Store Monad): Adjust module names accordingly.
2015-01-14 07:34:52 -05:00
|
|
|
|
(define (store-lift proc)
|
|
|
|
|
"Lift PROC, a procedure whose first argument is a connection to the store,
|
|
|
|
|
in the store monad."
|
2015-01-18 11:38:15 -05:00
|
|
|
|
(preserve-documentation proc
|
|
|
|
|
(lambda args
|
|
|
|
|
(lambda (store)
|
|
|
|
|
(values (apply proc store args) store)))))
|
monads: Move '%store-monad' and related procedures where they belong.
This turns (guix monads) into a generic module for monads, and moves the
store monad and related monadic procedures in their corresponding
module.
* guix/monads.scm (store-return, store-bind, %store-monad, store-lift,
text-file, interned-file, package-file, package->derivation,
package->cross-derivation, origin->derivation, imported-modules,
compiled, modules, built-derivations, run-with-store): Move to...
* guix/store.scm (store-return, store-bind, %store-monad, store-lift,
text-file, interned-file): ... here.
(%guile-for-build): New variable.
(run-with-store): Moved from monads.scm. Remove default value for
#:guile-for-build.
* guix/packages.scm (default-guile): Export.
(set-guile-for-build): New procedure.
(package-file, package->derivation, package->cross-derivation,
origin->derivation): Moved from monads.scm.
* guix/derivations.scm (%guile-for-build): Remove.
(imported-modules): Rename to...
(%imported-modules): ... this.
(compiled-modules): Rename to...
(%compiled-modules): ... this.
(built-derivations, imported-modules, compiled-modules): New
procedures.
* gnu/services/avahi.scm, gnu/services/base.scm, gnu/services/dbus.scm,
gnu/services/dmd.scm, gnu/services/networking.scm,
gnu/services/ssh.scm, gnu/services/xorg.scm, gnu/system/install.scm,
gnu/system/linux-initrd.scm, gnu/system/shadow.scm, guix/download.scm,
guix/gexp.scm, guix/git-download.scm, guix/profiles.scm,
guix/svn-download.scm, tests/monads.scm: Adjust imports accordingly.
* guix/monad-repl.scm (default-guile-derivation): New procedure.
(store-monad-language, run-in-store): Use it.
* build-aux/hydra/gnu-system.scm (qemu-jobs): Add explicit
'set-guile-for-build' call.
* guix/scripts/archive.scm (derivation-from-expression): Likewise.
* guix/scripts/build.scm (options/resolve-packages): Likewise.
* guix/scripts/environment.scm (guix-environment): Likewise.
* guix/scripts/system.scm (guix-system): Likewise.
* doc/guix.texi (The Store Monad): Adjust module names accordingly.
2015-01-14 07:34:52 -05:00
|
|
|
|
|
2015-01-14 08:25:58 -05:00
|
|
|
|
(define (store-lower proc)
|
|
|
|
|
"Lower PROC, a monadic procedure in %STORE-MONAD, to a \"normal\" procedure
|
|
|
|
|
taking the store as its first argument."
|
2015-01-18 11:38:15 -05:00
|
|
|
|
(preserve-documentation proc
|
|
|
|
|
(lambda (store . args)
|
|
|
|
|
(run-with-store store (apply proc args)))))
|
2015-01-14 08:25:58 -05:00
|
|
|
|
|
2020-03-25 07:41:18 -04:00
|
|
|
|
(define (mapm/accumulate-builds mproc lst)
|
|
|
|
|
"Like 'mapm' in %STORE-MONAD, but accumulate 'build-things' calls and
|
|
|
|
|
coalesce them into a single call."
|
|
|
|
|
(lambda (store)
|
|
|
|
|
(values (map/accumulate-builds store
|
|
|
|
|
(lambda (obj)
|
|
|
|
|
(run-with-store store
|
2020-05-14 10:53:42 -04:00
|
|
|
|
(mproc obj)
|
|
|
|
|
#:system (%current-system)
|
|
|
|
|
#:target (%current-target-system)))
|
2020-03-25 07:41:18 -04:00
|
|
|
|
lst)
|
|
|
|
|
store)))
|
|
|
|
|
|
|
|
|
|
|
monads: Move '%store-monad' and related procedures where they belong.
This turns (guix monads) into a generic module for monads, and moves the
store monad and related monadic procedures in their corresponding
module.
* guix/monads.scm (store-return, store-bind, %store-monad, store-lift,
text-file, interned-file, package-file, package->derivation,
package->cross-derivation, origin->derivation, imported-modules,
compiled, modules, built-derivations, run-with-store): Move to...
* guix/store.scm (store-return, store-bind, %store-monad, store-lift,
text-file, interned-file): ... here.
(%guile-for-build): New variable.
(run-with-store): Moved from monads.scm. Remove default value for
#:guile-for-build.
* guix/packages.scm (default-guile): Export.
(set-guile-for-build): New procedure.
(package-file, package->derivation, package->cross-derivation,
origin->derivation): Moved from monads.scm.
* guix/derivations.scm (%guile-for-build): Remove.
(imported-modules): Rename to...
(%imported-modules): ... this.
(compiled-modules): Rename to...
(%compiled-modules): ... this.
(built-derivations, imported-modules, compiled-modules): New
procedures.
* gnu/services/avahi.scm, gnu/services/base.scm, gnu/services/dbus.scm,
gnu/services/dmd.scm, gnu/services/networking.scm,
gnu/services/ssh.scm, gnu/services/xorg.scm, gnu/system/install.scm,
gnu/system/linux-initrd.scm, gnu/system/shadow.scm, guix/download.scm,
guix/gexp.scm, guix/git-download.scm, guix/profiles.scm,
guix/svn-download.scm, tests/monads.scm: Adjust imports accordingly.
* guix/monad-repl.scm (default-guile-derivation): New procedure.
(store-monad-language, run-in-store): Use it.
* build-aux/hydra/gnu-system.scm (qemu-jobs): Add explicit
'set-guile-for-build' call.
* guix/scripts/archive.scm (derivation-from-expression): Likewise.
* guix/scripts/build.scm (options/resolve-packages): Likewise.
* guix/scripts/environment.scm (guix-environment): Likewise.
* guix/scripts/system.scm (guix-system): Likewise.
* doc/guix.texi (The Store Monad): Adjust module names accordingly.
2015-01-14 07:34:52 -05:00
|
|
|
|
;;
|
|
|
|
|
;; Store monad operators.
|
|
|
|
|
;;
|
|
|
|
|
|
2018-07-10 13:00:48 -04:00
|
|
|
|
(define* (binary-file name
|
|
|
|
|
data ;bytevector
|
|
|
|
|
#:optional (references '()))
|
|
|
|
|
"Return as a monadic value the absolute file name in the store of the file
|
|
|
|
|
containing DATA, a bytevector. REFERENCES is a list of store items that the
|
|
|
|
|
resulting text file refers to; it defaults to the empty list."
|
|
|
|
|
(lambda (store)
|
|
|
|
|
(values (add-data-to-store store name data references)
|
|
|
|
|
store)))
|
|
|
|
|
|
|
|
|
|
(define* (text-file name
|
|
|
|
|
text ;string
|
2015-02-11 16:58:53 -05:00
|
|
|
|
#:optional (references '()))
|
monads: Move '%store-monad' and related procedures where they belong.
This turns (guix monads) into a generic module for monads, and moves the
store monad and related monadic procedures in their corresponding
module.
* guix/monads.scm (store-return, store-bind, %store-monad, store-lift,
text-file, interned-file, package-file, package->derivation,
package->cross-derivation, origin->derivation, imported-modules,
compiled, modules, built-derivations, run-with-store): Move to...
* guix/store.scm (store-return, store-bind, %store-monad, store-lift,
text-file, interned-file): ... here.
(%guile-for-build): New variable.
(run-with-store): Moved from monads.scm. Remove default value for
#:guile-for-build.
* guix/packages.scm (default-guile): Export.
(set-guile-for-build): New procedure.
(package-file, package->derivation, package->cross-derivation,
origin->derivation): Moved from monads.scm.
* guix/derivations.scm (%guile-for-build): Remove.
(imported-modules): Rename to...
(%imported-modules): ... this.
(compiled-modules): Rename to...
(%compiled-modules): ... this.
(built-derivations, imported-modules, compiled-modules): New
procedures.
* gnu/services/avahi.scm, gnu/services/base.scm, gnu/services/dbus.scm,
gnu/services/dmd.scm, gnu/services/networking.scm,
gnu/services/ssh.scm, gnu/services/xorg.scm, gnu/system/install.scm,
gnu/system/linux-initrd.scm, gnu/system/shadow.scm, guix/download.scm,
guix/gexp.scm, guix/git-download.scm, guix/profiles.scm,
guix/svn-download.scm, tests/monads.scm: Adjust imports accordingly.
* guix/monad-repl.scm (default-guile-derivation): New procedure.
(store-monad-language, run-in-store): Use it.
* build-aux/hydra/gnu-system.scm (qemu-jobs): Add explicit
'set-guile-for-build' call.
* guix/scripts/archive.scm (derivation-from-expression): Likewise.
* guix/scripts/build.scm (options/resolve-packages): Likewise.
* guix/scripts/environment.scm (guix-environment): Likewise.
* guix/scripts/system.scm (guix-system): Likewise.
* doc/guix.texi (The Store Monad): Adjust module names accordingly.
2015-01-14 07:34:52 -05:00
|
|
|
|
"Return as a monadic value the absolute file name in the store of the file
|
2015-02-11 16:58:53 -05:00
|
|
|
|
containing TEXT, a string. REFERENCES is a list of store items that the
|
|
|
|
|
resulting text file refers to; it defaults to the empty list."
|
monads: Move '%store-monad' and related procedures where they belong.
This turns (guix monads) into a generic module for monads, and moves the
store monad and related monadic procedures in their corresponding
module.
* guix/monads.scm (store-return, store-bind, %store-monad, store-lift,
text-file, interned-file, package-file, package->derivation,
package->cross-derivation, origin->derivation, imported-modules,
compiled, modules, built-derivations, run-with-store): Move to...
* guix/store.scm (store-return, store-bind, %store-monad, store-lift,
text-file, interned-file): ... here.
(%guile-for-build): New variable.
(run-with-store): Moved from monads.scm. Remove default value for
#:guile-for-build.
* guix/packages.scm (default-guile): Export.
(set-guile-for-build): New procedure.
(package-file, package->derivation, package->cross-derivation,
origin->derivation): Moved from monads.scm.
* guix/derivations.scm (%guile-for-build): Remove.
(imported-modules): Rename to...
(%imported-modules): ... this.
(compiled-modules): Rename to...
(%compiled-modules): ... this.
(built-derivations, imported-modules, compiled-modules): New
procedures.
* gnu/services/avahi.scm, gnu/services/base.scm, gnu/services/dbus.scm,
gnu/services/dmd.scm, gnu/services/networking.scm,
gnu/services/ssh.scm, gnu/services/xorg.scm, gnu/system/install.scm,
gnu/system/linux-initrd.scm, gnu/system/shadow.scm, guix/download.scm,
guix/gexp.scm, guix/git-download.scm, guix/profiles.scm,
guix/svn-download.scm, tests/monads.scm: Adjust imports accordingly.
* guix/monad-repl.scm (default-guile-derivation): New procedure.
(store-monad-language, run-in-store): Use it.
* build-aux/hydra/gnu-system.scm (qemu-jobs): Add explicit
'set-guile-for-build' call.
* guix/scripts/archive.scm (derivation-from-expression): Likewise.
* guix/scripts/build.scm (options/resolve-packages): Likewise.
* guix/scripts/environment.scm (guix-environment): Likewise.
* guix/scripts/system.scm (guix-system): Likewise.
* doc/guix.texi (The Store Monad): Adjust module names accordingly.
2015-01-14 07:34:52 -05:00
|
|
|
|
(lambda (store)
|
2015-02-11 16:58:53 -05:00
|
|
|
|
(values (add-text-to-store store name text references)
|
2015-01-17 17:19:13 -05:00
|
|
|
|
store)))
|
monads: Move '%store-monad' and related procedures where they belong.
This turns (guix monads) into a generic module for monads, and moves the
store monad and related monadic procedures in their corresponding
module.
* guix/monads.scm (store-return, store-bind, %store-monad, store-lift,
text-file, interned-file, package-file, package->derivation,
package->cross-derivation, origin->derivation, imported-modules,
compiled, modules, built-derivations, run-with-store): Move to...
* guix/store.scm (store-return, store-bind, %store-monad, store-lift,
text-file, interned-file): ... here.
(%guile-for-build): New variable.
(run-with-store): Moved from monads.scm. Remove default value for
#:guile-for-build.
* guix/packages.scm (default-guile): Export.
(set-guile-for-build): New procedure.
(package-file, package->derivation, package->cross-derivation,
origin->derivation): Moved from monads.scm.
* guix/derivations.scm (%guile-for-build): Remove.
(imported-modules): Rename to...
(%imported-modules): ... this.
(compiled-modules): Rename to...
(%compiled-modules): ... this.
(built-derivations, imported-modules, compiled-modules): New
procedures.
* gnu/services/avahi.scm, gnu/services/base.scm, gnu/services/dbus.scm,
gnu/services/dmd.scm, gnu/services/networking.scm,
gnu/services/ssh.scm, gnu/services/xorg.scm, gnu/system/install.scm,
gnu/system/linux-initrd.scm, gnu/system/shadow.scm, guix/download.scm,
guix/gexp.scm, guix/git-download.scm, guix/profiles.scm,
guix/svn-download.scm, tests/monads.scm: Adjust imports accordingly.
* guix/monad-repl.scm (default-guile-derivation): New procedure.
(store-monad-language, run-in-store): Use it.
* build-aux/hydra/gnu-system.scm (qemu-jobs): Add explicit
'set-guile-for-build' call.
* guix/scripts/archive.scm (derivation-from-expression): Likewise.
* guix/scripts/build.scm (options/resolve-packages): Likewise.
* guix/scripts/environment.scm (guix-environment): Likewise.
* guix/scripts/system.scm (guix-system): Likewise.
* doc/guix.texi (The Store Monad): Adjust module names accordingly.
2015-01-14 07:34:52 -05:00
|
|
|
|
|
|
|
|
|
(define* (interned-file file #:optional name
|
2016-06-15 05:51:16 -04:00
|
|
|
|
#:key (recursive? #t) (select? true))
|
monads: Move '%store-monad' and related procedures where they belong.
This turns (guix monads) into a generic module for monads, and moves the
store monad and related monadic procedures in their corresponding
module.
* guix/monads.scm (store-return, store-bind, %store-monad, store-lift,
text-file, interned-file, package-file, package->derivation,
package->cross-derivation, origin->derivation, imported-modules,
compiled, modules, built-derivations, run-with-store): Move to...
* guix/store.scm (store-return, store-bind, %store-monad, store-lift,
text-file, interned-file): ... here.
(%guile-for-build): New variable.
(run-with-store): Moved from monads.scm. Remove default value for
#:guile-for-build.
* guix/packages.scm (default-guile): Export.
(set-guile-for-build): New procedure.
(package-file, package->derivation, package->cross-derivation,
origin->derivation): Moved from monads.scm.
* guix/derivations.scm (%guile-for-build): Remove.
(imported-modules): Rename to...
(%imported-modules): ... this.
(compiled-modules): Rename to...
(%compiled-modules): ... this.
(built-derivations, imported-modules, compiled-modules): New
procedures.
* gnu/services/avahi.scm, gnu/services/base.scm, gnu/services/dbus.scm,
gnu/services/dmd.scm, gnu/services/networking.scm,
gnu/services/ssh.scm, gnu/services/xorg.scm, gnu/system/install.scm,
gnu/system/linux-initrd.scm, gnu/system/shadow.scm, guix/download.scm,
guix/gexp.scm, guix/git-download.scm, guix/profiles.scm,
guix/svn-download.scm, tests/monads.scm: Adjust imports accordingly.
* guix/monad-repl.scm (default-guile-derivation): New procedure.
(store-monad-language, run-in-store): Use it.
* build-aux/hydra/gnu-system.scm (qemu-jobs): Add explicit
'set-guile-for-build' call.
* guix/scripts/archive.scm (derivation-from-expression): Likewise.
* guix/scripts/build.scm (options/resolve-packages): Likewise.
* guix/scripts/environment.scm (guix-environment): Likewise.
* guix/scripts/system.scm (guix-system): Likewise.
* doc/guix.texi (The Store Monad): Adjust module names accordingly.
2015-01-14 07:34:52 -05:00
|
|
|
|
"Return the name of FILE once interned in the store. Use NAME as its store
|
|
|
|
|
name, or the basename of FILE if NAME is omitted.
|
|
|
|
|
|
|
|
|
|
When RECURSIVE? is true, the contents of FILE are added recursively; if FILE
|
|
|
|
|
designates a flat file and RECURSIVE? is true, its contents are added, and its
|
2016-06-15 05:51:16 -04:00
|
|
|
|
permission bits are kept.
|
|
|
|
|
|
|
|
|
|
When RECURSIVE? is true, call (SELECT? FILE STAT) for each directory entry,
|
|
|
|
|
where FILE is the entry's absolute file name and STAT is the result of
|
|
|
|
|
'lstat'; exclude entries for which SELECT? does not return true."
|
monads: Move '%store-monad' and related procedures where they belong.
This turns (guix monads) into a generic module for monads, and moves the
store monad and related monadic procedures in their corresponding
module.
* guix/monads.scm (store-return, store-bind, %store-monad, store-lift,
text-file, interned-file, package-file, package->derivation,
package->cross-derivation, origin->derivation, imported-modules,
compiled, modules, built-derivations, run-with-store): Move to...
* guix/store.scm (store-return, store-bind, %store-monad, store-lift,
text-file, interned-file): ... here.
(%guile-for-build): New variable.
(run-with-store): Moved from monads.scm. Remove default value for
#:guile-for-build.
* guix/packages.scm (default-guile): Export.
(set-guile-for-build): New procedure.
(package-file, package->derivation, package->cross-derivation,
origin->derivation): Moved from monads.scm.
* guix/derivations.scm (%guile-for-build): Remove.
(imported-modules): Rename to...
(%imported-modules): ... this.
(compiled-modules): Rename to...
(%compiled-modules): ... this.
(built-derivations, imported-modules, compiled-modules): New
procedures.
* gnu/services/avahi.scm, gnu/services/base.scm, gnu/services/dbus.scm,
gnu/services/dmd.scm, gnu/services/networking.scm,
gnu/services/ssh.scm, gnu/services/xorg.scm, gnu/system/install.scm,
gnu/system/linux-initrd.scm, gnu/system/shadow.scm, guix/download.scm,
guix/gexp.scm, guix/git-download.scm, guix/profiles.scm,
guix/svn-download.scm, tests/monads.scm: Adjust imports accordingly.
* guix/monad-repl.scm (default-guile-derivation): New procedure.
(store-monad-language, run-in-store): Use it.
* build-aux/hydra/gnu-system.scm (qemu-jobs): Add explicit
'set-guile-for-build' call.
* guix/scripts/archive.scm (derivation-from-expression): Likewise.
* guix/scripts/build.scm (options/resolve-packages): Likewise.
* guix/scripts/environment.scm (guix-environment): Likewise.
* guix/scripts/system.scm (guix-system): Likewise.
* doc/guix.texi (The Store Monad): Adjust module names accordingly.
2015-01-14 07:34:52 -05:00
|
|
|
|
(lambda (store)
|
2015-01-17 17:19:13 -05:00
|
|
|
|
(values (add-to-store store (or name (basename file))
|
2016-06-15 05:51:16 -04:00
|
|
|
|
recursive? "sha256" file
|
|
|
|
|
#:select? select?)
|
2015-01-17 17:19:13 -05:00
|
|
|
|
store)))
|
monads: Move '%store-monad' and related procedures where they belong.
This turns (guix monads) into a generic module for monads, and moves the
store monad and related monadic procedures in their corresponding
module.
* guix/monads.scm (store-return, store-bind, %store-monad, store-lift,
text-file, interned-file, package-file, package->derivation,
package->cross-derivation, origin->derivation, imported-modules,
compiled, modules, built-derivations, run-with-store): Move to...
* guix/store.scm (store-return, store-bind, %store-monad, store-lift,
text-file, interned-file): ... here.
(%guile-for-build): New variable.
(run-with-store): Moved from monads.scm. Remove default value for
#:guile-for-build.
* guix/packages.scm (default-guile): Export.
(set-guile-for-build): New procedure.
(package-file, package->derivation, package->cross-derivation,
origin->derivation): Moved from monads.scm.
* guix/derivations.scm (%guile-for-build): Remove.
(imported-modules): Rename to...
(%imported-modules): ... this.
(compiled-modules): Rename to...
(%compiled-modules): ... this.
(built-derivations, imported-modules, compiled-modules): New
procedures.
* gnu/services/avahi.scm, gnu/services/base.scm, gnu/services/dbus.scm,
gnu/services/dmd.scm, gnu/services/networking.scm,
gnu/services/ssh.scm, gnu/services/xorg.scm, gnu/system/install.scm,
gnu/system/linux-initrd.scm, gnu/system/shadow.scm, guix/download.scm,
guix/gexp.scm, guix/git-download.scm, guix/profiles.scm,
guix/svn-download.scm, tests/monads.scm: Adjust imports accordingly.
* guix/monad-repl.scm (default-guile-derivation): New procedure.
(store-monad-language, run-in-store): Use it.
* build-aux/hydra/gnu-system.scm (qemu-jobs): Add explicit
'set-guile-for-build' call.
* guix/scripts/archive.scm (derivation-from-expression): Likewise.
* guix/scripts/build.scm (options/resolve-packages): Likewise.
* guix/scripts/environment.scm (guix-environment): Likewise.
* guix/scripts/system.scm (guix-system): Likewise.
* doc/guix.texi (The Store Monad): Adjust module names accordingly.
2015-01-14 07:34:52 -05:00
|
|
|
|
|
2018-07-16 03:55:49 -04:00
|
|
|
|
(define interned-file-tree
|
|
|
|
|
(store-lift add-file-tree-to-store))
|
|
|
|
|
|
2015-02-02 06:25:34 -05:00
|
|
|
|
(define build
|
|
|
|
|
;; Monadic variant of 'build-things'.
|
|
|
|
|
(store-lift build-things))
|
|
|
|
|
|
2015-09-03 11:33:51 -04:00
|
|
|
|
(define set-build-options*
|
|
|
|
|
(store-lift set-build-options))
|
|
|
|
|
|
2016-11-19 11:05:07 -05:00
|
|
|
|
(define references*
|
|
|
|
|
(store-lift references))
|
|
|
|
|
|
2018-07-02 17:50:38 -04:00
|
|
|
|
(define (query-path-info* item)
|
|
|
|
|
"Monadic version of 'query-path-info' that returns #f when ITEM is not in
|
|
|
|
|
the store."
|
|
|
|
|
(lambda (store)
|
store: Rename '&nix-error' to '&store-error'.
* guix/store.scm (&nix-error): Rename to...
(&store-error): ... this, and adjust users.
(&nix-connection-error): Rename to...
(&store-connection-error): ... this, and adjust users.
(&nix-protocol-error): Rename to...
(&store-protocol-error): ... this, adjust users.
(&nix-error, &nix-connection-error, &nix-protocol-error): Define these
condition types and their getters as deprecrated aliases.
* build-aux/run-system-tests.scm, guix/derivations.scm,
guix/grafts.scm, guix/scripts/challenge.scm,
guix/scripts/graph.scm, guix/scripts/lint.scm,
guix/scripts/offload.scm, guix/serialization.scm,
guix/ssh.scm, guix/tests.scm, guix/ui.scm,
tests/derivations.scm, tests/gexp.scm, tests/guix-daemon.sh,
tests/packages.scm, tests/store.scm, doc/guix.texi: Adjust to use the
new names.
2019-01-21 11:41:11 -05:00
|
|
|
|
(guard (c ((store-protocol-error? c)
|
2018-07-02 17:50:38 -04:00
|
|
|
|
;; ITEM is not in the store; return #f.
|
|
|
|
|
(values #f store)))
|
|
|
|
|
(values (query-path-info store item) store))))
|
|
|
|
|
|
2016-02-12 12:59:11 -05:00
|
|
|
|
(define-inlinable (current-system)
|
|
|
|
|
;; Consult the %CURRENT-SYSTEM fluid at bind time. This is equivalent to
|
|
|
|
|
;; (lift0 %current-system %store-monad), but inlinable, thus avoiding
|
|
|
|
|
;; closure allocation in some cases.
|
|
|
|
|
(lambda (state)
|
|
|
|
|
(values (%current-system) state)))
|
|
|
|
|
|
|
|
|
|
(define-inlinable (set-current-system system)
|
|
|
|
|
;; Set the %CURRENT-SYSTEM fluid at bind time.
|
|
|
|
|
(lambda (state)
|
|
|
|
|
(values (%current-system system) state)))
|
|
|
|
|
|
2019-12-24 09:04:57 -05:00
|
|
|
|
(define-inlinable (current-target-system)
|
|
|
|
|
;; Consult the %CURRENT-TARGET-SYSTEM fluid at bind time.
|
|
|
|
|
(lambda (state)
|
|
|
|
|
(values (%current-target-system) state)))
|
|
|
|
|
|
2020-03-06 04:06:02 -05:00
|
|
|
|
(define-inlinable (set-current-target target)
|
|
|
|
|
;; Set the %CURRENT-TARGET-SYSTEM fluid at bind time.
|
|
|
|
|
(lambda (state)
|
|
|
|
|
(values (%current-target-system target) state)))
|
|
|
|
|
|
monads: Move '%store-monad' and related procedures where they belong.
This turns (guix monads) into a generic module for monads, and moves the
store monad and related monadic procedures in their corresponding
module.
* guix/monads.scm (store-return, store-bind, %store-monad, store-lift,
text-file, interned-file, package-file, package->derivation,
package->cross-derivation, origin->derivation, imported-modules,
compiled, modules, built-derivations, run-with-store): Move to...
* guix/store.scm (store-return, store-bind, %store-monad, store-lift,
text-file, interned-file): ... here.
(%guile-for-build): New variable.
(run-with-store): Moved from monads.scm. Remove default value for
#:guile-for-build.
* guix/packages.scm (default-guile): Export.
(set-guile-for-build): New procedure.
(package-file, package->derivation, package->cross-derivation,
origin->derivation): Moved from monads.scm.
* guix/derivations.scm (%guile-for-build): Remove.
(imported-modules): Rename to...
(%imported-modules): ... this.
(compiled-modules): Rename to...
(%compiled-modules): ... this.
(built-derivations, imported-modules, compiled-modules): New
procedures.
* gnu/services/avahi.scm, gnu/services/base.scm, gnu/services/dbus.scm,
gnu/services/dmd.scm, gnu/services/networking.scm,
gnu/services/ssh.scm, gnu/services/xorg.scm, gnu/system/install.scm,
gnu/system/linux-initrd.scm, gnu/system/shadow.scm, guix/download.scm,
guix/gexp.scm, guix/git-download.scm, guix/profiles.scm,
guix/svn-download.scm, tests/monads.scm: Adjust imports accordingly.
* guix/monad-repl.scm (default-guile-derivation): New procedure.
(store-monad-language, run-in-store): Use it.
* build-aux/hydra/gnu-system.scm (qemu-jobs): Add explicit
'set-guile-for-build' call.
* guix/scripts/archive.scm (derivation-from-expression): Likewise.
* guix/scripts/build.scm (options/resolve-packages): Likewise.
* guix/scripts/environment.scm (guix-environment): Likewise.
* guix/scripts/system.scm (guix-system): Likewise.
* doc/guix.texi (The Store Monad): Adjust module names accordingly.
2015-01-14 07:34:52 -05:00
|
|
|
|
(define %guile-for-build
|
|
|
|
|
;; The derivation of the Guile to be used within the build environment,
|
|
|
|
|
;; when using 'gexp->derivation' and co.
|
|
|
|
|
(make-parameter #f))
|
|
|
|
|
|
|
|
|
|
(define* (run-with-store store mval
|
|
|
|
|
#:key
|
|
|
|
|
(guile-for-build (%guile-for-build))
|
2017-09-12 16:19:44 -04:00
|
|
|
|
(system (%current-system))
|
|
|
|
|
(target #f))
|
monads: Move '%store-monad' and related procedures where they belong.
This turns (guix monads) into a generic module for monads, and moves the
store monad and related monadic procedures in their corresponding
module.
* guix/monads.scm (store-return, store-bind, %store-monad, store-lift,
text-file, interned-file, package-file, package->derivation,
package->cross-derivation, origin->derivation, imported-modules,
compiled, modules, built-derivations, run-with-store): Move to...
* guix/store.scm (store-return, store-bind, %store-monad, store-lift,
text-file, interned-file): ... here.
(%guile-for-build): New variable.
(run-with-store): Moved from monads.scm. Remove default value for
#:guile-for-build.
* guix/packages.scm (default-guile): Export.
(set-guile-for-build): New procedure.
(package-file, package->derivation, package->cross-derivation,
origin->derivation): Moved from monads.scm.
* guix/derivations.scm (%guile-for-build): Remove.
(imported-modules): Rename to...
(%imported-modules): ... this.
(compiled-modules): Rename to...
(%compiled-modules): ... this.
(built-derivations, imported-modules, compiled-modules): New
procedures.
* gnu/services/avahi.scm, gnu/services/base.scm, gnu/services/dbus.scm,
gnu/services/dmd.scm, gnu/services/networking.scm,
gnu/services/ssh.scm, gnu/services/xorg.scm, gnu/system/install.scm,
gnu/system/linux-initrd.scm, gnu/system/shadow.scm, guix/download.scm,
guix/gexp.scm, guix/git-download.scm, guix/profiles.scm,
guix/svn-download.scm, tests/monads.scm: Adjust imports accordingly.
* guix/monad-repl.scm (default-guile-derivation): New procedure.
(store-monad-language, run-in-store): Use it.
* build-aux/hydra/gnu-system.scm (qemu-jobs): Add explicit
'set-guile-for-build' call.
* guix/scripts/archive.scm (derivation-from-expression): Likewise.
* guix/scripts/build.scm (options/resolve-packages): Likewise.
* guix/scripts/environment.scm (guix-environment): Likewise.
* guix/scripts/system.scm (guix-system): Likewise.
* doc/guix.texi (The Store Monad): Adjust module names accordingly.
2015-01-14 07:34:52 -05:00
|
|
|
|
"Run MVAL, a monadic value in the store monad, in STORE, an open store
|
2015-01-21 13:31:10 -05:00
|
|
|
|
connection, and return the result."
|
2015-07-07 16:57:54 -04:00
|
|
|
|
;; Initialize the dynamic bindings here to avoid bad surprises. The
|
|
|
|
|
;; difficulty lies in the fact that dynamic bindings are resolved at
|
|
|
|
|
;; bind-time and not at call time, which can be disconcerting.
|
monads: Move '%store-monad' and related procedures where they belong.
This turns (guix monads) into a generic module for monads, and moves the
store monad and related monadic procedures in their corresponding
module.
* guix/monads.scm (store-return, store-bind, %store-monad, store-lift,
text-file, interned-file, package-file, package->derivation,
package->cross-derivation, origin->derivation, imported-modules,
compiled, modules, built-derivations, run-with-store): Move to...
* guix/store.scm (store-return, store-bind, %store-monad, store-lift,
text-file, interned-file): ... here.
(%guile-for-build): New variable.
(run-with-store): Moved from monads.scm. Remove default value for
#:guile-for-build.
* guix/packages.scm (default-guile): Export.
(set-guile-for-build): New procedure.
(package-file, package->derivation, package->cross-derivation,
origin->derivation): Moved from monads.scm.
* guix/derivations.scm (%guile-for-build): Remove.
(imported-modules): Rename to...
(%imported-modules): ... this.
(compiled-modules): Rename to...
(%compiled-modules): ... this.
(built-derivations, imported-modules, compiled-modules): New
procedures.
* gnu/services/avahi.scm, gnu/services/base.scm, gnu/services/dbus.scm,
gnu/services/dmd.scm, gnu/services/networking.scm,
gnu/services/ssh.scm, gnu/services/xorg.scm, gnu/system/install.scm,
gnu/system/linux-initrd.scm, gnu/system/shadow.scm, guix/download.scm,
guix/gexp.scm, guix/git-download.scm, guix/profiles.scm,
guix/svn-download.scm, tests/monads.scm: Adjust imports accordingly.
* guix/monad-repl.scm (default-guile-derivation): New procedure.
(store-monad-language, run-in-store): Use it.
* build-aux/hydra/gnu-system.scm (qemu-jobs): Add explicit
'set-guile-for-build' call.
* guix/scripts/archive.scm (derivation-from-expression): Likewise.
* guix/scripts/build.scm (options/resolve-packages): Likewise.
* guix/scripts/environment.scm (guix-environment): Likewise.
* guix/scripts/system.scm (guix-system): Likewise.
* doc/guix.texi (The Store Monad): Adjust module names accordingly.
2015-01-14 07:34:52 -05:00
|
|
|
|
(parameterize ((%guile-for-build guile-for-build)
|
2015-07-07 16:57:54 -04:00
|
|
|
|
(%current-system system)
|
2017-09-12 16:19:44 -04:00
|
|
|
|
(%current-target-system target))
|
2015-01-21 13:31:10 -05:00
|
|
|
|
(call-with-values (lambda ()
|
|
|
|
|
(run-with-state mval store))
|
2019-07-03 17:29:17 -04:00
|
|
|
|
(lambda (result new-store)
|
2019-07-04 18:48:20 -04:00
|
|
|
|
(when (and store new-store)
|
|
|
|
|
;; Copy the object cache from NEW-STORE so we don't fully discard
|
|
|
|
|
;; the state.
|
2021-05-28 11:22:03 -04:00
|
|
|
|
(let ((caches (store-connection-caches new-store)))
|
|
|
|
|
(set-store-connection-caches! store caches)))
|
2019-07-04 18:48:20 -04:00
|
|
|
|
result))))
|
monads: Move '%store-monad' and related procedures where they belong.
This turns (guix monads) into a generic module for monads, and moves the
store monad and related monadic procedures in their corresponding
module.
* guix/monads.scm (store-return, store-bind, %store-monad, store-lift,
text-file, interned-file, package-file, package->derivation,
package->cross-derivation, origin->derivation, imported-modules,
compiled, modules, built-derivations, run-with-store): Move to...
* guix/store.scm (store-return, store-bind, %store-monad, store-lift,
text-file, interned-file): ... here.
(%guile-for-build): New variable.
(run-with-store): Moved from monads.scm. Remove default value for
#:guile-for-build.
* guix/packages.scm (default-guile): Export.
(set-guile-for-build): New procedure.
(package-file, package->derivation, package->cross-derivation,
origin->derivation): Moved from monads.scm.
* guix/derivations.scm (%guile-for-build): Remove.
(imported-modules): Rename to...
(%imported-modules): ... this.
(compiled-modules): Rename to...
(%compiled-modules): ... this.
(built-derivations, imported-modules, compiled-modules): New
procedures.
* gnu/services/avahi.scm, gnu/services/base.scm, gnu/services/dbus.scm,
gnu/services/dmd.scm, gnu/services/networking.scm,
gnu/services/ssh.scm, gnu/services/xorg.scm, gnu/system/install.scm,
gnu/system/linux-initrd.scm, gnu/system/shadow.scm, guix/download.scm,
guix/gexp.scm, guix/git-download.scm, guix/profiles.scm,
guix/svn-download.scm, tests/monads.scm: Adjust imports accordingly.
* guix/monad-repl.scm (default-guile-derivation): New procedure.
(store-monad-language, run-in-store): Use it.
* build-aux/hydra/gnu-system.scm (qemu-jobs): Add explicit
'set-guile-for-build' call.
* guix/scripts/archive.scm (derivation-from-expression): Likewise.
* guix/scripts/build.scm (options/resolve-packages): Likewise.
* guix/scripts/environment.scm (guix-environment): Likewise.
* guix/scripts/system.scm (guix-system): Likewise.
* doc/guix.texi (The Store Monad): Adjust module names accordingly.
2015-01-14 07:34:52 -05:00
|
|
|
|
|
2022-10-14 15:51:18 -04:00
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
;;; Whether to enable grafts.
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
(define %graft?
|
|
|
|
|
;; Whether to honor package grafts by default.
|
|
|
|
|
(make-parameter #t))
|
|
|
|
|
|
|
|
|
|
(define (call-without-grafting thunk)
|
|
|
|
|
(lambda (store)
|
|
|
|
|
(values (parameterize ((%graft? #f))
|
|
|
|
|
(run-with-store store (thunk)))
|
|
|
|
|
store)))
|
|
|
|
|
|
|
|
|
|
(define-syntax-rule (without-grafting mexp ...)
|
|
|
|
|
"Bind monadic expressions MEXP in a dynamic extent where '%graft?' is
|
|
|
|
|
false."
|
|
|
|
|
(call-without-grafting (lambda () (mbegin %store-monad mexp ...))))
|
|
|
|
|
|
|
|
|
|
(define-inlinable (set-grafting enable?)
|
|
|
|
|
;; This monadic procedure enables grafting when ENABLE? is true, and
|
|
|
|
|
;; disables it otherwise. It returns the previous setting.
|
|
|
|
|
(lambda (store)
|
|
|
|
|
(values (%graft? enable?) store)))
|
|
|
|
|
|
|
|
|
|
(define-inlinable (grafting?)
|
|
|
|
|
;; Return a Boolean indicating whether grafting is enabled.
|
|
|
|
|
(lambda (store)
|
|
|
|
|
(values (%graft?) store)))
|
|
|
|
|
|
2012-06-01 17:29:55 -04:00
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
;;; Store paths.
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
(define %store-prefix
|
|
|
|
|
;; Absolute path to the Nix store.
|
2014-01-08 15:37:06 -05:00
|
|
|
|
(make-parameter %store-directory))
|
2012-06-01 17:29:55 -04:00
|
|
|
|
|
2017-05-04 10:40:00 -04:00
|
|
|
|
(define (compressed-hash bv size) ; `compressHash'
|
|
|
|
|
"Given the hash stored in BV, return a compressed version thereof that fits
|
|
|
|
|
in SIZE bytes."
|
|
|
|
|
(define new (make-bytevector size 0))
|
|
|
|
|
(define old-size (bytevector-length bv))
|
|
|
|
|
(let loop ((i 0))
|
|
|
|
|
(if (= i old-size)
|
|
|
|
|
new
|
|
|
|
|
(let* ((j (modulo i size))
|
|
|
|
|
(o (bytevector-u8-ref new j)))
|
|
|
|
|
(bytevector-u8-set! new j
|
|
|
|
|
(logxor o (bytevector-u8-ref bv i)))
|
|
|
|
|
(loop (+ 1 i))))))
|
|
|
|
|
|
|
|
|
|
(define (store-path type hash name) ; makeStorePath
|
|
|
|
|
"Return the store path for NAME/HASH/TYPE."
|
|
|
|
|
(let* ((s (string-append type ":sha256:"
|
|
|
|
|
(bytevector->base16-string hash) ":"
|
|
|
|
|
(%store-prefix) ":" name))
|
|
|
|
|
(h (sha256 (string->utf8 s)))
|
|
|
|
|
(c (compressed-hash h 20)))
|
|
|
|
|
(string-append (%store-prefix) "/"
|
|
|
|
|
(bytevector->nix-base32-string c) "-"
|
|
|
|
|
name)))
|
|
|
|
|
|
|
|
|
|
(define (output-path output hash name) ; makeOutputPath
|
|
|
|
|
"Return an output path for OUTPUT (the name of the output as a string) of
|
|
|
|
|
the derivation called NAME with hash HASH."
|
|
|
|
|
(store-path (string-append "output:" output) hash
|
|
|
|
|
(if (string=? output "out")
|
|
|
|
|
name
|
|
|
|
|
(string-append name "-" output))))
|
|
|
|
|
|
|
|
|
|
(define* (fixed-output-path name hash
|
|
|
|
|
#:key
|
|
|
|
|
(output "out")
|
|
|
|
|
(hash-algo 'sha256)
|
|
|
|
|
(recursive? #t))
|
|
|
|
|
"Return an output path for the fixed output OUTPUT defined by HASH of type
|
|
|
|
|
HASH-ALGO, of the derivation NAME. RECURSIVE? has the same meaning as for
|
|
|
|
|
'add-to-store'."
|
|
|
|
|
(if (and recursive? (eq? hash-algo 'sha256))
|
|
|
|
|
(store-path "source" hash name)
|
|
|
|
|
(let ((tag (string-append "fixed:" output ":"
|
|
|
|
|
(if recursive? "r:" "")
|
|
|
|
|
(symbol->string hash-algo) ":"
|
|
|
|
|
(bytevector->base16-string hash) ":")))
|
|
|
|
|
(store-path (string-append "output:" output)
|
|
|
|
|
(sha256 (string->utf8 tag))
|
|
|
|
|
name))))
|
|
|
|
|
|
2012-09-01 13:21:06 -04:00
|
|
|
|
(define (store-path? path)
|
|
|
|
|
"Return #t if PATH is a store path."
|
|
|
|
|
;; This is a lightweight check, compared to using a regexp, but this has to
|
|
|
|
|
;; be fast as it's called often in `derivation', for instance.
|
|
|
|
|
;; `isStorePath' in Nix does something similar.
|
|
|
|
|
(string-prefix? (%store-prefix) path))
|
2012-06-01 17:29:55 -04:00
|
|
|
|
|
2013-11-12 17:36:29 -05:00
|
|
|
|
(define (direct-store-path? path)
|
|
|
|
|
"Return #t if PATH is a store path, and not a sub-directory of a store path.
|
|
|
|
|
This predicate is sometimes needed because files *under* a store path are not
|
|
|
|
|
valid inputs."
|
|
|
|
|
(and (store-path? path)
|
2014-04-26 10:38:38 -04:00
|
|
|
|
(not (string=? path (%store-prefix)))
|
2013-11-12 17:36:29 -05:00
|
|
|
|
(let ((len (+ 1 (string-length (%store-prefix)))))
|
|
|
|
|
(not (string-index (substring path len) #\/)))))
|
|
|
|
|
|
2015-05-24 08:04:15 -04:00
|
|
|
|
(define (direct-store-path path)
|
|
|
|
|
"Return the direct store path part of PATH, stripping components after
|
|
|
|
|
'/gnu/store/xxxx-foo'."
|
|
|
|
|
(let ((prefix-length (+ (string-length (%store-prefix)) 35)))
|
|
|
|
|
(if (> (string-length path) prefix-length)
|
|
|
|
|
(let ((slash (string-index path #\/ prefix-length)))
|
|
|
|
|
(if slash (string-take path slash) path))
|
|
|
|
|
path)))
|
|
|
|
|
|
2012-06-01 17:29:55 -04:00
|
|
|
|
(define (derivation-path? path)
|
|
|
|
|
"Return #t if PATH is a derivation path."
|
|
|
|
|
(and (store-path? path) (string-suffix? ".drv" path)))
|
2012-10-31 20:39:23 -04:00
|
|
|
|
|
2020-03-12 06:08:16 -04:00
|
|
|
|
(define (store-path-base path)
|
|
|
|
|
"Return the base path of a path in the store."
|
|
|
|
|
(and (string-prefix? (%store-prefix) path)
|
|
|
|
|
(let ((base (string-drop path (+ 1 (string-length (%store-prefix))))))
|
|
|
|
|
(and (> (string-length base) 33)
|
|
|
|
|
(not (string-index base #\/))
|
|
|
|
|
base))))
|
2013-12-10 18:19:27 -05:00
|
|
|
|
|
2012-10-31 20:39:23 -04:00
|
|
|
|
(define (store-path-package-name path)
|
|
|
|
|
"Return the package name part of PATH, a file name in the store."
|
2020-03-12 06:08:16 -04:00
|
|
|
|
(let ((base (store-path-base path)))
|
|
|
|
|
(string-drop base (+ 32 1)))) ;32 hash part + 1 hyphen
|
2013-04-01 10:08:31 -04:00
|
|
|
|
|
|
|
|
|
(define (store-path-hash-part path)
|
|
|
|
|
"Return the hash part of PATH as a base32 string, or #f if PATH is not a
|
|
|
|
|
syntactically valid store path."
|
2021-02-03 08:43:29 -05:00
|
|
|
|
(match (store-path-base path)
|
|
|
|
|
(#f #f)
|
|
|
|
|
(base
|
|
|
|
|
(let ((hash (string-take base 32)))
|
|
|
|
|
(and (string-every %nix-base32-charset hash)
|
|
|
|
|
hash)))))
|
2013-11-11 18:10:10 -05:00
|
|
|
|
|
2018-09-28 17:19:13 -04:00
|
|
|
|
(define (derivation-log-file drv)
|
|
|
|
|
"Return the build log file for DRV, a derivation file name, or #f if it
|
|
|
|
|
could not be found."
|
|
|
|
|
(let* ((base (basename drv))
|
2019-02-03 16:32:13 -05:00
|
|
|
|
(log (string-append (or (getenv "GUIX_LOG_DIRECTORY")
|
|
|
|
|
(string-append %localstatedir "/log/guix"))
|
|
|
|
|
"/drvs/"
|
2018-09-28 17:19:13 -04:00
|
|
|
|
(string-take base 2) "/"
|
|
|
|
|
(string-drop base 2)))
|
|
|
|
|
(log.gz (string-append log ".gz"))
|
|
|
|
|
(log.bz2 (string-append log ".bz2")))
|
|
|
|
|
(cond ((file-exists? log.gz) log.gz)
|
|
|
|
|
((file-exists? log.bz2) log.bz2)
|
|
|
|
|
((file-exists? log) log)
|
|
|
|
|
(else #f))))
|
|
|
|
|
|
2013-11-11 18:10:10 -05:00
|
|
|
|
(define (log-file store file)
|
|
|
|
|
"Return the build log file for FILE, or #f if none could be found. FILE
|
|
|
|
|
must be an absolute store file name, or a derivation file name."
|
|
|
|
|
(cond ((derivation-path? file)
|
2018-09-28 17:19:13 -04:00
|
|
|
|
(derivation-log-file file))
|
2013-11-11 18:10:10 -05:00
|
|
|
|
(else
|
|
|
|
|
(match (valid-derivers store file)
|
|
|
|
|
((derivers ...)
|
|
|
|
|
;; Return the first that works.
|
|
|
|
|
(any (cut log-file store <>) derivers))
|
|
|
|
|
(_ #f)))))
|
2017-04-21 05:48:57 -04:00
|
|
|
|
|
|
|
|
|
;;; Local Variables:
|
|
|
|
|
;;; eval: (put 'system-error-to-connection-error 'scheme-indent-function 1)
|
|
|
|
|
;;; End:
|