From 592ef6c88fa8342d23142154c8392f6f1032275f Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Sun, 21 Oct 2012 16:57:50 +0200 Subject: packages: Add support for system-dependent inputs. * guix/packages.scm (package-derivation)[intern]: New procedure. Pass #t as the `recursive?' argument, instead of #f. [expand-input]: New procedure, with code formerly in the body. Support inputs where the input is a procedure returning a file name or an . Use `expand-input' in the body. * tests/packages.scm ("trivial with system-dependent input"): New test. --- guix/packages.scm | 71 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 46 insertions(+), 25 deletions(-) (limited to 'guix') diff --git a/guix/packages.scm b/guix/packages.scm index 4b687717e4..9a54eb747a 100644 --- a/guix/packages.scm +++ b/guix/packages.scm @@ -227,6 +227,51 @@ (define (cached-derivation package system) (define* (package-derivation store package #:optional (system (%current-system))) "Return the derivation of PACKAGE for SYSTEM." + (define (intern file) + ;; Add FILE to the store. Set the `recursive?' bit to #t, so that + ;; file permissions are preserved. + (add-to-store store (basename file) + #t #t "sha256" file)) + + (define expand-input + ;; Expand the given input tuple such that it contains only + ;; references to derivation paths or store paths. + (match-lambda + (((? string? name) (? package? package)) + (list name (package-derivation store package))) + (((? string? name) (? package? package) + (? string? sub-drv)) + (list name (package-derivation store package) + sub-drv)) + (((? string? name) + (and (? string?) (? derivation-path?) drv)) + (list name drv)) + (((? string? name) + (and (? string?) (? file-exists? file))) + ;; Add FILE to the store. When FILE is in the sub-directory of a + ;; store path, it needs to be added anyway, so it can be used as a + ;; source. + (list name (intern file))) + (((? string? name) (? origin? source)) + (list name (package-source-derivation store source))) + ((and i ((? string? name) (? procedure? proc) sub-drv ...)) + ;; This form allows PROC to make a SYSTEM-dependent choice. + + ;; XXX: Currently PROC must return a .drv, a store path, a local + ;; file name, or an . If it were allowed to return a + ;; package, then `transitive-inputs' and co. would need to be + ;; adjusted. + (let ((input (proc system))) + (if (or (string? input) (origin? input)) + (expand-input (cons* name input sub-drv)) + (raise (condition (&package-input-error + (package package) + (input i))))))) + (x + (raise (condition (&package-input-error + (package package) + (input x))))))) + (or (cached-derivation package system) ;; Compute the derivation and cache the result. Caching is @@ -241,31 +286,7 @@ (define* (package-derivation store package outputs) ;; TODO: For `search-paths', add a builder prologue that calls ;; `set-path-environment-variable'. - (let ((inputs (map (match-lambda - (((? string? name) (? package? package)) - (list name (package-derivation store package))) - (((? string? name) (? package? package) - (? string? sub-drv)) - (list name (package-derivation store package) - sub-drv)) - (((? string? name) - (and (? string?) (? derivation-path?) drv)) - (list name drv)) - (((? string? name) - (and (? string?) (? file-exists? file))) - ;; Add FILE to the store. When FILE is in the - ;; sub-directory of a store path, it needs to be - ;; added anyway, so it can be used as a source. - (list name - (add-to-store store (basename file) - #t #f "sha256" file))) - (((? string? name) (? origin? source)) - (list name - (package-source-derivation store source))) - (x - (raise (condition (&package-input-error - (package package) - (input x)))))) + (let ((inputs (map expand-input (package-transitive-inputs package)))) (apply builder -- cgit v1.2.3