Commit Graph

59 Commits

Author SHA1 Message Date
Ludovic Courtès ab13e2be69
time-machine: Make target commit check cheaper.
Commit 79ec651a28 introduced a check to
error out when attempting to use ‘time-machine’ to travel to a commit
before ‘v1.0.0’.

This commit fixes a performance issue with the strategy used in
79ec651a28 (the repository was opened,
updated, and traversed a second time by ‘validate-guix-channel’) as well
as a user interface issue (“Updating channel” messages would be printed
too late).

This patch reimplements the check in terms of the existing #:validate-pull
mechanism, which is designed to avoid extra repository operations.

Fixes <https://issues.guix.gnu.org/65788>.

* guix/inferior.scm (cached-channel-instance): Change default value
of #:validate-channels.  Remove call to VALIDATE-CHANNELS; pass it
as #:validate-pull to ‘latest-channel-instances’.
* guix/scripts/time-machine.scm (%reference-channels): New variable.
(validate-guix-channel): New procedure, written as a simplification of…
(guix-time-machine)[validate-guix-channel]: … this.  Remove.
Pass #:reference-channels to ‘cached-channel-instance’.

Reported-by: Simon Tournier <zimon.toutoune@gmail.com>
Change-Id: I9b0ec61fba7354fe08b04a91f4bd32b72a35460c
2023-11-05 23:23:23 +01:00
Maxim Cournoyer 79ec651a28
scripts: time-machine: Error when attempting to visit too old commits.
* doc/guix.texi (Invoking guix time-machine): Document limitation.
* guix/inferior.scm (cached-channel-instance): New VALIDATE-CHANNELS
argument.  Use it to validate channels when there are no cache hit.
* guix/scripts/time-machine.scm
(%options): Tag the given reference with 'tag-or-commit instead of 'commit.
(%oldest-possible-commit): New variable.
(guix-time-machine) <validate-guix-channel>: New nested procedure.  Pass it to
the 'cached-channel-instance' call.
* tests/guix-time-machine.sh: New test.
* Makefile.am (SH_TESTS): Register it.

Suggested-by: Simon Tournier <zimon.toutoune@gmail.com>
Reviewed-by: Ludovic Courtès <ludo@gnu.org>
Reviewed-by: Simon Tournier <zimon.toutoune@gmail.com>
2023-08-16 21:34:13 -04:00
Ludovic Courtès fed3953d70
inferior: Use 'spawn' on Guile 3.0.9+.
* guix/inferior.scm (open-bidirectional-pipe): When 'spawn' is defined,
use it instead of 'primitive-fork'.
2023-01-26 11:11:18 +01:00
Ludovic Courtès 60bea07593
inferior: Raise '&inferior-protocol-error' on invalid response.
* guix/inferior.scm (&inferior-protocol-error): New condition type.
(read-repl-response): Add default 'match' clause and raise it.
2022-11-22 09:43:54 +01:00
Ludovic Courtès f36522416e
channels: Interpret the 'commit' field of channel as a tag or commit.
Previously the 'commit' field would always be interpreted as a commit
ID.  This change adds flexibility, allowing for things like:

  guix time-machine --commit=v1.2.0 -- describe

* guix/channels.scm (channel-reference): Use 'tag-or-commit' rather than 'commit'.
* guix/inferior.scm (channel-full-commit): Likewise.
* doc/guix.texi (Invoking guix pull): Document it.
(Invoking guix time-machine): Likewise.
2022-10-17 09:37:27 +02:00
Ludovic Courtès 602527ab97
git: Factorize 'commit-id?' predicate.
* guix/git.scm (commit-id?): New procedure, copied from (guix swh).
(resolve-reference): Use it instead of inline code.
* guix/inferior.scm (channel-full-commit): Likewise.
2022-10-11 16:05:31 +02:00
Christopher Baines b4c4a6acb1
guix: inferior: Fix the behaviour of open-inferior #:error-port.
I'm looking at this as the Guix Data Service uses this behaviour to record and
display logs from inferior processes.

