From ce4a482983abaf7090d098cdda973139cefb56b7 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Sun, 19 Jan 2014 23:03:43 +0100 Subject: store: Add 'with-store' convenience macro. * guix/store.scm (with-store): New macro. --- guix/store.scm | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'guix') diff --git a/guix/store.scm b/guix/store.scm index 393eee8d1b..ede64341c5 100644 --- a/guix/store.scm +++ b/guix/store.scm @@ -53,6 +53,7 @@ (define-module (guix store) open-connection close-connection + with-store set-build-options valid-path? query-path-hash @@ -323,6 +324,17 @@ (define (close-connection server) "Close the connection to SERVER." (close (nix-server-socket server))) +(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." + (let ((store (open-connection))) + (dynamic-wind + (const #f) + (lambda () + exp ...) + (lambda () + (false-if-exception (close-connection store)))))) + (define current-build-output-port ;; The port where build output is sent. (make-parameter (current-error-port))) -- cgit v1.2.3