[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/nix-mode dd0d1c0d0b 467/500: nix-flake: WIP: nix-flake-ini
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/nix-mode dd0d1c0d0b 467/500: nix-flake: WIP: nix-flake-init |
Date: |
Sat, 29 Jan 2022 08:27:57 -0500 (EST) |
branch: elpa/nix-mode
commit dd0d1c0d0baa7627d0d431287c5b46904aa6d385
Author: Akira Komamura <akira.komamura@gmail.com>
Commit: Akira Komamura <akira.komamura@gmail.com>
nix-flake: WIP: nix-flake-init
---
nix-flake.el | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 72 insertions(+)
diff --git a/nix-flake.el b/nix-flake.el
index dd68c041db..d50757c7fd 100644
--- a/nix-flake.el
+++ b/nix-flake.el
@@ -296,5 +296,77 @@ whatever supported by Nix."
;; TODO: Let the user run 'nix flake init' to create flake.nix
(user-error "The directory does not contain flake.nix"))))
+;;;; nix flake init
+
+(defvar nix-flake-template-repository nil)
+
+(defun nix-flake--init-source ()
+ "Describe the current template repository for init command."
+ (format "Template repository: %s" nix-flake-template-repository))
+
+(defun nix-flake--templates (flake-ref)
+ "Return a list of templates in FLAKE-REF."
+ (thread-last (nix--process-json "flake" "show" "--json" flake-ref)
+ (alist-get 'templates)
+ (mapcar #'car)
+ (mapcar #'symbol-name)))
+
+(defun nix-flake--init (flake-ref template-name)
+ "Initialize a flake from a template.
+
+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))
+ " ")))
+
+;; It might be better to use `transient-define-suffix', but I don't know for
+;; sure.
+(defun nix-flake-init-select-template ()
+ "Select a template and initialize a flake."
+ (interactive)
+ (let* ((flake-ref (or nix-flake-template-repository
+ (nix-flake--select-flake)))
+ (template-name (completing-read
+ (format-message "Select a template from %s: "
flake-ref)
+ (nix-flake--templates flake-ref))))
+ (nix-flake--init flake-ref template-name)))
+
+;;;###autoload (autoload 'nix-flake-init "nix-flake" nil t)
+(transient-define-prefix nix-flake-init-dispatch (&optional flake-ref)
+ "Scaffold a project from a template."
+ [:description "Initialize a flake"]
+ [:description
+ nix-flake--init-source
+ ("r" nix-flake-init--from-registry)]
+ ["Initialize a flake"
+ ("t" "Select template" nix-flake-init-select-template)]
+ (interactive (list nil))
+ (when flake-ref
+ (setq nix-flake-template-repository flake-ref))
+ (transient-setup 'nix-flake-init-dispatch))
+
+;;;###autoload
+(defun nix-flake-init ()
+ "Run \"nix flake init\" command via a transient interface."
+ (interactive)
+ (let* ((root (ignore-errors
+ (vc-root-dir)))
+ (default-directory
+ (if (and root
+ (not (file-equal-p root default-directory))
+ (yes-or-no-p (format-message
+ "The directory %s is not the repository
root. Change to %s?"
+ default-directory root)))
+ root
+ default-directory)))
+ (if (file-exists-p "flake.nix")
+ (user-error "This directory already contains a flake")
+ (nix-flake-init-dispatch))))
+
(provide 'nix-flake)
;;; nix-flake.el ends here
- [nongnu] elpa/nix-mode 015bf9639a 386/500: Remove filenames handling, (continued)
- [nongnu] elpa/nix-mode 015bf9639a 386/500: Remove filenames handling, ELPA Syncer, 2022/01/29
- [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 <=
- [nongnu] elpa/nix-mode acf4fd09db 470/500: nix-flake: Add customization options, ELPA Syncer, 2022/01/29
- [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