summaryrefslogtreecommitdiff
path: root/guix/utils.scm
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2012-06-07 23:15:00 +0200
committerLudovic Courtès <ludo@gnu.org>2012-06-07 23:15:00 +0200
commitde4c3f26cbf25149265f779b5af08c79de47859c (patch)
treee89e4f66ede27773734b3a772e10df839753ea79 /guix/utils.scm
parent087602b687e28483923643b89490c2fd3b4d908b (diff)
Allow derivations with input derivations.
* guix/derivations.scm (derivation-path->output-path): New procedure. (derivation-hash): Call `memoize'. In the fixed-output case, convert HASH-ALGO to a string. In the other case, sort inputs in the alphabetical order of their hex hash. For inputs with no sub-drvs, add "out" as the sub-drv. * guix/utils.scm (%nixpkgs-directory): New parameter. (nixpkgs-derivation, memoize): New procedures. * tests/derivations.scm ("build derivation with 1 source"): Remove useless shebang. (%coreutils): New variable. ("build derivation with coreutils"): New test.
Diffstat (limited to 'guix/utils.scm')
-rw-r--r--guix/utils.scm46
1 files changed, 45 insertions, 1 deletions
diff --git a/guix/utils.scm b/guix/utils.scm
index a5f64f97a9..2ffecbfab9 100644
--- a/guix/utils.scm
+++ b/guix/utils.scm
@@ -19,9 +19,12 @@
(define-module (guix utils)
#:use-module (srfi srfi-1)
#:use-module (srfi srfi-26)
+ #:use-module (srfi srfi-39)
#:use-module (srfi srfi-60)
#:use-module (rnrs bytevectors)
#:use-module (ice-9 format)
+ #:autoload (ice-9 popen) (open-pipe*)
+ #:autoload (ice-9 rdelim) (read-line)
#:use-module ((chop hash)
#:select (bytevector-hash
hash-method/sha256))
@@ -29,7 +32,12 @@
bytevector->base32-string
bytevector->nix-base32-string
bytevector->base16-string
- sha256))
+ sha256
+
+ %nixpkgs-directory
+ nixpkgs-derivation
+
+ memoize))
;;;
@@ -198,3 +206,39 @@ the previous application or INIT."
"Return the SHA256 of BV as a bytevector."
(bytevector-hash hash-method/sha256 bv))
+
+
+;;;
+;;; Nixpkgs.
+;;;
+
+(define %nixpkgs-directory
+ (make-parameter (getenv "NIXPKGS")))
+
+(define (nixpkgs-derivation attribute)
+ "Return the derivation path of ATTRIBUTE in Nixpkgs."
+ (let* ((p (open-pipe* OPEN_READ "nix-instantiate" "-A"
+ attribute (%nixpkgs-directory)))
+ (l (read-line p))
+ (s (close-pipe p)))
+ (and (zero? (status:exit-val s))
+ (not (eof-object? l))
+ l)))
+
+
+;;;
+;;; Miscellaneous.
+;;;
+
+(define (memoize proc)
+ "Return a memoizing version of PROC."
+ (let ((cache (make-hash-table)))
+ (lambda args
+ (let ((results (hash-ref cache args)))
+ (if results
+ (apply values results)
+ (let ((results (call-with-values (lambda ()
+ (apply proc args))
+ list)))
+ (hash-set! cache args results)
+ (apply values results)))))))