* guix/inferior.scm (open-bidirectional-pipe): Call dup2 for file descriptor
2, passing either the file number for the current error port, or a file
descriptor for /dev/null.
* tests/inferior.scm ("#:error-port stderr", "#:error-port pipe"): Add two new
tests that cover some of the #:error-port behaviour.
2022-07-08 13:51:34 +01:00
Ludovic Courtès a4994d7393
inferior: Close duplicate socketpair file descriptor.
* guix/inferior.scm (open-bidirectional-pipe): Pass SOCK_CLOEXEC to
'socketpair'.
* tests/inferior.scm ("close-inferior"): Add test.
2022-05-20 18:46:07 +02:00
Ludovic Courtès e778910bdf
inferior: Move initialization bits away from 'inferior-eval-with-store'.
* guix/inferior.scm (port->inferior): In the inferior, define
'cached-store-connection', 'store-protocol-error?', and
'store-protocol-error-message'.
(inferior-eval-with-store): Use them.
2022-01-27 14:13:24 +01:00
Ludovic Courtès c71910a095
inferior: Inferior caches store connections.
Fixes <https://issues.guix.gnu.org/48007>.
Reported by Ricardo Wurmus <rekado@elephly.net>.

Previously, at each 'inferior-eval-with-store' call, the inferior would
create a new <store-connection> object with empty caches.  Consequently,
when repeatedly calling 'inferior-package-derivation', we would not
benefit from any caching and instead recompute all the derivations for
every package.  This patch fixes it by caching <store-connection>
objects in the inferior.

* guix/inferior.scm (port->inferior): Define '%store-table' in the inferior.
(inferior-eval-with-store): Cache store connections in %STORE-TABLE.
Remove now unneeded 'dynamic-wind' with 'close-port' call.
2022-01-27 14:13:24 +01:00
Ludovic Courtès bd86bbd300
inferior: Keep the store bridge connected.
Previously, each 'inferior-eval-with-store' would lead the inferior to
connect to the named socket the parent is listening to.  With this
change, the connection is established once for all and reused
afterwards.

* guix/inferior.scm (<inferior>)[bridge-file-name]: Remove.
(open-bidirectional-pipe): New procedure.
(inferior-pipe): Use it instead of 'open-pipe*' and return two values.
(port->inferior): Adjust call to 'inferior'.
(open-inferior): Adjust to 'inferior-pipe' changes.
(close-inferior): Remove 'inferior-bridge-file-name' handling.
(open-store-bridge!): Switch back to 'call-with-temporary-directory'.
Define '%bridge-socket' in the inferior, connected to the caller.
(proxy): Change first argument to be an inferior.  Add 'reponse-port'
and call to 'drain-input'.  Pass 'reponse-port' to 'select' and use it
as a loop termination clause.
(inferior-eval-with-store): Remove 'socket' and 'connect' calls from the
inferior code, and use '%bridge-socket' instead.
2022-01-27 14:13:24 +01:00
Ludovic Courtès 10aad72110
inferior: Create the store proxy listening socket only once.
Previously, each 'inferior-eval-with-store' call would have the calling
process create a temporary directory with a listening socket in there.
Now that listening socket is created once and reused in subsequent
calls.

* guix/inferior.scm (<inferior>)[bridge-file-name, bridge-socket]: New
fields.
(port->inferior): Adjust accordingly.
(close-inferior): Close 'inferior-bridge-socket' and delete
'inferior-bridge-file-name' if set.
(open-store-bridge!, ensure-store-bridge!): New procedures.
(inferior-eval-with-store): Use them.
2022-01-27 14:13:24 +01:00
Ludovic Courtès a9cc79d9f3
inferior: 'cached-channel-instance' always returns a directory.
This is a followup to b1fc98d6b0.

* guix/inferior.scm (cached-channel-instance): When AUTHENTICATE? is
false, return (derivation->output-path profile).
2022-01-17 19:05:48 +01:00
Ludovic Courtès b1fc98d6b0
inferior: Fix wrong-type-arg error when authentication is disabled.
Fixes <https://issues.guix.gnu.org/53230>.
Reported by Andrew Tropin <andrew@trop.in>.

Fixes a regression introduced in
9f371f23eb.

