aboutsummaryrefslogtreecommitdiff
path: root/guix/store.scm
diff options
context:
space:
mode:
Diffstat (limited to 'guix/store.scm')
-rw-r--r--guix/store.scm32
1 files changed, 31 insertions, 1 deletions
diff --git a/guix/store.scm b/guix/store.scm
index 0f1e2f9466..2821cacdcc 100644
--- a/guix/store.scm
+++ b/guix/store.scm
@@ -85,9 +85,11 @@
%store-prefix
store-path?
+ direct-store-path?
derivation-path?
store-path-package-name
- store-path-hash-part))
+ store-path-hash-part
+ log-file))
(define %protocol-version #x10c)
@@ -639,6 +641,14 @@ collected, and the number of bytes freed."
;; `isStorePath' in Nix does something similar.
(string-prefix? (%store-prefix) path))
+(define (direct-store-path? path)
+ "Return #t if PATH is a store path, and not a sub-directory of a store path.
+This predicate is sometimes needed because files *under* a store path are not
+valid inputs."
+ (and (store-path? path)
+ (let ((len (+ 1 (string-length (%store-prefix)))))
+ (not (string-index (substring path len) #\/)))))
+
(define (derivation-path? path)
"Return #t if PATH is a derivation path."
(and (store-path? path) (string-suffix? ".drv" path)))
@@ -660,3 +670,23 @@ syntactically valid store path."
"/([0-9a-df-np-sv-z]{32})-[^/]+$"))))
(and=> (regexp-exec path-rx path)
(cut match:substring <> 1))))
+
+(define (log-file store file)
+ "Return the build log file for FILE, or #f if none could be found. FILE
+must be an absolute store file name, or a derivation file name."
+ (define state-dir ; XXX: factorize
+ (or (getenv "NIX_STATE_DIR") %state-directory))
+
+ (cond ((derivation-path? file)
+ (let* ((base (basename file))
+ (log (string-append (dirname state-dir) ; XXX: ditto
+ "/log/nix/drvs/"
+ (string-take base 2) "/"
+ (string-drop base 2) ".bz2")))
+ (and (file-exists? log) log)))
+ (else
+ (match (valid-derivers store file)
+ ((derivers ...)
+ ;; Return the first that works.
+ (any (cut log-file store <>) derivers))
+ (_ #f)))))