[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/nix-mode acf4fd09db 470/500: nix-flake: Add customization
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/nix-mode acf4fd09db 470/500: nix-flake: Add customization options |
Date: |
Sat, 29 Jan 2022 08:27:57 -0500 (EST) |
branch: elpa/nix-mode
commit acf4fd09db1ebc20f2e642b0f64e6e549ccbb5ae
Author: Akira Komamura <akira.komamura@gmail.com>
Commit: Akira Komamura <akira.komamura@gmail.com>
nix-flake: Add customization options
---
nix-flake.el | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++----------
1 file changed, 78 insertions(+), 15 deletions(-)
diff --git a/nix-flake.el b/nix-flake.el
index 475d53a4df..bdf432f957 100644
--- a/nix-flake.el
+++ b/nix-flake.el
@@ -11,6 +11,28 @@
(require 'nix)
(require 'transient)
+;;;; Custom variables
+
+(defcustom nix-flake-init-post-action 'open-flake
+ "Action to run after successfully initializing a flake.
+
+This action is run after a flake is successlly initialized by
+`nix-flake-init` (or generally `nix-flake-dispatch`).
+
+You can also specify a function, which should take no arguments.
+It is called in the directory of the flake."
+ :type '(choice (const :tag "Open flake.nix" open-flake-nix)
+ (const :tag "Do nothing" nil)
+ (function :tag "User-defined function")))
+
+(defcustom nix-flake-add-to-registry t
+ "Whether to add a new flake to registry.
+
+When this variable is non-nil, every flake reference from the
+interactive input is added to the flake registry, unless it is
+already registered in either the user or the global registry."
+ :type 'boolean)
+
;;;; Transient classes
;;;;; flake-ref
@@ -61,13 +83,30 @@
;; just in case, but it may not be necessary.
(defun nix-flake--select-flake (&optional prompt initial-input history)
"Select a flake from the registry."
- (completing-read (or prompt "Flake URL: ")
- (thread-last (nix-flake--registry-list)
- (cl-remove-if-not (pcase-lambda (`(,type . ,_))
- (member type '("user" "global"))))
- (mapcar (pcase-lambda (`(,_ ,_ ,ref))
- ref)))
- nil nil nil history initial-input))
+ (let* ((registry-entries (thread-last (nix-flake--registry-list)
+ (cl-remove-if-not (pcase-lambda (`(,type . ,_))
+ (member type '("user"
"global"))))))
+ (input (string-trim
+ (completing-read (or prompt "Flake URL: ")
+ (thread-last registry-entries
+ (mapcar (pcase-lambda (`(,_ ,_ ,ref))
+ ref)))
+ nil nil nil history initial-input))))
+ (prog1 input
+ (when (and nix-flake-add-to-registry
+ (not (member input
+ (thread-last registry-entries
+ (mapcar (lambda (cells)
+ (list (nth 1 cells)
+ (nth 2 cells))))
+ (flatten-list)))))
+ (let ((name (read-string (format-message "Enter the registry name for
%s: "
+ input))))
+ (unless (or (not name)
+ (string-empty-p name))
+ (start-process "nix registry add" "*nix registry add*"
+ nix-executable
+ "registry" "add" name input)))))))
;;;; nix-flake command
@@ -345,7 +384,11 @@ whatever supported by Nix."
;;;;; Setting the template repository
-(defvar nix-flake-template-repository nil)
+(defvar nix-flake-template-repository nil
+ "Flake reference to the current template sets.")
+
+(defvar nix-flake-template-name nil
+ "Attribute name of the last used template.")
(defun nix-flake--init-source ()
"Describe the current template repository for init command."
@@ -369,13 +412,33 @@ whatever supported by Nix."
FLAKE-REF must be a reference to a flake which contains the
template, TEMPLATE-NAME is the name of the template."
- (compile (mapconcat #'shell-quote-argument
- `(,nix-executable
- "flake"
- "init"
- "-t"
- ,(concat flake-ref "#" template-name))
- " ")))
+ ;; Save the selection state for later use.
+ (setq nix-flake-template-repository flake-ref
+ nix-flake-template-name template-name)
+ (let ((proc (start-process "nix flake init"
+ "*nix flake init*"
+ nix-executable
+ "flake"
+ "init"
+ "-t"
+ (concat flake-ref "#" template-name))))
+ (set-process-sentinel proc
+ (lambda (process _event)
+ (when (eq 'exit (process-status process))
+ (if (= 0 (process-exit-status process))
+ (nix-flake-init-post-action)
+ (message "Returned non-zero from nix flake
init")))))
+ proc))
+
+(defun nix-flake-init-post-action ()
+ "Perform an post-process action depending on the configuration.
+
+See `nix-flake-init-post-action' variable for details."
+ (pcase nix-flake-init-post-action
+ ('open-flake-nix
+ (find-file "flake.nix"))
+ ((pred functionp)
+ (funcall nix-flake-init-post-action))))
;;;;; Selecting a template
- [nongnu] elpa/nix-mode 0e3a8ef7a8 398/500: Check for process before completing in nix-repl, (continued)
- [nongnu] elpa/nix-mode 0e3a8ef7a8 398/500: Check for process before completing in nix-repl, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 12d1e29ff1 397/500: Merge pull request #106 from jcs-PR/minor, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 8bc6750c4c 420/500: Update flake.lock., ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 1b1b9fb61d 440/500: Update nixos, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode f2acc55830 431/500: Add .dir-locals.el file, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 1697f18066 439/500: Fix #128, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 04d9a86eae 437/500: Merge pull request #130 from nagy/simplify, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 9362a70d0b 468/500: nix-flake: Organize the library into outlines, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 241cc0881e 466/500: nix-flake.el: Init nix-flake command, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode dd0d1c0d0b 467/500: nix-flake: WIP: nix-flake-init, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode acf4fd09db 470/500: nix-flake: Add customization options,
ELPA Syncer <=
- [nongnu] elpa/nix-mode 7346057087 471/500: nix-flake: Show aliases in the registry as well, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode de85646434 486/500: Add dependabot.yml, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 186698599c 480/500: nix-flake: Set a prompt string, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 6712a66321 381/500: Fix yaml, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 1c42c634bf 379/500: Allow missing git repo, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 38958e5203 413/500: Update install-nix-action in GitHub Action, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode cc60a0d027 417/500: Make nix-drv-mode a derived-mode of javascript-mode, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 0de9c70c89 429/500: Split up `nix-search` into two separate functions, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode e8e5211f6e 426/500: Merge pull request #122 from leungbk/def-obsol, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 98426b94e5 280/500: Add function to indent things in blocks for nix-indent-line, ELPA Syncer, 2022/01/29