* guix/inferior.scm (cached-channel-instance): Add call to
'derivation->output-path' when AUTHENTICATE? is false.
2022-01-13 23:11:18 +01:00
Ludovic Courtès 9f371f23eb
inferior: 'cached-channel-instance' does not cache unauthenticated instances.
The comment saying that caching is fine even when AUTHENTICATE? is false
was true in commit 838ac881ec, but it
became incorrect in 7cfd789150, which
no longer calls 'latest-channel-instances' on cache hits.

* guix/inferior.scm (cached-channel-instance): Do not create CACHED when
AUTHENTICATE? is false.
2021-12-01 17:51:33 +01:00
Ludovic Courtès 7bd5f72918
inferior: 'cached-channel-instance' no longer calls 'show-what-to-build'.
This allows the user of 'cached-channel-instance' to install the build
handler of its choice.  In particular, it allows "guix time-machine" to
install a build notifier with the right options instead of using the
defaults that 'cached-channel-instance' would pass to
'show-what-to-build*'.

* guix/inferior.scm (cached-channel-instance): Remove call to
'show-what-to-build*'.
(inferior-for-channels): Wrap body in 'with-build-handler'.
* guix/scripts/time-machine.scm (guix-time-machine): Use
'with-build-handler'.
2021-08-09 18:14:37 +02:00
Christopher Baines 97d615b176
inferior: Support querying package replacements.
I'm looking at this to help with adding support for looking up package
replacements to store in the Guix Data Service.

* guix/inferior.scm (inferior-package-replacement): New procedure.
* tests/inferior.scm ("inferior-package-replacement"): New test.
2021-05-15 12:14:47 +01:00
Ludovic Courtès 2569bd994b
inferior: Add <inferior> printer.
This avoids printing the whole package table in backtraces and such.

* guix/inferior.scm (write-inferior): New procedure.
<top level>: Call 'set-record-type-printer!'.
2021-03-13 22:51:18 +01:00
Mathieu Othacehe a831ff6bc3
inferior: Use a safe symlink monadic procedure.
This is a follow-up of 6ee7e3d26b.

* guix/inferior.scm (cached-channel-instance): Introduce "symlink/safe" and
use it instead of symlink. Remove the duplicated "file-exists?" call.
2021-03-10 13:09:23 +01:00
Mathieu Othacehe 8898eaec57
Revert "inferior: Break cached-channel-instance into two procedures."
This reverts commit 7d63b77551 because it raises
some concerns, see:
https://lists.gnu.org/archive/html/guix-devel/2021-03/msg00124.html.
2021-03-10 13:08:32 +01:00
Mathieu Othacehe 6ee7e3d26b
inferior: Fix concurrent cached-profile calls.
* guix/inferior.scm (cached-profile): Do not create the profile symlink if it
already exists.
2021-03-10 08:49:48 +01:00
Mathieu Othacehe 7d63b77551
inferior: Break cached-channel-instance into two procedures.
Break cached-channel-instance into two different procedures:
channels->cached-profile and instances->cached-profile operating respectively
on channels and channels instances.

* guix/inferior.scm (cached-channel-instance): Rename it into ...
(cached-profile): ... this new procedure.
(channels->cached-profile, instances->cached-profile): New procedures.
* guix/scripts/time-machine.scm (guix-time-machine): Adapt accordingly.
2021-03-10 08:49:48 +01:00
Ludovic Courtès 7cfd789150
inferior: Speed up 'cached-channel-instance' for cache hits.
That way a command like:

  guix time-machine --commit=5aeee07cc9 -- describe

goes from 3.4s to 0.5s on a cache hit, even slightly less when passing
the full commit ID.

* guix/inferior.scm (channel-full-commit): New procedure.
(cached-channel-instance): Remove 'instances' top-level variable.  Add
'commits' and use it for 'key'.  Move 'latest-channel-instances' call to
the cache miss case.
2021-01-29 12:09:11 +01:00
Ricardo Wurmus 09ab0d42b0
guix: Fix typo.
* guix/inferior.scm (inferior-available-packages): Remove extra word in
docstring.
2021-01-28 15:07:52 +01:00
Ludovic Courtès 0f20b3fa20
inferior: Memoize entries in 'inferior-package->manifest-entry'.
Fixes a performance issue as reported by Ricardo Wurmus
in <https://bugs.gnu.org/46100>.

