[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/nix-mode 8e20de5ba7 462/500: Merge pull request #134 from
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/nix-mode 8e20de5ba7 462/500: Merge pull request #134 from nagy/store-path |
Date: |
Sat, 29 Jan 2022 08:27:56 -0500 (EST) |
branch: elpa/nix-mode
commit 8e20de5ba7061d810b08df5557b1fdb60c94b639
Merge: 327175e768 b1257d3ea6
Author: Matthew Bauer <mjbauer95@gmail.com>
Commit: GitHub <noreply@github.com>
Merge pull request #134 from nagy/store-path
Introduce `nix-store-show-path` command
---
README.md | 10 ++++
flake.nix | 1 +
nix-mode.el | 2 +-
nix-store.el | 193 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
nix.el | 5 ++
5 files changed, 206 insertions(+), 5 deletions(-)
diff --git a/README.md b/README.md
index 7f3bd74a7a..94935dc12d 100644
--- a/README.md
+++ b/README.md
@@ -72,6 +72,16 @@ open this with:
M-x nix-repl<RET>
+### nix-store.el
+
+This file provides a command `M-x nix-store-show-path`. The command displays an
+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
+documentation of the function `nix-store-show-path` for more information.
+
### nix-prettify-mode.el
When nix-prettify-mode is enabled, hash-parts of the Nix store file names are
diff --git a/flake.nix b/flake.nix
index b09a2e1413..638ebaebf7 100644
--- a/flake.nix
+++ b/flake.nix
@@ -14,6 +14,7 @@
company
mmm-mode
f
+ magit-section
]);
in stdenvNoCC.mkDerivation {
pname = "nix-mode";
diff --git a/nix-mode.el b/nix-mode.el
index 1d79abea5d..31993f386c 100644
--- a/nix-mode.el
+++ b/nix-mode.el
@@ -4,7 +4,7 @@
;; Homepage: https://github.com/NixOS/nix-mode
;; Version: 1.4.4
;; Keywords: nix, languages, tools, unix
-;; Package-Requires: ((emacs "25.1"))
+;; Package-Requires: ((emacs "25.1") magit-section)
;; This file is NOT part of GNU Emacs.
diff --git a/nix-store.el b/nix-store.el
index b5bf922334..3e772d799e 100644
--- a/nix-store.el
+++ b/nix-store.el
@@ -11,16 +11,201 @@
;;; Code:
+(require 'eieio)
(require 'nix)
+(require 'magit-section)
+(require 'cl-lib)
+
+(defgroup nix-store nil
+ "Nix-store customizations."
+ :group 'nix)
(defun nix-store-realise (path)
"Realise a path asynchronously.
PATH the path within /nix/store to realise"
(make-process
- :buffer nil
- :command (list nix-store-executable "--realise" path)
- :noquery t
- :name (format "*nix-store*<%s>" path)))
+ :buffer nil
+ :command (list nix-store-executable "--realise" path)
+ :noquery t
+ :name (format "*nix-store*<%s>" path)))
+
+(defvar-local nix-buffer-store-path nil "Buffer-local object holding an
`nix-store-path` object.")
+
+(defclass nix-store-path ()
+ ((path :initarg :path :accessor
nix-store-path-path)
+ (status :initarg :status :initform 'realised :accessor
nix-store-path-status)
+ (hash :initarg :hash :accessor
nix-store-path-hash)
+ (size :initarg :size :accessor
nix-store-path-size)
+ (derivers :initarg :derivers :accessor
nix-store-path-derivers)
+ (outputs :initarg :outputs :accessor
nix-store-path-outputs)
+ (references :initarg :references :accessor
nix-store-path-references)
+ (referrers :initarg :referrers :accessor
nix-store-path-referrers)
+ (requisites :initarg :requisites :accessor
nix-store-path-requisites))
+ "Nix-Store-Path Class holds all information of the path that
+is displayed")
+
+(cl-defmethod nix-store-fill-data ((object nix-store-path))
+ "Query the nix store store via `nix-store-executable' and save that data
into OBJECT."
+ (oset object :size (nix-store--query 'size (nix-store-path-path object)))
+ (oset object :hash (nix-store--query 'hash (nix-store-path-path object)))
+ (oset object :derivers (nix-store--query 'deriver (nix-store-path-path
object)))
+ (oset object :outputs (nix-store--query 'outputs (nix-store-path-path
object)))
+ (oset object :referrers (nix-store--query 'referrers (nix-store-path-path
object)))
+ (oset object :requisites (nix-store--query 'requisites (nix-store-path-path
object)))
+ (oset object :references (nix-store--query 'references (nix-store-path-path
object)))
+ object)
+
+(cl-defun nix-store--query (argument &optional (path (nix-store-path-path
nix-buffer-store-path)))
+ "Query the nix-store for information.
+ARGUMENT is given to the executable as an argument. See
+nix-store(1) for possibilities. PATH is the store object that is
+being queried. Runs `nix-store-executable' to get that
+information."
+ (let ((nix-executable nix-store-executable))
+ (cond
+ ((eq 'deriver argument)
+ ;; Special treatment for 'derivers', we want to treat a single entry
+ ;; with this string as an empty list
+ (remove "unknown-deriver"
+ (nix--process-lines "--query" "--deriver" path )))
+ ((eq 'size argument) (string-to-number (nix--process-string "--query"
"--size" path )))
+ ((eq 'hash argument) (nix--process-string "--query" "--hash" path ))
+ ((eq 'requisites argument) (nix--process-lines "--query" "--requisites"
path ))
+ ((eq 'references argument) (nix--process-lines "--query" "--references"
path ))
+ ((eq 'referrers argument) (nix--process-lines "--query" "--referrers"
path ))
+ ((eq 'outputs argument)
+ (ignore-errors
+ ;; This can fail for non-derivation paths
+ (nix--process-lines "--query" "--outputs" path )))
+ (t (error "Unknown argument to nix-store --query: %s" argument)))))
+
+(cl-defun nix-store-path-insert-path (&optional (store-path
nix-buffer-store-path))
+ "Insert a section showing the path of STORE-PATH."
+ (magit-insert-section (path (nix-store-path-path store-path))
+ (magit-insert-heading (propertize (format "%-11s" "Path:") 'face
'magit-section-heading)
+ (format "%s" (oref store-path path)))))
+
+(cl-defun nix-store-path-insert-size (&optional (store-path
nix-buffer-store-path))
+ "Insert a section showing the size of STORE-PATH."
+ (magit-insert-section (size (nix-store-path-size store-path))
+ (magit-insert-heading (propertize (format "%-11s" "Size:") 'face
'magit-section-heading)
+ (format "%s" (oref store-path size)))))
+
+(cl-defun nix-store-path-insert-hash (&optional (store-path
nix-buffer-store-path))
+ "Insert a section showing the hash of STORE-PATH."
+ (magit-insert-section (hash (nix-store-path-hash store-path))
+ (magit-insert-heading (propertize (format "%-11s" "Hash:") 'face
'magit-section-heading)
+ (format "%s" (oref store-path hash)))))
+
+(cl-defun nix-store-path-insert-status (&optional (store-path
nix-buffer-store-path))
+ "Insert a section showing the status of STORE-PATH."
+ (magit-insert-section (status (nix-store-path-status store-path))
+ (magit-insert-heading (propertize (format "%-11s" "Status:") 'face
'magit-section-heading)
+ (format "%s" (oref store-path status)))))
+
+(defmacro nix-store--magit-insert-section-list (type value label)
+ "Helper macro for inserting a list as a magit-section.
+TYPE and VALUE will be used as the type and value of the section
+respectively. The LABEL is the text displayed."
+ `(let ((value ,value))
+ (when (and (listp value) (> (length value) 0))
+ (magit-insert-section (,type value)
+ (magit-insert-heading ,label)
+ (cl-loop for x in value do (magit-insert-section (store-path x)
(insert x) (newline)))
+ (insert ?\n)
+ (magit-insert-child-count (magit-current-section))))))
+
+(cl-defun nix-store-path-insert-derivers (&optional (store-path
nix-buffer-store-path))
+ "Insert sections showing all derivers of STORE-PATH."
+ (nix-store--magit-insert-section-list derivers (nix-store-path-derivers
store-path) "Derivers:"))
+
+(cl-defun nix-store-path-insert-outputs (&optional (store-path
nix-buffer-store-path))
+ "Insert sections showing all outputs of STORE-PATH."
+ (nix-store--magit-insert-section-list outputs (nix-store-path-outputs
store-path) "Outputs:"))
+
+(cl-defun nix-store-path-insert-references (&optional (store-path
nix-buffer-store-path))
+ "Insert sections showing all references of STORE-PATH."
+ (nix-store--magit-insert-section-list references (nix-store-path-references
store-path) "References:"))
+
+(cl-defun nix-store-path-insert-referrers (&optional (store-path
nix-buffer-store-path))
+ "Insert sections showing all referrers of STORE-PATH."
+ (nix-store--magit-insert-section-list referrers (nix-store-path-referrers
store-path) "Referrers:"))
+
+(cl-defun nix-store-path-insert-requisites (&optional (store-path
nix-buffer-store-path))
+ "Insert sections showing all requisites of STORE-PATH."
+ (nix-store--magit-insert-section-list requisites (nix-store-path-requisites
store-path) "Requisites:"))
+
+(defcustom nix-store-path-headers-hook
+ '(nix-store-path-insert-path
+ nix-store-path-insert-status
+ nix-store-path-insert-hash
+ nix-store-path-insert-size)
+ "Hook run to insert headers into the nix-store buffer.
+A list of function that each take one argument, the store path object."
+ :group 'nix-store
+ :type 'hook
+ :options '(nix-store-path-insert-path
+ nix-store-path-insert-status
+ nix-store-path-insert-hash
+ nix-store-path-insert-size))
+
+(defcustom nix-store-path-sections-hook
+ '(nix-store-path-insert-derivers
+ nix-store-path-insert-outputs
+ nix-store-path-insert-references
+ nix-store-path-insert-referrers
+ nix-store-path-insert-requisites)
+ "Hook run to insert sections into a nix-store buffer.
+A list of function that each take one argument, the store path object."
+ :group 'nix-store
+ :type 'hook)
+
+(defun nix-store-show-path (path)
+ "Show a nix-store PATH.
+
+If you want to change the order of the section lists (or even
+implement your own ones) you can customize the variable
+`nix-store-path-headers-hook' and
+`nix-store-path-sections-hook'."
+ (interactive "FNix-Store-Path: ")
+ (setq path (expand-file-name path default-directory))
+ (switch-to-buffer (format "Nix Store Path: %s" path))
+ (nix-store-path-mode)
+ (setq nix-buffer-store-path (nix-store-fill-data (make-instance
'nix-store-path :path path))
+ list-buffers-directory path)
+ (when (file-directory-p path)
+ (setq default-directory path))
+ (let ((inhibit-read-only t))
+ (erase-buffer)
+ (magit-insert-section (store-path)
+ (magit-insert-headers 'nix-store-path-headers-hook)
+ (magit-run-section-hook 'nix-store-path-sections-hook))
+ (setf (point) (point-min))))
+
+(defun nix-store-path-at-point ()
+ "Return the nix-store path at point."
+ ;; TODO extract this via magit-section values
+ (substring-no-properties (thing-at-point 'filename)))
+
+(defun nix-store-show-path-at-point ()
+ "Opens the nix-store-path at point.
+
+It uses \\[nix-store-show-path] to display the store path."
+ (interactive)
+ (nix-store-show-path (nix-store-path-at-point)))
+
+(defvar nix-store-path-mode-map
+ (let ((map (make-sparse-keymap)))
+ (define-key map (kbd "RET") 'nix-store-show-path-at-point)
+ map))
+
+(defun nix-store--revert-buffer-function (&rest _ignore)
+ "Helper function to be called by `revert-buffer'."
+ (nix-store-show-path (nix-store-path-path nix-buffer-store-path)))
+
+(define-derived-mode nix-store-path-mode magit-section-mode "Nix Store Path"
+ (setq-local revert-buffer-function #'nix-store--revert-buffer-function)
+ (read-only-mode 1))
(provide 'nix-store)
;;; nix-store.el ends here
diff --git a/nix.el b/nix.el
index 59e6e4c2e7..bf5887b27e 100644
--- a/nix.el
+++ b/nix.el
@@ -347,6 +347,11 @@ OPTIONS a list of options to accept."
(json-read-from-string
(apply #'nix--process-string args)))
+(defun nix--process-lines (&rest args)
+ (seq-filter (lambda (el) (not (string= "" el)))
+ (split-string
+ (apply #'nix--process-string args) "\n")))
+
(defun nix--process-json-nocheck (&rest args)
;; No checking of exitcode is possible here until
;; https://github.com/NixOS/nix/issues/2474 is resolved
- [nongnu] elpa/nix-mode 6573b1d70e 145/500: Add nix-shell.el, (continued)
- [nongnu] elpa/nix-mode 6573b1d70e 145/500: Add nix-shell.el, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 0af6073003 171/500: Add nix-mode to nix-mode group., ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode af686b570c 159/500: Fix package-lint complaints., ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 3fa526ee57 165/500: Add MELPA badges to READM.md, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 420cbbf94c 215/500: Reorganization, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 1090226479 224/500: nix-repl-show -> nix-repl, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 588246b499 229/500: Fix escaping of characters, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode a5bf79a563 425/500: Merge pull request #120 from znewman01/master, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 7593b023a7 405/500: Merge pull request #110 from leungbk/repl-history, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 1fdf8e654a 444/500: Merge pull request #132 from league/master, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 8e20de5ba7 462/500: Merge pull request #134 from nagy/store-path,
ELPA Syncer <=
- [nongnu] elpa/nix-mode 01e37b6761 464/500: Merge pull request #139 from akirak/fix/nix-24-for-25, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 8a05b88eb3 448/500: Fix a typo, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 207e5c0a92 455/500: nix-format.el: Add nix-format-before-save, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 86b7195b3e 010/500: Use warning font lock for upper case vars, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode c81c03b35e 403/500: nix-repl: use history file, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode c19e103eee 430/500: Add support nix 2.4 flakes in search, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 5fa017c6ad 393/500: Merge pull request #105 from rossabaker/completions, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 0380e03203 406/500: Merge pull request #109 from yilinwei/master, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode aef98227cc 419/500: Merge branch 'master' into derived-nix-drv-mode, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode ffcab906b8 407/500: Makefile: add nix-mode project directory to 'load-path' in 'run' target, ELPA Syncer, 2022/01/29