branch: elpa/nix-mode commit 634a1ffcaa3a9e2834cbe8f0d672d301ac3046b4 Merge: 2915a0f4c7 1f93977c25 Author: Matthew Bauer <mjbaue...@gmail.com> Commit: GitHub <nore...@github.com>
Merge pull request #170 from zainab-ali/nix-store-show-log Add `nix-store-show-log` to open a log file from nix-store-path mode. --- README.md | 5 ++++- nix-log.el | 21 ++++++++++++--------- nix-store.el | 10 ++++++++++ 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index f3c2bd2ddd..3ef5662ced 100644 --- a/README.md +++ b/README.md @@ -93,9 +93,12 @@ overview of a store path. The information it shows is the realisation status, the hash and the size of the store path. Also it shows lists of derivers, references, referrers and requisites of the respective path. -You can change the order in which that information is show. See the +You can change the order in which that information is shown. See the documentation of the function `nix-store-show-path` for more information. +When viewing a store buffer, the command `M-x nix-store-show-log` +opens a local log file associated with a derivation. + ### nix-prettify-mode.el When nix-prettify-mode is enabled, hash-parts of the Nix store file names are diff --git a/nix-log.el b/nix-log.el index 730cd6de3a..92d76c3869 100644 --- a/nix-log.el +++ b/nix-log.el @@ -16,6 +16,16 @@ (require 'nix) (require 'nix-search) (require 'nix-instantiate) +(require 'files) + +(defun nix-log-path (drv-file) + "Get the nix log of path a derivation" + (let* ((drv-name (file-relative-name drv-file nix-store-dir)) + (log-file (format "%s/log/nix/drvs/%s/%s.bz2" + nix-state-dir + (substring drv-name 0 2) (substring drv-name 2)))) + (if (file-exists-p log-file) log-file + (error "No log is available for derivation")))) ;;;###autoload (defun nix-log (file attr) @@ -26,15 +36,8 @@ ATTR attribute to load the log of." (unless attr (setq attr (nix-read-attr file))) (let* ((drv-file (nix-instantiate file attr)) - (drv-name (progn - (string-match (format "^%s/\\(.*\\)$" nix-store-dir) drv-file) - (match-string 1 drv-file))) - (log-file (format "%s/log/nix/drvs/%s/%s.bz2" - nix-state-dir - (substring drv-name 0 2) drv-name))) - (if (file-exists-p log-file) - (find-file log-file) - (error "No log is available for derivation")))) + (log-file (nix-log-path drv-file))) + (find-file log-file))) (provide 'nix-log) ;;; nix-log.el ends here diff --git a/nix-store.el b/nix-store.el index d633031393..e3e872edeb 100644 --- a/nix-store.el +++ b/nix-store.el @@ -14,6 +14,7 @@ (require 'eieio) (require 'nix) +(require 'nix-log) (require 'magit-section) (eval-when-compile (require 'cl-lib)) @@ -206,9 +207,18 @@ It uses \\[nix-store-show-path] to display the store path." (interactive) (nix-store-show-path (nix-store-path-at-point))) +(defun nix-store-show-log () + "Opens the log file for the derivation of the nix-store path." + (interactive) + (let ((drv-path (car (nix-store-path-derivers nix-buffer-store-path)))) + (if (not drv-path) + (message "This store path has no associated derivation.") + (find-file (nix-log-path drv-path))))) + (defvar nix-store-path-mode-map (let ((map (make-sparse-keymap))) (define-key map (kbd "RET") 'nix-store-show-path-at-point) + (define-key map (kbd "l") 'nix-store-show-log) map)) (defun nix-store--revert-buffer-function (&rest _ignore)