From de4c3f26cbf25149265f779b5af08c79de47859c Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Thu, 7 Jun 2012 23:15:00 +0200 Subject: 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. --- guix/utils.scm | 46 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) (limited to 'guix/utils.scm') 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))))))) -- cgit v1.2.3