* guix/inferior.scm (inferior-package->manifest-entry): Remove #:parent parameter.
[cache]: New variable.
[memoized]: New macro.
[loop]: New procedure.
2021-01-27 23:03:06 +01:00
Ludovic Courtès 4f621a2b00
maint: Require Guile >= 2.2.6.
* configure.ac: For Guile 2.2, require 2.2.6 or later.
* guix/gexp.scm (define-syntax-parameter-once): Remove.
Use 'define-syntax-parameter' instead.
* guix/mnoads.scm: Likewise.
* guix/inferior.scm (proxy)[select*]: Remove.
* guix/scripts/publish.scm <top level>: Remove replacement for (@@ (web
http) read-header-line).
* guix/store/deduplication.scm (counting-wrapper-port): Remove.
(nar-sha256): Call 'port-position' on PORT to compute SIZE.
2020-12-19 23:25:01 +01:00
Ludovic Courtès a5e2fc7376
utils: Move <location> and '&error-location' to (guix diagnostics).
* guix/utils.scm (<location>, source-properties->location)
(location->source-properties, &error-location): Move to...
* guix/diagnostics.scm: ... here.
* gnu.scm: Adjust imports accordingly.
* gnu/machine.scm: Likewise.
* gnu/system.scm: Likewise.
* gnu/tests.scm: Likewise.
* guix/inferior.scm: Likewise.
* tests/channels.scm: Likewise.
* tests/packages.scm: Likewise.
2020-07-25 19:11:36 +02:00
Ludovic Courtès 838ac881ec
time-machine: Add '--disable-authentication'.
* guix/inferior.scm (cached-channel-instance): Add #:authenticate? and
pass it to 'latest-channel-instances'.
* guix/scripts/time-machine.scm (show-help, %options): Add
'--disable-authentication'.
(%default-options): Add 'authenticate-channels?'.
(guix-time-machine): Honor it.
2020-06-16 16:10:47 +02:00
Ludovic Courtès 1dca6aaafa
inferior: '&inferior-exception' includes a stack trace.
* guix/inferior.scm (port->inferior): Bump protocol to (0 1 1).
(&inferior-exception)[stack]: New field.
(read-repl-response): Recognize 'exception' form for protocol (0 1 1).
* tests/inferior.scm ("&inferior-exception"): Check the value returned
by 'inferior-exception-stack'.
2020-03-19 15:14:08 +01:00
Ludovic Courtès ec0a866172
inferior: Adjust to protocol (0 1).
* guix/inferior.scm (port->inferior): For protocol (0 x ...), where x >= 1,
send the (() repl-version ...) form.
2020-03-19 15:14:08 +01:00
Ludovic Courtès f7537e30b8
inferior: Distinguish inferior exceptions.
This avoids ambiguities when looking at a backtrace where the exception
was actually thrown by an inferior in a very different context.

* guix/inferior.scm (&inferior-exception): New condition type.
(read-repl-response): Add optional 'inferior' parameter.  Raise
'&inferior-exception' instead of rethrowing to KEY when receiving an
'exception' message.
(read-inferior-response): Pass INFERIOR to 'read-repl-response'.
* tests/inferior.scm ("&inferior-exception"): New test.
2020-03-12 11:52:38 +01:00
Ludovic Courtès ea6d962b93
More module autoload adjustments.
This is a followup to 7a0836cffd.

* guix/scripts/package.scm: Adjust binding list of the (guix store roots)
autoload.
* guix/inferior.scm: Adjust binding list of the (guix cache) autoload.
2020-01-15 18:40:43 +01:00
Ludovic Courtès 7a241c6350
inferior: Add 'inferior-package-provenance'.
* guix/inferior.scm (inferior-package-provenance): New procedure.
2019-12-29 18:24:54 +01:00
Konrad Hinsen 1d5485690b
inferior: 'cached-channel-instance' takes an open store connection.
* guix/inferior.scm (cached-channel-instance): Take an explicit 'store'
argument.
(inferior-for-channels): Wrap call to 'cached-channel-instance' in
'with-store'.
* guix/time-machine.scm (guix-time-machine): Wrap call to
'cached-channel-instance' in 'with-store'.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2019-11-15 23:28:17 +01:00
Konrad Hinsen f675f8dec7
Add 'guix time-machine'.
* guix/scripts/time-machine.scm: New file.
* Makefile.am: (MODULES): Add it.
* guix/scripts/pull.scm (channel-list): Export.
* guix/inferior.scm (cached-channel-instance): New procedure.
(inferior-for-channels): Use it.
* doc/guix.texi (Invoking guix time-machine): New section.
(Channels): Cross-reference it.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2019-11-15 23:28:17 +01:00
Christopher Baines ef0c265438
inferior: Set the error port when using older Guix versions.
This makes the behaviour more consistent.

