[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/nix-mode 9362a70d0b 468/500: nix-flake: Organize the libra
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/nix-mode 9362a70d0b 468/500: nix-flake: Organize the library into outlines |
Date: |
Sat, 29 Jan 2022 08:27:57 -0500 (EST) |
branch: elpa/nix-mode
commit 9362a70d0ba13e8a878367b31de60da88c97143c
Author: Akira Komamura <akira.komamura@gmail.com>
Commit: Akira Komamura <akira.komamura@gmail.com>
nix-flake: Organize the library into outlines
---
nix-flake.el | 109 ++++++++++++++++++++++++++++++++++-------------------------
1 file changed, 63 insertions(+), 46 deletions(-)
diff --git a/nix-flake.el b/nix-flake.el
index d50757c7fd..ca16c75709 100644
--- a/nix-flake.el
+++ b/nix-flake.el
@@ -8,12 +8,45 @@
;;; Code:
-(require 'transient)
(require 'nix)
+(require 'transient)
+
+;;;; Utility functions
+
+(defun nix-flake--to-list (x)
+ "If X is not a list, make a singleton list containing it."
+ (if (listp x)
+ x
+ (list x)))
+
+;;;; Registry
+;; Maybe we'll move these functions to a separate library named
nix-registry.el.
+
+(defun nix-flake--registry-list ()
+ "Return a list of entries from the registry."
+ (cl-flet
+ ((split-entry
+ (s)
+ (split-string s "[[:space:]]+")))
+ (thread-last (nix--process-lines "registry" "list")
+ (mapcar #'split-entry))))
+
+(defun nix-flake--select-flake ()
+ "Select a flake from the registry."
+ (completing-read "Flake URL: "
+ (thread-last (nix-flake--registry-list)
+ (cl-remove-if-not (pcase-lambda (`(,type . ,_))
+ (member type '("user" "global"))))
+ (mapcar (pcase-lambda (`(,_ ,_ ,ref))
+ ref)))))
+
+;;;; nix-flake command
+
+;;;;; Variables
(defvar nix-flake-ref nil)
-(defvar nix-flake-outputs nil)
+;;;;; --update-input
(defclass nix-flake:update-input (transient-option)
())
@@ -40,17 +73,6 @@
(when-let ((value (oref obj value)))
(list (oref obj argument) value)))
-(defun nix-flake-system-attribute-names (types)
- "Return a list of output attributes of particular TYPES."
- (let ((system (intern (nix-system))))
- (thread-last nix-flake-outputs
- (mapcar (pcase-lambda (`(,type . ,alist))
- (when (memq type types)
- (mapcar #'car (alist-get system alist)))))
- (apply #'append)
- (cl-remove-duplicates)
- (mapcar #'symbol-name))))
-
(defun nix-flake--input-names ()
"Return a list of inputs to the flake."
(thread-last (nix--process-json "flake" "info" nix-flake-ref "--json")
@@ -67,9 +89,20 @@ FIXME: PROMPT INITIAL-INPUT"
(completing-read prompt (nix-flake--input-names)
nil nil initial-input))
-(defun nix-flake--args ()
- "Return arguments for Nix command."
- (flatten-list (transient-args 'nix-flake-dispatch)))
+;;;;; Attribute names
+
+(defvar nix-flake-outputs nil)
+
+(defun nix-flake-system-attribute-names (types)
+ "Return a list of output attributes of particular TYPES."
+ (let ((system (intern (nix-system))))
+ (thread-last nix-flake-outputs
+ (mapcar (pcase-lambda (`(,type . ,alist))
+ (when (memq type types)
+ (mapcar #'car (alist-get system alist)))))
+ (apply #'append)
+ (cl-remove-duplicates)
+ (mapcar #'symbol-name))))
(defun nix-flake--run-attribute-names ()
"Return possible attribute names for run command."
@@ -87,11 +120,11 @@ FIXME: PROMPT INITIAL-INPUT"
"Return non-nil if there is the default derivation for build command."
(not (null (nix-flake-system-attribute-names '(defaultPackage)))))
-(defun nix-flake--to-list (x)
- "If X is not a list, make a singleton list containing it."
- (if (listp x)
- x
- (list x)))
+;;;;; Building command lines
+
+(defun nix-flake--args ()
+ "Return arguments for Nix command."
+ (flatten-list (transient-args 'nix-flake-dispatch)))
(defun nix-flake--command (subcommand nix-args flake-ref &optional args)
"Build a command line for a Nix subcommand.
@@ -140,6 +173,8 @@ not take the extra arguments."
(concat " -- " args)
"")))
+;;;;; Individual subcommands
+
(defun nix-flake-run-attribute (args flake-ref attribute command-args)
"Run an app in the current flake.
@@ -211,10 +246,6 @@ For ARGS and FLAKE-REF, see the documentation of
(interactive (list (nix-flake--args) nix-flake-ref))
(compile (nix-flake--command '("flake" "update") args flake-ref)))
-(defun nix-flake--description ()
- "Describe the current flake."
- (concat "Flake: " nix-flake-ref))
-
;;;###autoload (autoload 'nix-flake-dispatch "nix-flake" nil t)
(transient-define-prefix nix-flake-dispatch (flake-ref &optional remote)
"Run a command on a Nix flake."
@@ -243,27 +274,9 @@ For ARGS and FLAKE-REF, see the documentation of
(nix--process-json "flake" "show" "--json"
"--no-update-lock-file"))))
(transient-setup 'nix-flake-dispatch))
-(defun nix-flake--registry-list ()
- "Return a list of entries from the registry."
- (cl-flet
- ((split-entry
- (s)
- (split-string s "[[:space:]]+")))
- (thread-last (nix--process-lines "registry" "list")
- (mapcar #'split-entry))))
-
-(defun nix-flake--select-flake ()
- "Select a flake from the registry."
- (completing-read "Flake URL: "
- (thread-last (nix-flake--registry-list)
- (cl-remove-if-not (pcase-lambda (`(,type . ,_))
- (member type '("user" "global"))))
- (mapcar (pcase-lambda (`(,_ ,_ ,ref))
- ref)))))
-
-(defun nix-flake--directory-ref (dir)
- "Return the flake ref for a local DIR."
- (expand-file-name dir))
+(defun nix-flake--description ()
+ "Describe the current flake."
+ (concat "Flake: " nix-flake-ref))
;; A wrapper function for ensuring existence of flake.nix and flake.lock
;; in the project directory.
@@ -296,6 +309,10 @@ 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"))))
+(defun nix-flake--directory-ref (dir)
+ "Return the flake ref for a local DIR."
+ (expand-file-name dir))
+
;;;; nix flake init
(defvar nix-flake-template-repository nil)
- [nongnu] elpa/nix-mode 21d3ba0b80 382/500: Update yaml again, (continued)
- [nongnu] elpa/nix-mode 21d3ba0b80 382/500: Update yaml again, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 7487346812 378/500: Add flake, ELPA Syncer, 2022/01/29
- [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 <=
- [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, 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