aboutsummaryrefslogtreecommitdiff
path: root/guix
diff options
context:
space:
mode:
authorMark H Weaver <mhw@netris.org>2015-01-13 12:14:08 -0500
committerMark H Weaver <mhw@netris.org>2015-01-13 12:14:08 -0500
commita813710a5fb0822e9d95088462d70f6522fe8457 (patch)
tree35299db4712eda92c809635716d530d085223e81 /guix
parentd8cd15949092b7cd90ee1dcc4aefe87b3ba4a6fb (diff)
parent765f0ac8f9f67f775a667a4276faf85ddde6d7ea (diff)
downloadguix-a813710a5fb0822e9d95088462d70f6522fe8457.tar
guix-a813710a5fb0822e9d95088462d70f6522fe8457.tar.gz
Merge branch 'master' into core-updates
Diffstat (limited to 'guix')
-rw-r--r--guix/build-system/glib-or-gtk.scm30
-rw-r--r--guix/build/glib-or-gtk-build-system.scm139
-rw-r--r--guix/derivations.scm25
-rw-r--r--guix/gexp.scm17
-rw-r--r--guix/monads.scm73
-rw-r--r--guix/sets.scm116
6 files changed, 288 insertions, 112 deletions
diff --git a/guix/build-system/glib-or-gtk.scm b/guix/build-system/glib-or-gtk.scm
index 8091311879..7a90587136 100644
--- a/guix/build-system/glib-or-gtk.scm
+++ b/guix/build-system/glib-or-gtk.scm
@@ -34,15 +34,14 @@
;; This build system is an extension of the 'gnu-build-system'. It
;; accomodates the needs of applications making use of glib or gtk+ (with "or"
;; to be interpreted in the mathematical sense). This is achieved by adding
-;; two phases run after the 'install' phase:
+;; three phases run after the 'install' phase:
;;
;; 'glib-or-gtk-wrap' phase:
;;
-;; a) This phase looks for GSettings schemas by verifying the existence of
-;; path "datadir/glib-2.0/schemas" in all input packages. If the path is
-;; found in any package, then all programs in "out/bin" are wrapped in scripts
-;; where the environment variable "XDG_DATA_DIRS" is set and points to the
-;; list of found schemas directories.
+;; a) This phase looks for GSettings schemas, GIO modules and theming data.
+;; If any of these is found in any input package, then all programs in
+;; "out/bin" are wrapped in scripts defining the nedessary environment
+;; variables.
;;
;; b) Looks for the existence of "libdir/gtk-3.0" directories in all input
;; packages. If any is found, then the environment variable "GTK_PATH" is
@@ -56,6 +55,11 @@
;; exists and does not include a file named "gschemas.compiled", then
;; "glib-compile-schemas" is run in that directory.
;;
+;; 'glib-or-gtk-icon-cache' phase:
+;;
+;; Looks for the existence of icon themes and, if no cache exists, generate
+;; the "icon-theme.cache" file.
+;;
;; Code:
(define %default-modules
@@ -76,15 +80,22 @@
(let ((module (resolve-interface '(gnu packages glib))))
(module-ref module 'glib)))
+(define (default-gtk+)
+ "Return the default gtk+ package from which we use
+\"gtk-update-icon-cache\"."
+ (let ((module (resolve-interface '(gnu packages gtk))))
+ (module-ref module 'gtk+)))
+
(define* (lower name
#:key source inputs native-inputs outputs system target
- (glib (default-glib)) (implicit-inputs? #t)
+ (glib (default-glib)) (gtk+ (default-gtk+))
+ (implicit-inputs? #t)
(strip-binaries? #t)
#:allow-other-keys
#:rest arguments)
"Return a bag for NAME."
(define private-keywords
- '(#:source #:target #:glib #:inputs #:native-inputs
+ '(#:source #:target #:glib #:gtk+ #:inputs #:native-inputs
#:outputs #:implicit-inputs?))
(and (not target) ;XXX: no cross-compilation
@@ -95,7 +106,8 @@
`(("source" ,source))
'())
,@inputs))
- (build-inputs `(("glib:bin" ,glib)
+ (build-inputs `(("glib:bin" ,glib "bin") ; to compile schemas
+ ("gtk+" ,gtk+) ; to generate icon cache
,@(if implicit-inputs?
(standard-packages)
'())
diff --git a/guix/build/glib-or-gtk-build-system.scm b/guix/build/glib-or-gtk-build-system.scm
index 9351a70a0e..a404a84f3f 100644
--- a/guix/build/glib-or-gtk-build-system.scm
+++ b/guix/build/glib-or-gtk-build-system.scm
@@ -22,6 +22,7 @@
#:use-module (guix build utils)
#:use-module (ice-9 match)
#:use-module (ice-9 regex)
+ #:use-module (ice-9 ftw)
#:use-module (srfi srfi-1)
#:use-module (srfi srfi-26)
#:export (%standard-phases
@@ -41,6 +42,9 @@
(fold (lambda (s p) (or (string-ci=? s directory) p))
#f directories-list))
+;; We do not include $HOME/.guix-profile/gtk-v.0 (v=2 or 3) because we do not
+;; want to mix gtk+-2 and gtk+-3 modules. See
+;; https://developer.gnome.org/gtk3/stable/gtk-running.html
(define (gtk-module-directories inputs)
"Check for the existence of \"libdir/gtk-v.0\" in INPUTS. Return a list
with all found directories."
@@ -64,20 +68,60 @@ with all found directories."
prev)))))
(fold gtk-module '() inputs)))
-(define (schemas-directories inputs)
- "Check for the existence of \"datadir/glib-2.0/schemas\" in INPUTS. Return
-a list with all found directories."
- (define (glib-schemas input previous)
+;; See
+;; http://www.freedesktop.org/wiki/DesktopThemeSpec
+;; http://freedesktop.org/wiki/Specifications/sound-theme-spec
+;; http://freedesktop.org/wiki/Specifications/icon-theme-spec
+;;
+;; Currently desktop themes are not well supported and do not honor
+;; XDG_DATA_DIRS. One example is evince which only looks for desktop themes
+;; in $HOME/.themes (for backward compatibility) and in XDG_DATA_HOME (which
+;; defaults to $HOME/.local/share). One way to handle these applications
+;; appears to be by making $HOME/.themes a symlink to
+;; $HOME/.guix-profile/share/themes.
+(define (data-directories inputs)
+ "Check for the existence of \"$datadir/glib-2.0/schemas\" or XDG themes data
+in INPUTS. Return a list with all found directories."
+ (define (data-directory input previous)
(let* ((in (match input
((_ . dir) dir)
(_ "")))
(datadir (string-append in "/share")))
- (if (and (subdirectory-exists? datadir "/glib-2.0/schemas")
+ (if (and (or (subdirectory-exists? datadir "/glib-2.0/schemas")
+ (subdirectory-exists? datadir "/sounds")
+ (subdirectory-exists? datadir "/themes")
+ (subdirectory-exists? datadir "/cursors")
+ (subdirectory-exists? datadir "/wallpapers")
+ (subdirectory-exists? datadir "/icons"))
(not (directory-included? datadir previous)))
(cons datadir previous)
previous)))
- (fold glib-schemas '() inputs))
+ (fold data-directory '() inputs))
+
+;; All GIO modules are expected to be installed in GLib's $libdir/gio/modules
+;; directory. That directory has to include a file called giomodule.cache
+;; listing all available modules. GIO can be made aware of modules in other
+;; directories with the help of the environment variable GIO_EXTRA_MODULES.
+;; The official GIO documentation states that this environment variable should
+;; only be used for testing and not in a production environment. However, it
+;; appears that there is no other way of specifying multiple modules
+;; directories (NIXOS also does use this variable). See
+;; https://developer.gnome.org/gio/stable/running-gio-apps.html
+(define (gio-module-directories inputs)
+ "Check for the existence of \"$libdir/gio/modules\" in the INPUTS and
+returns a list with all found directories."
+ (define (gio-module-directory input previous)
+ (let* ((in (match input
+ ((_ . dir) dir)
+ (_ "")))
+ (gio-mod-dir (string-append in "/lib/gio/modules")))
+ (if (and (directory-exists? gio-mod-dir)
+ (not (directory-included? gio-mod-dir previous)))
+ (cons gio-mod-dir previous)
+ previous)))
+
+ (fold gio-module-directory '() inputs))
(define* (wrap-all-programs #:key inputs outputs
(glib-or-gtk-wrap-excluded-outputs '())
@@ -96,27 +140,57 @@ add a dependency of that output on GLib and GTK+."
(unless (member output glib-or-gtk-wrap-excluded-outputs)
(let* ((bindir (string-append directory "/bin"))
(bin-list (find-files bindir ".*"))
- (schemas (schemas-directories
+ (datadirs (data-directories
(alist-cons output directory inputs)))
(gtk-mod-dirs (gtk-module-directories
(alist-cons output directory inputs)))
- (schemas-env-var
- (if (not (null? schemas))
- `("XDG_DATA_DIRS" ":" prefix ,schemas)
+ (gio-mod-dirs (gio-module-directories
+ (alist-cons output directory inputs)))
+ (data-env-var
+ (if (not (null? datadirs))
+ `("XDG_DATA_DIRS" ":" prefix ,datadirs)
#f))
(gtk-mod-env-var
(if (not (null? gtk-mod-dirs))
`("GTK_PATH" ":" prefix ,gtk-mod-dirs)
+ #f))
+ (gio-mod-env-var
+ (if (not (null? gio-mod-dirs))
+ `("GIO_EXTRA_MODULES" ":" prefix ,gio-mod-dirs)
#f)))
(cond
- ((and schemas-env-var gtk-mod-env-var)
- (for-each (cut wrap-program <> schemas-env-var gtk-mod-env-var)
+ ((and data-env-var gtk-mod-env-var gio-mod-env-var)
+ (for-each (cut wrap-program <>
+ data-env-var
+ gtk-mod-env-var
+ gio-mod-env-var)
bin-list))
- (schemas-env-var
- (for-each (cut wrap-program <> schemas-env-var)
+ ((and data-env-var gtk-mod-env-var (not gio-mod-env-var))
+ (for-each (cut wrap-program <>
+ data-env-var
+ gtk-mod-env-var)
bin-list))
- (gtk-mod-env-var
- (for-each (cut wrap-program <> gtk-mod-env-var)
+ ((and data-env-var (not gtk-mod-env-var) gio-mod-env-var)
+ (for-each (cut wrap-program <>
+ data-env-var
+ gio-mod-env-var)
+ bin-list))
+ ((and (not data-env-var) gtk-mod-env-var gio-mod-env-var)
+ (for-each (cut wrap-program <>
+ gio-mod-env-var
+ gtk-mod-env-var)
+ bin-list))
+ ((and data-env-var (not gtk-mod-env-var) (not gio-mod-env-var))
+ (for-each (cut wrap-program <>
+ data-env-var)
+ bin-list))
+ ((and (not data-env-var) gtk-mod-env-var (not gio-mod-env-var))
+ (for-each (cut wrap-program <>
+ gtk-mod-env-var)
+ bin-list))
+ ((and (not data-env-var) (not gtk-mod-env-var) gio-mod-env-var)
+ (for-each (cut wrap-program <>
+ gio-mod-env-var)
bin-list))))))))
(for-each handle-output outputs)
@@ -136,12 +210,41 @@ if needed."
#t))))
outputs))
+(define* (generate-icon-cache #:key outputs #:allow-other-keys)
+ "Implement phase \"glib-or-gtk-icon-cache\": generate icon cache if
+needed."
+ (every (match-lambda
+ ((output . directory)
+ (let ((iconsdir (string-append directory
+ "/share/icons")))
+ (when (file-exists? iconsdir)
+ (with-directory-excursion iconsdir
+ (for-each
+ (lambda (dir)
+ (unless (file-exists?
+ (string-append iconsdir "/" dir "/"
+ "icon-theme.cache"))
+ (system* "gtk-update-icon-cache"
+ "--ignore-theme-index"
+ (string-append iconsdir "/" dir))))
+ (scandir "."
+ (lambda (name)
+ (and
+ (not (equal? name "."))
+ (not (equal? name ".."))
+ (equal? 'directory
+ (stat:type (stat name)))))))))
+ #t)))
+ outputs))
+
(define %standard-phases
(alist-cons-after
'install 'glib-or-gtk-wrap wrap-all-programs
(alist-cons-after
- 'install 'glib-or-gtk-compile-schemas compile-glib-schemas
- gnu:%standard-phases)))
+ 'install 'glib-or-gtk-icon-cache generate-icon-cache
+ (alist-cons-after
+ 'install 'glib-or-gtk-compile-schemas compile-glib-schemas
+ gnu:%standard-phases))))
(define* (glib-or-gtk-build #:key inputs (phases %standard-phases)
#:allow-other-keys #:rest args)
diff --git a/guix/derivations.scm b/guix/derivations.scm
index ec438e833c..b48e7e604d 100644
--- a/guix/derivations.scm
+++ b/guix/derivations.scm
@@ -31,6 +31,7 @@
#:use-module (guix hash)
#:use-module (guix base32)
#:use-module (guix records)
+ #:use-module (guix sets)
#:export (<derivation>
derivation?
derivation-outputs
@@ -162,16 +163,18 @@ download with a fixed hash (aka. `fetchurl')."
(define (derivation-prerequisites drv)
"Return the list of derivation-inputs required to build DRV, recursively."
- (let loop ((drv drv)
- (result '()))
- (let ((inputs (remove (cut member <> result) ; XXX: quadratic
+ (let loop ((drv drv)
+ (result '())
+ (input-set (set)))
+ (let ((inputs (remove (cut set-contains? input-set <>)
(derivation-inputs drv))))
- (fold loop
- (append inputs result)
- (map (lambda (i)
- (call-with-input-file (derivation-input-path i)
- read-derivation))
- inputs)))))
+ (fold2 loop
+ (append inputs result)
+ (fold set-insert input-set inputs)
+ (map (lambda (i)
+ (call-with-input-file (derivation-input-path i)
+ read-derivation))
+ inputs)))))
(define (offloadable-derivation? drv)
"Return true if DRV can be offloaded, false otherwise."
@@ -214,8 +217,8 @@ substituter many times."
(append self deps result)))
'()
drv)))
- (subst (substitutable-paths store paths)))
- (cut member <> subst)))
+ (subst (list->set (substitutable-paths store paths))))
+ (cut set-contains? subst <>)))
(define* (derivation-prerequisites-to-build store drv
#:key
diff --git a/guix/gexp.scm b/guix/gexp.scm
index 78e11f5850..d13e1c46da 100644
--- a/guix/gexp.scm
+++ b/guix/gexp.scm
@@ -1,5 +1,5 @@
;;; GNU Guix --- Functional package management for GNU
-;;; Copyright © 2014 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2014, 2015 Ludovic Courtès <ludo@gnu.org>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -33,7 +33,8 @@
gexp?
gexp->derivation
gexp->file
- gexp->script))
+ gexp->script
+ text-file*))
;;; Commentary:
;;;
@@ -522,6 +523,18 @@ its search path."
(write '(ungexp exp) port))))
#:local-build? #t))
+(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 builder
+ (gexp (call-with-output-file (ungexp output "out")
+ (lambda (port)
+ (display (string-append (ungexp-splicing text)) port)))))
+
+ (gexp->derivation name builder))
+
+
;;;
;;; Syntactic sugar.
diff --git a/guix/monads.scm b/guix/monads.scm
index 65683e65de..20fee79602 100644
--- a/guix/monads.scm
+++ b/guix/monads.scm
@@ -1,5 +1,5 @@
;;; GNU Guix --- Functional package management for GNU
-;;; Copyright © 2013, 2014 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2013, 2014, 2015 Ludovic Courtès <ludo@gnu.org>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -57,7 +57,6 @@
store-lift
run-with-store
text-file
- text-file*
interned-file
package-file
origin->derivation
@@ -357,56 +356,6 @@ containing TEXT, a string."
(lambda (store)
(add-text-to-store store name text '())))
-(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))))
-
- ;; TODO: Rewrite using 'gexp->derivation'.
- (mlet %store-monad ((inputs (lower-inputs inputs)))
- (derivation-expression name (builder 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
@@ -440,26 +389,6 @@ cross-compilation target triplet."
(string-append out "/" file)
out))))
-(define (lower-inputs inputs)
- "Turn any package from INPUTS into a derivation; return the corresponding
-input list as a monadic value."
- ;; XXX: This procedure is bound to disappear with 'derivation-expression'.
- (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))))
-
-(define derivation-expression
- ;; XXX: This procedure is superseded by 'gexp->derivation'.
- (store-lift build-expression->derivation))
-
(define package->derivation
(store-lift package-derivation))
diff --git a/guix/sets.scm b/guix/sets.scm
new file mode 100644
index 0000000000..017b79ca31
--- /dev/null
+++ b/guix/sets.scm
@@ -0,0 +1,116 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2015 Ludovic Courtès <ludo@gnu.org>
+;;;
+;;; 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 sets)
+ #:use-module (srfi srfi-1)
+ #:use-module (srfi srfi-9)
+ #:use-module (srfi srfi-26)
+ #:use-module (ice-9 vlist)
+ #:use-module (ice-9 match)
+ #:export (set
+ setq
+ set?
+ set-insert
+ set-union
+ set-contains?
+ set->list
+ list->set
+ list->setq))
+
+;;; Commentary:
+;;;
+;;; A simple (simplistic?) implementation of unordered persistent sets based
+;;; on vhashes that seems to be good enough so far.
+;;;
+;;; Another option would be to use "bounded balance trees" (Adams 1992) as
+;;; implemented by Ian Price in 'pfds', which has faster union etc. but needs
+;;; an order on the objects of the set.
+;;;
+;;; Code:
+
+(define-record-type <set>
+ (%make-set vhash insert ref)
+ set?
+ (vhash set-vhash)
+ (insert set-insert-proc)
+ (ref set-ref))
+
+(define %insert
+ (cut vhash-cons <> #t <>))
+(define %insertq
+ (cut vhash-consq <> #t <>))
+
+(define (set . args)
+ "Return a set containing the ARGS, compared as per 'equal?'."
+ (list->set args))
+
+(define (setq . args)
+ "Return a set containing the ARGS, compared as per 'eq?'."
+ (list->setq args))
+
+(define (list->set lst)
+ "Return a set with the elements taken from LST. Elements of the set will be
+compared with 'equal?'."
+ (%make-set (fold %insert vlist-null lst)
+ %insert
+ vhash-assoc))
+
+(define (list->setq lst)
+ "Return a set with the elements taken from LST. Elements of the set will be
+compared with 'eq?'."
+ (%make-set (fold %insertq vlist-null lst)
+ %insertq
+ vhash-assq))
+
+(define-inlinable (set-contains? set value)
+ "Return #t if VALUE is a member of SET."
+ (->bool ((set-ref set) value (set-vhash set))))
+
+(define (set-insert value set)
+ "Insert VALUE into SET."
+ (if (set-contains? set value)
+ set
+ (let ((vhash ((set-insert-proc set) value (set-vhash set))))
+ (%make-set vhash (set-insert-proc set) (set-ref set)))))
+
+(define-inlinable (set-size set)
+ "Return the number of elements in SET."
+ (vlist-length (set-vhash set)))
+
+(define (set-union set1 set2)
+ "Return the union of SET1 and SET2. Warning: this is linear in the number
+of elements of the smallest."
+ (unless (eq? (set-insert-proc set1) (set-insert-proc set2))
+ (error "set-union: incompatible sets"))
+
+ (let* ((small (if (> (set-size set1) (set-size set2))
+ set2 set1))
+ (large (if (eq? small set1) set2 set1)))
+ (vlist-fold (match-lambda*
+ (((item . _) result)
+ (set-insert item result)))
+ large
+ (set-vhash small))))
+
+(define (set->list set)
+ "Return the list of elements of SET."
+ (map (match-lambda
+ ((key . _) key))
+ (vlist->list (set-vhash set))))
+
+;;; sets.scm ends here