21
21
" Nix-store customizations."
22
22
:group 'nix )
23
23
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
+
24
28
(defun nix-store-realise (path )
25
29
" Realise a path asynchronously.
26
30
PATH the path within /nix/store to realise"
27
31
(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)))
32
36
33
37
(defvar-local nix-buffer-store-path nil " Buffer-local object holding an `nix-store-path` object." )
34
38
35
39
(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))
45
49
" Nix-Store-Path Class holds all information of the path that
46
50
is displayed" )
47
51
@@ -65,30 +69,30 @@ being queried. Runs `nix-store-executable' to get that
65
69
information."
66
70
(let ((nix-executable nix-store-executable))
67
71
(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)))))
83
87
84
88
(cl-defun nix-store-path-insert-path (&optional (store-path nix-buffer-store-path))
85
89
" Insert a section showing the path of STORE-PATH."
86
90
(magit-insert-section (path (nix-store-path-path store-path))
87
91
(magit-insert-heading (propertize (format " %- 11s" " Path:" ) 'face 'magit-section-heading )
88
92
(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 ) ))))
92
96
93
97
(cl-defun nix-store-path-insert-size (&optional (store-path nix-buffer-store-path))
94
98
" Insert a section showing the size of STORE-PATH."
@@ -112,17 +116,18 @@ information."
112
116
" Helper macro for inserting a list as a magit-section.
113
117
TYPE and VALUE will be used as the type and value of the section
114
118
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 )))
116
122
(when (and (listp value) (> (length value) 0 ))
117
123
(magit-insert-section (, type value)
118
124
(magit-insert-heading , label )
119
125
(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 )))
126
131
(insert ?\n )
127
132
(magit-insert-child-count (magit-current-section))))))
128
133
@@ -148,28 +153,30 @@ respectively. The LABEL is the text displayed."
148
153
149
154
(defcustom nix-store-path-headers-hook
150
155
'(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)
154
159
" Hook run to insert headers into the nix-store buffer.
155
160
A list of function that each take one argument, the store path object."
156
161
:group 'nix-store
157
162
:type 'hook
163
+ :package-version '(nix-mode . " 1.5.0" )
158
164
: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))
162
168
163
169
(defcustom nix-store-path-sections-hook
164
170
'(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)
169
175
" Hook run to insert sections into a nix-store buffer.
170
176
A list of function that each take one argument, the store path object."
171
177
:group 'nix-store
172
- :type 'hook )
178
+ :type 'hook
179
+ :package-version '(nix-mode . " 1.5.0" ))
173
180
174
181
(defun nix-store-show-path (path )
175
182
" Show a nix-store PATH.
@@ -183,7 +190,7 @@ implement your own ones) you can customize the variable
183
190
(switch-to-buffer (format " Nix Store Path: %s " path))
184
191
(nix-store-path-mode)
185
192
(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)
187
194
(when (file-directory-p path)
188
195
(setq default-directory path))
189
196
(let ((inhibit-read-only t ))
@@ -208,10 +215,9 @@ It uses \\[nix-store-show-path] to display the store path."
208
215
(defun nix-store-show-log ()
209
216
" Opens the log file for the derivation of the nix-store path."
210
217
(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." )))
215
221
216
222
(defvar nix-store-path-mode-map
217
223
(let ((map (make-sparse-keymap )))
@@ -224,6 +230,7 @@ It uses \\[nix-store-show-path] to display the store path."
224
230
(nix-store-show-path (nix-store-path-path nix-buffer-store-path)))
225
231
226
232
(define-derived-mode nix-store-path-mode magit-section-mode " Nix Store Path"
233
+ :group 'nix-store
227
234
(setq-local revert-buffer-function #'nix-store--revert-buffer-function )
228
235
(read-only-mode 1 ))
229
236
0 commit comments