aboutsummaryrefslogtreecommitdiff
path: root/guix/gexp.scm
diff options
context:
space:
mode:
authorMarius Bakke <mbakke@fastmail.com>2017-10-24 22:00:23 +0200
committerMarius Bakke <mbakke@fastmail.com>2017-10-24 22:00:23 +0200
commitca4fd41de892c7055ce140863382c332441b15d3 (patch)
tree39872899c5bc649e11172dccb2f262a56f234661 /guix/gexp.scm
parent7276eca4dcbe513922d5a778ee5fc8f2b2649642 (diff)
parent648c896ad3b198a1742c1ee8f66a1922aa98c1d8 (diff)
downloadpatches-ca4fd41de892c7055ce140863382c332441b15d3.tar
patches-ca4fd41de892c7055ce140863382c332441b15d3.tar.gz
Merge branch 'master' into core-updates
Diffstat (limited to 'guix/gexp.scm')
-rw-r--r--guix/gexp.scm52
1 files changed, 52 insertions, 0 deletions
diff --git a/guix/gexp.scm b/guix/gexp.scm
index 2622c5cb62..b9525603ee 100644
--- a/guix/gexp.scm
+++ b/guix/gexp.scm
@@ -78,6 +78,8 @@
gexp->script
text-file*
mixed-text-file
+ file-union
+ directory-union
imported-files
imported-modules
compiled-modules
@@ -1171,6 +1173,56 @@ This is the declarative counterpart of 'text-file*'."
(computed-file name build))
+(define (file-union name files)
+ "Return a <computed-file> that builds a directory containing all of FILES.
+Each item in FILES must be a two-element list where the first element is the
+file name to use in the new directory, and the second element is a gexp
+denoting the target file. Here's an example:
+
+ (file-union \"etc\"
+ `((\"hosts\" ,(plain-file \"hosts\"
+ \"127.0.0.1 localhost\"))
+ (\"bashrc\" ,(plain-file \"bashrc\"
+ \"alias ls='ls --color'\"))))
+
+This yields an 'etc' directory containing these two files."
+ (computed-file name
+ (gexp
+ (begin
+ (mkdir (ungexp output))
+ (chdir (ungexp output))
+ (ungexp-splicing
+ (map (match-lambda
+ ((target source)
+ (gexp
+ (begin
+ ;; Stat the source to abort early if it does
+ ;; not exist.
+ (stat (ungexp source))
+
+ (symlink (ungexp source)
+ (ungexp target))))))
+ files))))))
+
+(define (directory-union name things)
+ "Return a directory that is the union of THINGS, where THINGS is a list of
+file-like objects denoting directories. For example:
+
+ (directory-union \"guile+emacs\" (list guile emacs))
+
+yields a directory that is the union of the 'guile' and 'emacs' packages."
+ (match things
+ ((one)
+ ;; Only one thing; return it.
+ one)
+ (_
+ (computed-file name
+ (with-imported-modules '((guix build union))
+ (gexp (begin
+ (use-modules (guix build union))
+ (union-build (ungexp output)
+ '(ungexp things)))))))))
+
;;;
;;; Syntactic sugar.