* guix/inferior.scm (inferior-pipe): Wrap the second open-pipe* call with
with-error-to-port, to match the first call to open-pipe*.
2019-10-15 19:01:50 +01:00
Christopher Baines f0428c18f8
inferior: Allow controlling the inferior error port.
Previously, stderr for the inferior process would always be sent to /dev/null
because the current-output-port when the process is launched is a void
port. This change means that it's possible to pass in a different port to use.

* guix/inferior.scm (inferior-pipe): Take the error-port as an argument.
(open-inferior): Add new error-port keyword argument, with a default
of (%make-void-port "w").
2019-10-15 19:01:47 +01:00
Christopher Baines 2cd599f005
inferior: Change to use the (guix repl) module.
Rather than (guix scripts repl), from which the machine-repl procedure was
removed in [1].

1: 92a4087bf4

* guix/inferior.scm (inferior-pipe): Load (guix repl) rather than (guix
scripts repl).
2019-10-01 19:01:20 +01:00
Vagrant Cascadian a130544d60
inferior: Fix typo.
* guix/inferior: Fix spelling of "specifications".
2019-09-23 12:03:00 -07:00
Ludovic Courtès 7150743522
inferior: Propagate '&store-protocol-error' error conditions.
Until now '&store-protocol-error' conditions raised in the inferior
would not be correctly propagated because SRFI-35 records lack a read
syntax.

Reported at <https://bugs.gnu.org/37449>
by Carl Dong <contact@carldong.me>.

* guix/inferior.scm (port->inferior): Import (srfi srfi-34) in the inferior.
(inferior-eval-with-store): Define 'error?' and 'error-message'.  Wrap
call to PROC in 'guard'.  Check the response of INFERIOR for a
'store-protocol-error' or a 'result' tag.
* tests/inferior.scm ("inferior-eval-with-store, &store-protocol-error"):
New test.
2019-09-21 16:48:36 +02:00
Ludovic Courtès d0ffa321dd
inferior: Add 'read-repl-response'.
* guix/inferior.scm (read-repl-response): New procedure.
(read-inferior-response): Use it.
2019-07-04 18:05:02 +02:00
Ludovic Courtès 4035fcba93
channels: Do not fail when the inferior lacks 'guix repl'.
Fixes <https://bugs.gnu.org/34637>.
Reported by Martin Flack <martin.flack@gmail.com>.

Previously we'd fail to build the package cache for old versions of Guix
that lack 'guix repl'.  Now we simply ignore the issue and keep going
without a cache.

* guix/inferior.scm (gexp->derivation-in-inferior): Add
 #:silent-failure? and honor it.
[drop-extra-keyword]: New procedure.
Use it.
* guix/channels.scm (package-cache-file): Pass #:silent-failure? #t.
2019-03-08 12:31:38 +01:00
Ludovic Courtès 739380542d
inferior: Add 'inferior-available-packages'.
* guix/inferior.scm (inferior-available-packages): New procedure.
* tests/inferior.scm ("inferior-available-packages"): New test.
2019-02-12 23:30:16 +01:00
Ludovic Courtès de9fbe9cdc
store: Rename <nix-server> to <store-connection>.
* guix/store.scm (<nix-server>): Rename to...
(<store-connection>): ... this.  Adjust users accordingly.
(nix-server?, nix-server-major-version)
(nix-server-minor-version, nix-server-socket)
(nix-server-version): Define as deprecated aliases.
* guix/inferior.scm: Adjust accordingly.
* guix/ssh.scm: Likewise.
2019-01-21 23:09:55 +01:00
Ludovic Courtès 1fafc383b1
inferior: 'gexp->derivation-in-inferior' honors EXP's load path.
Previously the imported modules and extensions of EXP would be missing
from the load path of 'guix repl'.

