environ.scm 2.5 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
;;; Guix-kernel -- Guix kernel for Jupyter
;;; Copyright (C) 2018  Pierre-Antoine Rouby <pierre-antoine.rouby@inria.fr>
;;;
;;; This program 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.
;;;
;;; This program 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 this program.  If not, see <https://www.gnu.org/licenses/>.

17
18
19
20
21
22
23
24
25
26
(define-module (guix-kernel environ)
  #:use-module (gnu packages)
  #:use-module (guix licenses)
  #:use-module (guix packages)
  #:use-module (guix records)
  #:use-module (guix store)
  #:use-module (guix utils)
  #:use-module (guix monads)
  #:use-module (guix derivations)
  #:use-module (guix build utils)
27
  #:use-module (srfi srfi-1)
28
  #:use-module (srfi srfi-11)
29
  #:use-module (srfi srfi-26)
30
31
  #:export (guile->path
            guile-current-version->path
32
33
            guile-current-load-path->args-list
            guile-current-load-compiled-path->args-list
34

35
36
37
            package-name->path))

(define (store) (open-connection))
38

39
40
41
42
43
44
(define (m-package-by-name->package-path name)
  (mlet %store-monad ((drv (package->derivation
                            (specification->package name))))
    (mbegin %store-monad
      (built-derivations (list drv))
      (return (derivation->output-path drv)))))
45

46
47
(define (guile->path guile)
  "Return path to guile executable file. GUILE is package specification."
48
  (string-append
49
   (run-with-store (store) (m-package-by-name->package-path guile))
50
51
   "/bin/guile"))

52
53
54
55
(define (guile-current-version->path)
  "Return path to current guile executable file."
  (guile->path (string-append "guile" "@" (version))))

56
57
58
59
60
61
62
63
64
65
(define (guile-current-load-path->args-list)
  "Return list of load path with '-L' prefix for each path."
  (append-map (cut list "-L" <>)
              %load-path))

(define (guile-current-load-compiled-path->args-list)
  "Return list of load compiled path with '-C' prefix for each path."
  (append-map (cut list "-C" <>)
              %load-compiled-path))

66
67
(define (package-name->path name)
  "Return store path for package coresponding to NAME."
68
  (run-with-store (store) (m-package-by-name->package-path name)))