monads: Add 'interned-file'.
* guix/monads.scm (interned-file): New procedure. * tests/monads.scm ("interned-file"): New test. * doc/guix.texi (The Store Monad): Document it.master
parent
7ab44369b3
commit
0a90af1531
|
@ -2012,6 +2012,29 @@ will references @var{coreutils}, @var{grep}, and @var{sed}, thereby
|
||||||
preventing them from being garbage-collected during its lifetime.
|
preventing them from being garbage-collected during its lifetime.
|
||||||
@end deffn
|
@end deffn
|
||||||
|
|
||||||
|
@deffn {Monadic Procedure} interned-file @var{file} [@var{name}] @
|
||||||
|
[#:recursive? #t]
|
||||||
|
Return the name of @var{file} once interned in the store. Use
|
||||||
|
@var{name} as its store name, or the basename of @var{file} if
|
||||||
|
@var{name} is omitted.
|
||||||
|
|
||||||
|
When @var{recursive?} is true, the contents of @var{file} are added
|
||||||
|
recursively; if @var{file} designates a flat file and @var{recursive?}
|
||||||
|
is true, its contents are added, and its permission bits are kept.
|
||||||
|
|
||||||
|
The example below adds a file to the store, under two different names:
|
||||||
|
|
||||||
|
@example
|
||||||
|
(run-with-store (open-connection)
|
||||||
|
(mlet %store-monad ((a (interned-file "README"))
|
||||||
|
(b (interned-file "README" "LEGU-MIN")))
|
||||||
|
(return (list a b))))
|
||||||
|
|
||||||
|
@result{} ("/gnu/store/rwm@dots{}-README" "/gnu/store/44i@dots{}-LEGU-MIN")
|
||||||
|
@end example
|
||||||
|
|
||||||
|
@end deffn
|
||||||
|
|
||||||
@deffn {Monadic Procedure} package-file @var{package} [@var{file}] @
|
@deffn {Monadic Procedure} package-file @var{package} [@var{file}] @
|
||||||
[#:system (%current-system)] [#:output "out"] Return as a monadic
|
[#:system (%current-system)] [#:output "out"] Return as a monadic
|
||||||
value in the absolute file name of @var{file} within the @var{output}
|
value in the absolute file name of @var{file} within the @var{output}
|
||||||
|
|
|
@ -55,6 +55,7 @@
|
||||||
run-with-store
|
run-with-store
|
||||||
text-file
|
text-file
|
||||||
text-file*
|
text-file*
|
||||||
|
interned-file
|
||||||
package-file
|
package-file
|
||||||
origin->derivation
|
origin->derivation
|
||||||
package->derivation
|
package->derivation
|
||||||
|
@ -362,6 +363,18 @@ and store file names; the resulting store file holds references to all these."
|
||||||
(derivation-expression name (builder inputs)
|
(derivation-expression name (builder inputs)
|
||||||
#:inputs inputs)))
|
#:inputs inputs)))
|
||||||
|
|
||||||
|
(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)))
|
||||||
|
|
||||||
(define* (package-file package
|
(define* (package-file package
|
||||||
#:optional file
|
#:optional file
|
||||||
#:key (system (%current-system)) (output "out"))
|
#:key (system (%current-system)) (output "out"))
|
||||||
|
|
|
@ -108,6 +108,16 @@
|
||||||
guile)))
|
guile)))
|
||||||
#:guile-for-build (package-derivation %store %bootstrap-guile)))
|
#:guile-for-build (package-derivation %store %bootstrap-guile)))
|
||||||
|
|
||||||
|
(test-assert "interned-file"
|
||||||
|
(run-with-store %store
|
||||||
|
(mlet* %store-monad ((file -> (search-path %load-path "guix.scm"))
|
||||||
|
(a (interned-file file))
|
||||||
|
(b (interned-file file "b")))
|
||||||
|
(return (equal? (call-with-input-file file get-string-all)
|
||||||
|
(call-with-input-file a get-string-all)
|
||||||
|
(call-with-input-file b get-string-all))))
|
||||||
|
#:guile-for-build (package-derivation %store %bootstrap-guile)))
|
||||||
|
|
||||||
(define derivation-expression
|
(define derivation-expression
|
||||||
(@@ (guix monads) derivation-expression))
|
(@@ (guix monads) derivation-expression))
|
||||||
|
|
||||||
|
|
Reference in New Issue