* guix/inferior.scm (gexp->derivation-in-inferior)[script]: New
variable.
[trampoline]: Write (primitive-load #$script) to PIPE.  Add #$output.
* tests/channels.scm ("channel-instances->manifest")[depends?]: Check
for requisites rather than direct references.
Adjust callers accordingly.
2019-01-20 17:57:14 +01:00
Ludovic Courtès ae92782240
inferior: Add 'gexp->derivation-in-inferior'.
* guix/inferior.scm (gexp->derivation-in-inferior): New procedure.
2019-01-15 20:24:09 +01:00
Ludovic Courtès 76832d3420
Remove most uses of the _IO*F constants.
These constants, for use with 'setvbuf', were deprecated in Guile 2.2
and disappeared in Guile 3.0.  Here we keep these constants in
build-side code where removing them is not feasible.

* guix/build/download-nar.scm (download-nar): Adjust 'setvbuf' calls to
the Guile 2.2+ API.
* guix/build/download.scm (open-socket-for-uri): Likewise.
(open-connection-for-uri, url-fetch): Likewise.
* guix/build/make-bootstrap.scm (make-stripped-libc): Likewise.
* guix/build/union.scm (setvbuf) [guile-2.0]: New conditional wrapper.
(union-build): Adjust to new API.
* guix/ftp-client.scm (ftp-open, ftp-list, ftp-retr): Likewise.
* guix/http-client.scm (http-fetch): Likewise.
* guix/inferior.scm (proxy): Likewise.
* guix/scripts/substitute.scm (fetch, http-multiple-get): Likewise.
* guix/self.scm (compiled-modules): Likewise.
* guix/ssh.scm (remote-daemon-channel, store-import-channel)
(store-export-channel): Likewise.
* guix/ui.scm (initialize-guix): Likewise.
* tests/publish.scm (http-get-port): Likewise.
* guix/store.scm (%newlines): Adjust comment.
2019-01-09 14:47:53 +01:00
Ludovic Courtès a65177a657
maint: Remove 'cond-expand' forms for Guile 2.0.
Note: Leave 'cond-expand' forms used in the build-side modules that can
run on %BOOTSTRAP-GUILE, which is currently Guile 2.0.

* guix/build/compile.scm: Move 'use-modules' clause from 'cond-expand'
to 'define-module' form.
(%default-optimizations): Remove 'cond-expand'.
* guix/build/download.scm (tls-wrap): Remove 'cond-expand'.
* guix/build/syscalls.scm: Remove 'cond-expand' form around
'%set-automatic-finalization-enabled?!' and
'without-automatic-finalization'.
* guix/inferior.scm (port->inferior): Remove 'cond-expand'.
* guix/scripts/pack.scm (wrapped-package)[build]: Remove 'cond-expand'.
* guix/status.scm (build-event-output-port): Remove 'cond-expand'.
* guix/store.scm (open-inet-socket): Remove 'cond-expand'.
* guix/ui.scm (install-locale): Remove 'cond-expand'.
* tests/status.scm ("current-build-output-port, UTF-8 + garbage"):
Remove 'cond-expand'.
* tests/store.scm ("current-build-output-port, UTF-8 + garbage"):
Remove 'cond-expand'.
2019-01-09 14:47:53 +01:00
Ludovic Courtès af15fe13b6
ssh: Add 'remote-inferior'.
* guix/inferior.scm (<inferior>)[close]: New field.
(port->inferior): New procedure.
(open-inferior): Rewrite in terms of 'port->inferior'.
(close-inferior): Honor INFERIOR's 'close' field.
(inferior-eval-with-store): Add FIXME comment.
* guix/ssh.scm (remote-inferior): New procedure.
2018-12-24 16:06:32 +01:00
Ludovic Courtès 94c0e61fe7
inferior: Add 'inferior-eval-with-store'.
* guix/inferior.scm (inferior-eval-with-store): New procedure, with code
formerly in 'inferior-package-derivation'.
(inferior-package-derivation): Rewrite in terms of
'inferior-eval-with-store'.
* tests/inferior.scm ("inferior-eval-with-store"): New test.
2018-11-28 10:39:58 +01:00