2013-10-03 22:45:25 +02:00
|
|
|
|
;;; GNU Guix --- Functional package management for GNU
|
2014-01-29 13:04:48 +01:00
|
|
|
|
;;; Copyright © 2013, 2014 Ludovic Courtès <ludo@gnu.org>
|
2013-10-03 22:45:25 +02:00
|
|
|
|
;;;
|
|
|
|
|
;;; This file is part of GNU Guix.
|
|
|
|
|
;;;
|
|
|
|
|
;;; GNU Guix is free software; you can redistribute it and/or modify it
|
|
|
|
|
;;; under the terms of the GNU General Public License as published by
|
|
|
|
|
;;; the Free Software Foundation; either version 3 of the License, or (at
|
|
|
|
|
;;; your option) any later version.
|
|
|
|
|
;;;
|
|
|
|
|
;;; GNU Guix is distributed in the hope that it will be useful, but
|
|
|
|
|
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
;;; GNU General Public License for more details.
|
|
|
|
|
;;;
|
|
|
|
|
;;; You should have received a copy of the GNU General Public License
|
|
|
|
|
;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
(define-module (guix monads)
|
|
|
|
|
#:use-module (guix store)
|
|
|
|
|
#:use-module (guix derivations)
|
|
|
|
|
#:use-module (guix packages)
|
2013-10-02 21:58:19 +02:00
|
|
|
|
#:use-module ((system syntax)
|
|
|
|
|
#:select (syntax-local-binding))
|
2013-10-03 22:45:25 +02:00
|
|
|
|
#:use-module (ice-9 match)
|
2014-02-03 23:12:54 +01:00
|
|
|
|
#:use-module (srfi srfi-1)
|
2013-10-02 21:58:19 +02:00
|
|
|
|
#:use-module (srfi srfi-9)
|
2013-10-03 22:45:25 +02:00
|
|
|
|
#:use-module (srfi srfi-26)
|
|
|
|
|
#:export (;; Monads.
|
2013-10-02 21:58:19 +02:00
|
|
|
|
define-monad
|
2013-10-03 22:45:25 +02:00
|
|
|
|
monad?
|
|
|
|
|
monad-bind
|
|
|
|
|
monad-return
|
|
|
|
|
|
|
|
|
|
;; Syntax.
|
|
|
|
|
>>=
|
|
|
|
|
return
|
|
|
|
|
with-monad
|
|
|
|
|
mlet
|
|
|
|
|
mlet*
|
2014-10-08 23:35:08 +02:00
|
|
|
|
mbegin
|
2014-12-02 10:11:11 +01:00
|
|
|
|
mwhen
|
|
|
|
|
munless
|
2014-12-02 10:10:51 +01:00
|
|
|
|
lift0 lift1 lift2 lift3 lift4 lift5 lift6 lift7 lift
|
2013-10-03 22:45:25 +02:00
|
|
|
|
listm
|
|
|
|
|
foldm
|
|
|
|
|
mapm
|
|
|
|
|
sequence
|
|
|
|
|
anym
|
|
|
|
|
|
|
|
|
|
;; Concrete monads.
|
|
|
|
|
%identity-monad
|
|
|
|
|
|
|
|
|
|
%store-monad
|
|
|
|
|
store-bind
|
|
|
|
|
store-return
|
|
|
|
|
store-lift
|
|
|
|
|
run-with-store
|
|
|
|
|
text-file
|
2014-02-03 23:12:54 +01:00
|
|
|
|
text-file*
|
2014-07-24 22:27:35 +02:00
|
|
|
|
interned-file
|
2013-10-03 22:45:25 +02:00
|
|
|
|
package-file
|
2014-05-01 16:15:00 +02:00
|
|
|
|
origin->derivation
|
2013-10-03 22:45:25 +02:00
|
|
|
|
package->derivation
|
2014-08-17 20:56:47 +02:00
|
|
|
|
package->cross-derivation
|
2014-04-27 23:19:11 +02:00
|
|
|
|
built-derivations)
|
2014-01-29 13:04:48 +01:00
|
|
|
|
#:replace (imported-modules
|
|
|
|
|
compiled-modules))
|
2013-10-03 22:45:25 +02:00
|
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
;;;
|
|
|
|
|
;;; This module implements the general mechanism of monads, and provides in
|
|
|
|
|
;;; particular an instance of the "store" monad. The API was inspired by that
|
|
|
|
|
;;; of Racket's "better-monads" module (see
|
|
|
|
|
;;; <http://planet.racket-lang.org/package-source/toups/functional.plt/1/1/planet-docs/better-monads-guide/index.html>).
|
|
|
|
|
;;; The implementation and use case were influenced by Oleg Kysielov's
|
|
|
|
|
;;; "Monadic Programming in Scheme" (see
|
|
|
|
|
;;; <http://okmij.org/ftp/Scheme/monad-in-Scheme.html>).
|
|
|
|
|
;;;
|
|
|
|
|
;;; The store monad allows us to (1) build sequences of operations in the
|
|
|
|
|
;;; store, and (2) make the store an implicit part of the execution context,
|
|
|
|
|
;;; rather than a parameter of every single function.
|
|
|
|
|
;;;
|
|
|
|
|
;;; Code:
|
|
|
|
|
|
2013-10-02 21:58:19 +02:00
|
|
|
|
;; Record type for monads manipulated at run time.
|
|
|
|
|
(define-record-type <monad>
|
|
|
|
|
(make-monad bind return)
|
2013-10-03 22:45:25 +02:00
|
|
|
|
monad?
|
|
|
|
|
(bind monad-bind)
|
|
|
|
|
(return monad-return)) ; TODO: Add 'plus' and 'zero'
|
|
|
|
|
|
2013-10-02 21:58:19 +02:00
|
|
|
|
(define-syntax define-monad
|
|
|
|
|
(lambda (s)
|
|
|
|
|
"Define the monad under NAME, with the given bind and return methods."
|
|
|
|
|
(define prefix (string->symbol "% "))
|
|
|
|
|
(define (make-rtd-name name)
|
|
|
|
|
(datum->syntax name
|
|
|
|
|
(symbol-append prefix (syntax->datum name) '-rtd)))
|
|
|
|
|
|
|
|
|
|
(syntax-case s (bind return)
|
|
|
|
|
((_ name (bind b) (return r))
|
|
|
|
|
(with-syntax ((rtd (make-rtd-name #'name)))
|
|
|
|
|
#`(begin
|
|
|
|
|
(define rtd
|
|
|
|
|
;; The record type, for use at run time.
|
|
|
|
|
(make-monad b r))
|
|
|
|
|
|
|
|
|
|
(define-syntax name
|
|
|
|
|
;; An "inlined record", for use at expansion time. The goal is
|
|
|
|
|
;; to allow 'bind' and 'return' to be resolved at expansion
|
|
|
|
|
;; time, in the common case where the monad is accessed
|
|
|
|
|
;; directly as NAME.
|
|
|
|
|
(lambda (s)
|
|
|
|
|
(syntax-case s (%bind %return)
|
|
|
|
|
((_ %bind) #'b)
|
|
|
|
|
((_ %return) #'r)
|
|
|
|
|
(_ #'rtd))))))))))
|
|
|
|
|
|
2013-10-03 22:45:25 +02:00
|
|
|
|
(define-syntax-parameter >>=
|
|
|
|
|
;; The name 'bind' is already taken, so we choose this (obscure) symbol.
|
|
|
|
|
(lambda (s)
|
|
|
|
|
(syntax-violation '>>= ">>= (bind) used outside of 'with-monad'" s)))
|
|
|
|
|
|
|
|
|
|
(define-syntax-parameter return
|
|
|
|
|
(lambda (s)
|
|
|
|
|
(syntax-violation 'return "return used outside of 'with-monad'" s)))
|
|
|
|
|
|
|
|
|
|
(define-syntax with-monad
|
|
|
|
|
(lambda (s)
|
|
|
|
|
"Evaluate BODY in the context of MONAD, and return its result."
|
|
|
|
|
(syntax-case s ()
|
|
|
|
|
((_ monad body ...)
|
2013-10-02 21:58:19 +02:00
|
|
|
|
(eq? 'macro (syntax-local-binding #'monad))
|
|
|
|
|
;; MONAD is a syntax transformer, so we can obtain the bind and return
|
|
|
|
|
;; methods by directly querying it.
|
|
|
|
|
#'(syntax-parameterize ((>>= (identifier-syntax (monad %bind)))
|
|
|
|
|
(return (identifier-syntax (monad %return))))
|
|
|
|
|
body ...))
|
|
|
|
|
((_ monad body ...)
|
|
|
|
|
;; MONAD refers to the <monad> record that represents the monad at run
|
|
|
|
|
;; time, so use the slow method.
|
2013-10-03 22:45:25 +02:00
|
|
|
|
#'(syntax-parameterize ((>>= (identifier-syntax
|
|
|
|
|
(monad-bind monad)))
|
|
|
|
|
(return (identifier-syntax
|
|
|
|
|
(monad-return monad))))
|
|
|
|
|
body ...)))))
|
|
|
|
|
|
|
|
|
|
(define-syntax mlet*
|
|
|
|
|
(syntax-rules (->)
|
|
|
|
|
"Bind the given monadic values MVAL to the given variables VAR. When the
|
|
|
|
|
form is (VAR -> VAL), bind VAR to the non-monadic value VAL in the same way as
|
|
|
|
|
'let'."
|
|
|
|
|
;; Note: the '->' symbol corresponds to 'is:' in 'better-monads.rkt'.
|
|
|
|
|
((_ monad () body ...)
|
|
|
|
|
(with-monad monad body ...))
|
|
|
|
|
((_ monad ((var mval) rest ...) body ...)
|
|
|
|
|
(with-monad monad
|
|
|
|
|
(>>= mval
|
|
|
|
|
(lambda (var)
|
|
|
|
|
(mlet* monad (rest ...)
|
|
|
|
|
body ...)))))
|
|
|
|
|
((_ monad ((var -> val) rest ...) body ...)
|
|
|
|
|
(let ((var val))
|
|
|
|
|
(mlet* monad (rest ...)
|
|
|
|
|
body ...)))))
|
|
|
|
|
|
|
|
|
|
(define-syntax mlet
|
|
|
|
|
(lambda (s)
|
|
|
|
|
(syntax-case s ()
|
|
|
|
|
((_ monad ((var mval ...) ...) body ...)
|
|
|
|
|
(with-syntax (((temp ...) (generate-temporaries #'(var ...))))
|
|
|
|
|
#'(mlet* monad ((temp mval ...) ...)
|
|
|
|
|
(let ((var temp) ...)
|
|
|
|
|
body ...)))))))
|
|
|
|
|
|
2014-10-08 23:35:08 +02:00
|
|
|
|
(define-syntax mbegin
|
2014-12-02 10:11:11 +01:00
|
|
|
|
(syntax-rules (%current-monad)
|
2014-10-08 23:35:08 +02:00
|
|
|
|
"Bind the given monadic expressions in sequence, returning the result of
|
|
|
|
|
the last one."
|
2014-12-02 10:11:11 +01:00
|
|
|
|
((_ %current-monad mexp)
|
|
|
|
|
mexp)
|
|
|
|
|
((_ %current-monad mexp rest ...)
|
|
|
|
|
(>>= mexp
|
|
|
|
|
(lambda (unused-value)
|
|
|
|
|
(mbegin %current-monad rest ...))))
|
2014-10-08 23:35:08 +02:00
|
|
|
|
((_ monad mexp)
|
|
|
|
|
(with-monad monad
|
|
|
|
|
mexp))
|
|
|
|
|
((_ monad mexp rest ...)
|
|
|
|
|
(with-monad monad
|
|
|
|
|
(>>= mexp
|
|
|
|
|
(lambda (unused-value)
|
|
|
|
|
(mbegin monad rest ...)))))))
|
|
|
|
|
|
2014-12-02 10:11:11 +01:00
|
|
|
|
(define-syntax mwhen
|
|
|
|
|
(syntax-rules ()
|
|
|
|
|
"When CONDITION is true, evaluate EXP0..EXP* as in an 'mbegin'. When
|
|
|
|
|
CONDITION is false, return *unspecified* in the current monad."
|
|
|
|
|
((_ condition exp0 exp* ...)
|
|
|
|
|
(if condition
|
|
|
|
|
(mbegin %current-monad
|
|
|
|
|
exp0 exp* ...)
|
|
|
|
|
(return *unspecified*)))))
|
|
|
|
|
|
|
|
|
|
(define-syntax munless
|
|
|
|
|
(syntax-rules ()
|
|
|
|
|
"When CONDITION is false, evaluate EXP0..EXP* as in an 'mbegin'. When
|
|
|
|
|
CONDITION is true, return *unspecified* in the current monad."
|
|
|
|
|
((_ condition exp0 exp* ...)
|
|
|
|
|
(if condition
|
|
|
|
|
(return *unspecified*)
|
|
|
|
|
(mbegin %current-monad
|
|
|
|
|
exp0 exp* ...)))))
|
|
|
|
|
|
2013-10-03 22:45:25 +02:00
|
|
|
|
(define-syntax define-lift
|
|
|
|
|
(syntax-rules ()
|
|
|
|
|
((_ liftn (args ...))
|
|
|
|
|
(define (liftn proc monad)
|
|
|
|
|
"Lift PROC to MONAD---i.e., return a monadic function in MONAD."
|
|
|
|
|
(lambda (args ...)
|
|
|
|
|
(with-monad monad
|
|
|
|
|
(return (proc args ...))))))))
|
|
|
|
|
|
2014-12-02 10:10:51 +01:00
|
|
|
|
(define-lift lift0 ())
|
2013-10-03 22:45:25 +02:00
|
|
|
|
(define-lift lift1 (a))
|
|
|
|
|
(define-lift lift2 (a b))
|
|
|
|
|
(define-lift lift3 (a b c))
|
|
|
|
|
(define-lift lift4 (a b c d))
|
|
|
|
|
(define-lift lift5 (a b c d e))
|
|
|
|
|
(define-lift lift6 (a b c d e f))
|
|
|
|
|
(define-lift lift7 (a b c d e f g))
|
|
|
|
|
|
2014-11-05 22:25:09 +01:00
|
|
|
|
(define (lift proc monad)
|
|
|
|
|
"Lift PROC, a procedure that accepts an arbitrary number of arguments, to
|
|
|
|
|
MONAD---i.e., return a monadic function in MONAD."
|
2013-10-03 22:45:25 +02:00
|
|
|
|
(lambda args
|
|
|
|
|
(with-monad monad
|
|
|
|
|
(return (apply proc args)))))
|
|
|
|
|
|
|
|
|
|
(define (foldm monad mproc init lst)
|
|
|
|
|
"Fold MPROC over LST, a list of monadic values in MONAD, and return a
|
|
|
|
|
monadic value seeded by INIT."
|
|
|
|
|
(with-monad monad
|
|
|
|
|
(let loop ((lst lst)
|
|
|
|
|
(result init))
|
|
|
|
|
(match lst
|
|
|
|
|
(()
|
|
|
|
|
(return result))
|
|
|
|
|
((head tail ...)
|
|
|
|
|
(mlet* monad ((item head)
|
|
|
|
|
(result (mproc item result)))
|
|
|
|
|
(loop tail result)))))))
|
|
|
|
|
|
|
|
|
|
(define (mapm monad mproc lst)
|
|
|
|
|
"Map MPROC over LST, a list of monadic values in MONAD, and return a monadic
|
2014-07-12 17:16:36 +02:00
|
|
|
|
list. LST items are bound from left to right, so effects in MONAD are known
|
|
|
|
|
to happen in that order."
|
|
|
|
|
(mlet monad ((result (foldm monad
|
|
|
|
|
(lambda (item result)
|
|
|
|
|
(mlet monad ((item (mproc item)))
|
|
|
|
|
(return (cons item result))))
|
|
|
|
|
'()
|
|
|
|
|
lst)))
|
|
|
|
|
(return (reverse result))))
|
2013-10-03 22:45:25 +02:00
|
|
|
|
|
|
|
|
|
(define-inlinable (sequence monad lst)
|
|
|
|
|
"Turn the list of monadic values LST into a monadic list of values, by
|
|
|
|
|
evaluating each item of LST in sequence."
|
|
|
|
|
(with-monad monad
|
|
|
|
|
(mapm monad return lst)))
|
|
|
|
|
|
|
|
|
|
(define (anym monad proc lst)
|
|
|
|
|
"Apply PROC to the list of monadic values LST; return the first value,
|
|
|
|
|
lifted in MONAD, for which PROC returns true."
|
|
|
|
|
(with-monad monad
|
|
|
|
|
(let loop ((lst lst))
|
|
|
|
|
(match lst
|
|
|
|
|
(()
|
|
|
|
|
(return #f))
|
|
|
|
|
((head tail ...)
|
2013-12-09 21:10:28 +01:00
|
|
|
|
(mlet* monad ((value head)
|
|
|
|
|
(result -> (proc value)))
|
|
|
|
|
(if result
|
|
|
|
|
(return result)
|
2013-10-03 22:45:25 +02:00
|
|
|
|
(loop tail))))))))
|
|
|
|
|
|
|
|
|
|
(define-syntax listm
|
|
|
|
|
(lambda (s)
|
|
|
|
|
"Return a monadic list in MONAD from the monadic values MVAL."
|
|
|
|
|
(syntax-case s ()
|
|
|
|
|
((_ monad mval ...)
|
|
|
|
|
(with-syntax (((val ...) (generate-temporaries #'(mval ...))))
|
|
|
|
|
#'(mlet monad ((val mval) ...)
|
|
|
|
|
(return (list val ...))))))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
;;; Identity monad.
|
|
|
|
|
;;;
|
|
|
|
|
|
2013-10-02 21:58:19 +02:00
|
|
|
|
(define-inlinable (identity-return value)
|
2013-10-03 22:45:25 +02:00
|
|
|
|
value)
|
|
|
|
|
|
2013-10-02 21:58:19 +02:00
|
|
|
|
(define-inlinable (identity-bind mvalue mproc)
|
2013-10-03 22:45:25 +02:00
|
|
|
|
(mproc mvalue))
|
|
|
|
|
|
2013-10-02 21:58:19 +02:00
|
|
|
|
(define-monad %identity-monad
|
|
|
|
|
(bind identity-bind)
|
|
|
|
|
(return identity-return))
|
2013-10-03 22:45:25 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
;;; Store monad.
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
;; return:: a -> StoreM a
|
2013-10-02 21:58:19 +02:00
|
|
|
|
(define-inlinable (store-return value)
|
2013-10-03 22:45:25 +02:00
|
|
|
|
"Return VALUE from a monadic function."
|
|
|
|
|
;; The monadic value is just this.
|
|
|
|
|
(lambda (store)
|
|
|
|
|
value))
|
|
|
|
|
|
|
|
|
|
;; >>=:: StoreM a -> (a -> StoreM b) -> StoreM b
|
2013-10-02 21:58:19 +02:00
|
|
|
|
(define-inlinable (store-bind mvalue mproc)
|
|
|
|
|
"Bind MVALUE in MPROC."
|
2013-10-03 22:45:25 +02:00
|
|
|
|
(lambda (store)
|
|
|
|
|
(let* ((value (mvalue store))
|
|
|
|
|
(mresult (mproc value)))
|
|
|
|
|
(mresult store))))
|
|
|
|
|
|
2013-10-02 21:58:19 +02:00
|
|
|
|
(define-monad %store-monad
|
|
|
|
|
(bind store-bind)
|
|
|
|
|
(return store-return))
|
2013-10-03 22:45:25 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define (store-lift proc)
|
|
|
|
|
"Lift PROC, a procedure whose first argument is a connection to the store,
|
|
|
|
|
in the store monad."
|
|
|
|
|
(define result
|
|
|
|
|
(lambda args
|
|
|
|
|
(lambda (store)
|
|
|
|
|
(apply proc store args))))
|
|
|
|
|
|
|
|
|
|
(set-object-property! result 'documentation
|
|
|
|
|
(procedure-property proc 'documentation))
|
|
|
|
|
result)
|
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
;;; Store monad operators.
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
(define* (text-file name text)
|
|
|
|
|
"Return as a monadic value the absolute file name in the store of the file
|
2014-02-03 23:12:54 +01:00
|
|
|
|
containing TEXT, a string."
|
2013-10-03 22:45:25 +02:00
|
|
|
|
(lambda (store)
|
|
|
|
|
(add-text-to-store store name text '())))
|
|
|
|
|
|
2014-02-03 23:12:54 +01:00
|
|
|
|
(define* (text-file* name #:rest text)
|
|
|
|
|
"Return as a monadic value a derivation that builds a text file containing
|
|
|
|
|
all of TEXT. TEXT may list, in addition to strings, packages, derivations,
|
|
|
|
|
and store file names; the resulting store file holds references to all these."
|
|
|
|
|
(define inputs
|
|
|
|
|
;; Transform packages and derivations from TEXT into a valid input list.
|
|
|
|
|
(filter-map (match-lambda
|
|
|
|
|
((? package? p) `("x" ,p))
|
|
|
|
|
((? derivation? d) `("x" ,d))
|
|
|
|
|
((x ...) `("x" ,@x))
|
|
|
|
|
((? string? s)
|
|
|
|
|
(and (direct-store-path? s) `("x" ,s)))
|
|
|
|
|
(x x))
|
|
|
|
|
text))
|
|
|
|
|
|
|
|
|
|
(define (computed-text text inputs)
|
|
|
|
|
;; Using the lowered INPUTS, return TEXT with derivations replaced with
|
|
|
|
|
;; their output file name.
|
|
|
|
|
(define (real-string? s)
|
|
|
|
|
(and (string? s) (not (direct-store-path? s))))
|
|
|
|
|
|
|
|
|
|
(let loop ((inputs inputs)
|
|
|
|
|
(text text)
|
|
|
|
|
(result '()))
|
|
|
|
|
(match text
|
|
|
|
|
(()
|
|
|
|
|
(string-concatenate-reverse result))
|
|
|
|
|
(((? real-string? head) rest ...)
|
|
|
|
|
(loop inputs rest (cons head result)))
|
|
|
|
|
((_ rest ...)
|
|
|
|
|
(match inputs
|
|
|
|
|
(((_ (? derivation? drv) sub-drv ...) inputs ...)
|
|
|
|
|
(loop inputs rest
|
|
|
|
|
(cons (apply derivation->output-path drv
|
|
|
|
|
sub-drv)
|
|
|
|
|
result)))
|
|
|
|
|
(((_ file) inputs ...)
|
|
|
|
|
;; FILE is the result of 'add-text-to-store' or so.
|
|
|
|
|
(loop inputs rest (cons file result))))))))
|
|
|
|
|
|
|
|
|
|
(define (builder inputs)
|
|
|
|
|
`(call-with-output-file (assoc-ref %outputs "out")
|
|
|
|
|
(lambda (port)
|
|
|
|
|
(display ,(computed-text text inputs) port))))
|
|
|
|
|
|
2014-04-27 23:19:11 +02:00
|
|
|
|
;; TODO: Rewrite using 'gexp->derivation'.
|
2014-02-03 23:12:54 +01:00
|
|
|
|
(mlet %store-monad ((inputs (lower-inputs inputs)))
|
|
|
|
|
(derivation-expression name (builder inputs)
|
|
|
|
|
#:inputs inputs)))
|
|
|
|
|
|
2014-07-24 22:27:35 +02:00
|
|
|
|
(define* (interned-file file #:optional name
|
|
|
|
|
#:key (recursive? #t))
|
|
|
|
|
"Return the name of FILE once interned in the store. Use NAME as its store
|
|
|
|
|
name, or the basename of FILE if NAME is omitted.
|
|
|
|
|
|
|
|
|
|
When RECURSIVE? is true, the contents of FILE are added recursively; if FILE
|
|
|
|
|
designates a flat file and RECURSIVE? is true, its contents are added, and its
|
|
|
|
|
permission bits are kept."
|
|
|
|
|
(lambda (store)
|
|
|
|
|
(add-to-store store (or name (basename file))
|
|
|
|
|
recursive? "sha256" file)))
|
|
|
|
|
|
2013-10-03 22:45:25 +02:00
|
|
|
|
(define* (package-file package
|
|
|
|
|
#:optional file
|
2014-08-17 20:56:47 +02:00
|
|
|
|
#:key
|
2014-08-17 21:08:06 +02:00
|
|
|
|
system (output "out") target)
|
2014-01-29 13:04:48 +01:00
|
|
|
|
"Return as a monadic value the absolute file name of FILE within the
|
2013-10-03 22:45:25 +02:00
|
|
|
|
OUTPUT directory of PACKAGE. When FILE is omitted, return the name of the
|
2014-08-17 20:56:47 +02:00
|
|
|
|
OUTPUT directory of PACKAGE. When TARGET is true, use it as a
|
|
|
|
|
cross-compilation target triplet."
|
2013-10-03 22:45:25 +02:00
|
|
|
|
(lambda (store)
|
2014-08-17 20:56:47 +02:00
|
|
|
|
(define compute-derivation
|
|
|
|
|
(if target
|
|
|
|
|
(cut package-cross-derivation <> <> target <>)
|
|
|
|
|
package-derivation))
|
|
|
|
|
|
|
|
|
|
(let* ((system (or system (%current-system)))
|
|
|
|
|
(drv (compute-derivation store package system))
|
|
|
|
|
(out (derivation->output-path drv output)))
|
2013-10-03 22:45:25 +02:00
|
|
|
|
(if file
|
|
|
|
|
(string-append out "/" file)
|
|
|
|
|
out))))
|
|
|
|
|
|
2013-12-09 21:32:36 +01:00
|
|
|
|
(define (lower-inputs inputs)
|
|
|
|
|
"Turn any package from INPUTS into a derivation; return the corresponding
|
|
|
|
|
input list as a monadic value."
|
2014-04-27 23:19:11 +02:00
|
|
|
|
;; XXX: This procedure is bound to disappear with 'derivation-expression'.
|
2013-12-09 21:32:36 +01:00
|
|
|
|
(with-monad %store-monad
|
|
|
|
|
(sequence %store-monad
|
|
|
|
|
(map (match-lambda
|
|
|
|
|
((name (? package? package) sub-drv ...)
|
|
|
|
|
(mlet %store-monad ((drv (package->derivation package)))
|
|
|
|
|
(return `(,name ,drv ,@sub-drv))))
|
|
|
|
|
((name (? string? file))
|
|
|
|
|
(return `(,name ,file)))
|
|
|
|
|
(tuple
|
|
|
|
|
(return tuple)))
|
|
|
|
|
inputs))))
|
|
|
|
|
|
2013-10-03 22:45:25 +02:00
|
|
|
|
(define derivation-expression
|
2014-04-27 23:19:11 +02:00
|
|
|
|
;; XXX: This procedure is superseded by 'gexp->derivation'.
|
2013-10-03 22:45:25 +02:00
|
|
|
|
(store-lift build-expression->derivation))
|
|
|
|
|
|
|
|
|
|
(define package->derivation
|
|
|
|
|
(store-lift package-derivation))
|
|
|
|
|
|
2014-08-17 20:56:47 +02:00
|
|
|
|
(define package->cross-derivation
|
|
|
|
|
(store-lift package-cross-derivation))
|
|
|
|
|
|
2014-05-01 16:15:00 +02:00
|
|
|
|
(define origin->derivation
|
|
|
|
|
(store-lift package-source-derivation))
|
|
|
|
|
|
2014-01-29 13:04:48 +01:00
|
|
|
|
(define imported-modules
|
|
|
|
|
(store-lift (@ (guix derivations) imported-modules)))
|
|
|
|
|
|
|
|
|
|
(define compiled-modules
|
|
|
|
|
(store-lift (@ (guix derivations) compiled-modules)))
|
|
|
|
|
|
2013-10-03 22:45:25 +02:00
|
|
|
|
(define built-derivations
|
|
|
|
|
(store-lift build-derivations))
|
|
|
|
|
|
|
|
|
|
(define* (run-with-store store mval
|
|
|
|
|
#:key
|
|
|
|
|
(guile-for-build (%guile-for-build))
|
|
|
|
|
(system (%current-system)))
|
|
|
|
|
"Run MVAL, a monadic value in the store monad, in STORE, an open store
|
|
|
|
|
connection."
|
2014-05-01 18:53:16 +02:00
|
|
|
|
(define (default-guile)
|
|
|
|
|
;; Lazily resolve 'guile-final'. This module must not refer to (gnu …)
|
|
|
|
|
;; modules directly, to avoid circular dependencies, hence this hack.
|
gnu: Split (gnu packages base), adding (gnu packages commencement).
* gnu/packages/base.scm (gnu-make-boot0, diffutils-boot0,
findutils-boot0, %boot0-inputs, nix-system->gnu-triplet, boot-triplet,
binutils-boot0, gcc-boot0, perl-boot0, linux-libre-headers-boot0,
texinfo-boot0, %boot1-inputs, glibc-final-with-bootstrap-bash,
cross-gcc-wrapper, static-bash-for-glibc, glibc-final,
gcc-boot0-wrapped, %boot2-inputs, binutils-final, libstdc++,
gcc-final, ld-wrapper-boot3, %boot3-inputs, bash-final, %boot4-inputs,
guile-final, gnu-make-final, ld-wrapper, coreutils-final, grep-final,
%boot5-inputs, %final-inputs, canonical-package, gcc-toolchain,
gcc-toolchain-4.8, gcc-toolchain-4.9): Move to...
* gnu/packages/commencement.scm: ... here. New file.
* gnu-system.am (GNU_SYSTEM_MODULES): Add it.
* build-aux/check-final-inputs-self-contained.scm: Adjust accordingly.
* gnu/packages/cross-base.scm: Likewise.
* gnu/packages/make-bootstrap.scm: Likewise.
* guix/build-system/cmake.scm (cmake-build): Likewise.
* guix/build-system/gnu.scm (standard-packages, gnu-build,
gnu-cross-build): Likewise.
* guix/build-system/perl.scm (perl-build): Likewise.
* guix/build-system/python.scm (python-build): Likewise.
* guix/build-system/trivial.scm (guile-for-build): Likewise.
* guix/download.scm (url-fetch): Likewise.
* guix/gexp.scm (default-guile): Likewise.
* guix/git-download.scm (git-fetch): Likewise.
* guix/monads.scm (run-with-store): Likewise.
* guix/packages.scm (default-guile): Likewise.
* guix/scripts/package.scm (guix-package): Likewise.
* guix/scripts/refresh.scm: Likewise.
* guix/svn-download.scm (svn-fetch): Likewise.
* tests/builders.scm (%bootstrap-inputs, %bootstrap-search-paths):
Likewise.
* tests/packages.scm ("GNU Make, bootstrap"): Likewise.
* tests/guix-package.sh: Likewise.
* gnu/services/base.scm: Use 'canonical-package' instead of xxx-final.
* gnu/services/xorg.scm: Likewise.
* gnu/system/vm.scm: Likewise.
* guix/scripts/pull.scm (guix-pull): Likewise.
2014-08-27 00:25:17 +02:00
|
|
|
|
(module-ref (resolve-interface '(gnu packages commencement))
|
2014-05-01 18:53:16 +02:00
|
|
|
|
'guile-final))
|
|
|
|
|
|
2013-10-03 22:45:25 +02:00
|
|
|
|
(parameterize ((%guile-for-build (or guile-for-build
|
|
|
|
|
(package-derivation store
|
2014-05-01 18:53:16 +02:00
|
|
|
|
(default-guile)
|
2013-10-03 22:45:25 +02:00
|
|
|
|
system)))
|
|
|
|
|
(%current-system system))
|
|
|
|
|
(mval store)))
|
|
|
|
|
|
|
|
|
|
;;; monads.scm end here
|