about summary refs log tree commit diff
path: root/configs/shared/emacs/.emacs.d/elpa/nix-mode-20180908.2240/nix-log.el
blob: 192ab3170e87717fbcb10c9790f103f87831ca6d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
;;; nix-log.el -- run nix commands in Emacs -*- lexical-binding: t -*-

;; Author: Matthew Bauer <mjbauer95@gmail.com>
;; Homepage: https://github.com/NixOS/nix-mode
;; Keywords: nix

;; This file is NOT part of GNU Emacs.

;;; Commentary:

;;; Code:

(require 'nix)
(require 'nix-search)
(require 'nix-instantiate)

(defun nix-log (file attr)
  "Open the nix log.
FILE nix file to parse.
ATTR attribute to load the log of."
  (interactive (list (nix-read-file) nil))
  (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"))))

(provide 'nix-log)
;;; nix-log.el ends here