Skip to content

Commit e06fbfd

Browse files
authored
Merge pull request #181 from nagy/master
Introduce `nix-store-path-omit-self`
2 parents c18a24e + c3ffcaf commit e06fbfd

File tree

4 files changed

+68
-57
lines changed

4 files changed

+68
-57
lines changed

CHANGELOG.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
# Changelog
22

3+
## Unreleased (1.6.0)
4+
5+
* Introduce nix-store-path-omit-self customization option.
6+
37
## 1.5.0
48

59
* Removed json-mode dependency, using js instead.
610
* Compatibility with Emacs 28+.
7-
* Add nix-flake commands, based on magit-session.
11+
* Add nix-flake commands, based on magit-section.
812
* Add nix-store-show-log command.
913
* Other various fixes.
1014

nix-drv-mode.el

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
;;; nix-drv-mode.el --- Major mode for viewing .drv files
1+
;;; nix-drv-mode.el --- Major mode for viewing .drv files -*- lexical-binding: t -*-
22

33
;; Maintainer: Matthew Bauer <[email protected]>
44
;; Homepage: https://github.com/NixOS/nix-mode

nix-prettify-mode.el

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ enabling/disabling `nix-prettify-mode'. If nil, do nothing.")
125125
"Toggle Nix Prettify mode.
126126
127127
With a prefix argument ARG, enable Nix Prettify mode if ARG is
128-
positive, and disable it otherwise. If called from Lisp, enable
128+
positive, and disable it otherwise. If called from Lisp, enable
129129
the mode if ARG is omitted or nil.
130130
131131
When Nix Prettify mode is enabled, hash-parts of the Nix store

nix-store.el

+61-54
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,31 @@
2121
"Nix-store customizations."
2222
:group 'nix)
2323

24+
(defcustom nix-store-path-omit-self t
25+
"Do not list the current entry itself within sections of nix-store-path-mode."
26+
:package-version '(nix-mode . "1.6.0"))
27+
2428
(defun nix-store-realise (path)
2529
"Realise a path asynchronously.
2630
PATH the path within /nix/store to realise"
2731
(make-process
28-
:buffer nil
29-
:command (list nix-store-executable "--realise" path)
30-
:noquery t
31-
:name (format "*nix-store*<%s>" path)))
32+
:buffer nil
33+
:command (list nix-store-executable "--realise" path)
34+
:noquery t
35+
:name (format "*nix-store*<%s>" path)))
3236

3337
(defvar-local nix-buffer-store-path nil "Buffer-local object holding an `nix-store-path` object.")
3438

3539
(defclass nix-store-path ()
36-
((path :initarg :path :accessor nix-store-path-path)
37-
(status :initarg :status :accessor nix-store-path-status)
38-
(hash :initarg :hash :accessor nix-store-path-hash)
39-
(size :initarg :size :accessor nix-store-path-size)
40-
(derivers :initarg :derivers :accessor nix-store-path-derivers)
41-
(outputs :initarg :outputs :accessor nix-store-path-outputs)
42-
(references :initarg :references :accessor nix-store-path-references)
43-
(referrers :initarg :referrers :accessor nix-store-path-referrers)
44-
(requisites :initarg :requisites :accessor nix-store-path-requisites))
40+
((path :initarg :path :accessor nix-store-path-path)
41+
(status :initarg :status :accessor nix-store-path-status)
42+
(hash :initarg :hash :accessor nix-store-path-hash)
43+
(size :initarg :size :accessor nix-store-path-size)
44+
(derivers :initarg :derivers :accessor nix-store-path-derivers)
45+
(outputs :initarg :outputs :accessor nix-store-path-outputs)
46+
(references :initarg :references :accessor nix-store-path-references)
47+
(referrers :initarg :referrers :accessor nix-store-path-referrers)
48+
(requisites :initarg :requisites :accessor nix-store-path-requisites))
4549
"Nix-Store-Path Class holds all information of the path that
4650
is displayed")
4751

@@ -65,30 +69,30 @@ being queried. Runs `nix-store-executable' to get that
6569
information."
6670
(let ((nix-executable nix-store-executable))
6771
(cond
68-
((eq 'deriver argument)
69-
;; Special treatment for 'derivers', we want to treat a single entry
70-
;; with this string as an empty list
71-
(remove "unknown-deriver"
72-
(nix--process-lines "--query" "--deriver" path )))
73-
((eq 'size argument) (string-to-number (nix--process-string "--query" "--size" path )))
74-
((eq 'hash argument) (nix--process-string "--query" "--hash" path ))
75-
((eq 'requisites argument) (nix--process-lines "--query" "--requisites" path ))
76-
((eq 'references argument) (nix--process-lines "--query" "--references" path ))
77-
((eq 'referrers argument) (nix--process-lines "--query" "--referrers" path ))
78-
((eq 'outputs argument)
79-
(ignore-errors
80-
;; This can fail for non-derivation paths
81-
(nix--process-lines "--query" "--outputs" path )))
82-
(t (error "Unknown argument to nix-store --query: %s" argument)))))
72+
((eq 'deriver argument)
73+
;; Special treatment for 'derivers', we want to treat a single entry
74+
;; with this string as an empty list
75+
(remove "unknown-deriver"
76+
(nix--process-lines "--query" "--deriver" path )))
77+
((eq 'size argument) (string-to-number (nix--process-string "--query" "--size" path )))
78+
((eq 'hash argument) (nix--process-string "--query" "--hash" path ))
79+
((eq 'requisites argument) (nix--process-lines "--query" "--requisites" path ))
80+
((eq 'references argument) (nix--process-lines "--query" "--references" path ))
81+
((eq 'referrers argument) (nix--process-lines "--query" "--referrers" path ))
82+
((eq 'outputs argument)
83+
(ignore-errors
84+
;; This can fail for non-derivation paths
85+
(nix--process-lines "--query" "--outputs" path )))
86+
(t (error "Unknown argument to nix-store --query: %s" argument)))))
8387

8488
(cl-defun nix-store-path-insert-path (&optional (store-path nix-buffer-store-path))
8589
"Insert a section showing the path of STORE-PATH."
8690
(magit-insert-section (path (nix-store-path-path store-path))
8791
(magit-insert-heading (propertize (format "%-11s" "Path:") 'face 'magit-section-heading)
8892
(propertize (oref store-path path)
89-
'face (if (file-exists-p (nix-store-path-path store-path))
90-
'nix-store-path-realised-face
91-
'nix-store-path-unrealised-face) ))))
93+
'face (if (file-exists-p (nix-store-path-path store-path))
94+
'nix-store-path-realised-face
95+
'nix-store-path-unrealised-face) ))))
9296

9397
(cl-defun nix-store-path-insert-size (&optional (store-path nix-buffer-store-path))
9498
"Insert a section showing the size of STORE-PATH."
@@ -112,17 +116,18 @@ information."
112116
"Helper macro for inserting a list as a magit-section.
113117
TYPE and VALUE will be used as the type and value of the section
114118
respectively. The LABEL is the text displayed."
115-
`(let ((value ,value))
119+
`(let ((value (cl-remove
120+
(and nix-store-path-omit-self (nix-store-path-path nix-buffer-store-path))
121+
,value :test #'equal)))
116122
(when (and (listp value) (> (length value) 0))
117123
(magit-insert-section (,type value)
118124
(magit-insert-heading ,label)
119125
(cl-loop for x in value
120-
for exists = (file-exists-p x)
121-
do
122-
(magit-insert-section (store-path x)
123-
(insert
124-
(propertize x 'face (if exists 'nix-store-path-realised-face 'nix-store-path-unrealised-face))
125-
?\n)))
126+
for exists = (file-exists-p x)
127+
for face = (if exists 'nix-store-path-realised-face 'nix-store-path-unrealised-face)
128+
do
129+
(magit-insert-section (store-path x)
130+
(insert (propertize x 'face face) ?\n)))
126131
(insert ?\n)
127132
(magit-insert-child-count (magit-current-section))))))
128133

@@ -148,28 +153,30 @@ respectively. The LABEL is the text displayed."
148153

149154
(defcustom nix-store-path-headers-hook
150155
'(nix-store-path-insert-path
151-
nix-store-path-insert-status
152-
nix-store-path-insert-hash
153-
nix-store-path-insert-size)
156+
nix-store-path-insert-status
157+
nix-store-path-insert-hash
158+
nix-store-path-insert-size)
154159
"Hook run to insert headers into the nix-store buffer.
155160
A list of function that each take one argument, the store path object."
156161
:group 'nix-store
157162
:type 'hook
163+
:package-version '(nix-mode . "1.5.0")
158164
:options '(nix-store-path-insert-path
159-
nix-store-path-insert-status
160-
nix-store-path-insert-hash
161-
nix-store-path-insert-size))
165+
nix-store-path-insert-status
166+
nix-store-path-insert-hash
167+
nix-store-path-insert-size))
162168

163169
(defcustom nix-store-path-sections-hook
164170
'(nix-store-path-insert-derivers
165-
nix-store-path-insert-outputs
166-
nix-store-path-insert-references
167-
nix-store-path-insert-referrers
168-
nix-store-path-insert-requisites)
171+
nix-store-path-insert-outputs
172+
nix-store-path-insert-references
173+
nix-store-path-insert-referrers
174+
nix-store-path-insert-requisites)
169175
"Hook run to insert sections into a nix-store buffer.
170176
A list of function that each take one argument, the store path object."
171177
:group 'nix-store
172-
:type 'hook)
178+
:type 'hook
179+
:package-version '(nix-mode . "1.5.0"))
173180

174181
(defun nix-store-show-path (path)
175182
"Show a nix-store PATH.
@@ -183,7 +190,7 @@ implement your own ones) you can customize the variable
183190
(switch-to-buffer (format "Nix Store Path: %s" path))
184191
(nix-store-path-mode)
185192
(setq nix-buffer-store-path (nix-store-fill-data (make-instance 'nix-store-path :path path))
186-
list-buffers-directory path)
193+
list-buffers-directory path)
187194
(when (file-directory-p path)
188195
(setq default-directory path))
189196
(let ((inhibit-read-only t))
@@ -208,10 +215,9 @@ It uses \\[nix-store-show-path] to display the store path."
208215
(defun nix-store-show-log ()
209216
"Opens the log file for the derivation of the nix-store path."
210217
(interactive)
211-
(let ((drv-path (car (nix-store-path-derivers nix-buffer-store-path))))
212-
(if (not drv-path)
213-
(message "This store path has no associated derivation.")
214-
(find-file (nix-log-path drv-path)))))
218+
(if-let ((drv-path (car (nix-store-path-derivers nix-buffer-store-path))))
219+
(find-file (nix-log-path drv-path))
220+
(user-error "This store path has no associated derivation.")))
215221

216222
(defvar nix-store-path-mode-map
217223
(let ((map (make-sparse-keymap)))
@@ -224,6 +230,7 @@ It uses \\[nix-store-show-path] to display the store path."
224230
(nix-store-show-path (nix-store-path-path nix-buffer-store-path)))
225231

226232
(define-derived-mode nix-store-path-mode magit-section-mode "Nix Store Path"
233+
:group 'nix-store
227234
(setq-local revert-buffer-function #'nix-store--revert-buffer-function)
228235
(read-only-mode 1))
229236

0 commit comments

Comments
 (0)