[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/nix-mode c19e103eee 430/500: Add support nix 2.4 flakes in
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/nix-mode c19e103eee 430/500: Add support nix 2.4 flakes in search |
Date: |
Sat, 29 Jan 2022 08:27:52 -0500 (EST) |
branch: elpa/nix-mode
commit c19e103eee7091a79cdc9ecff320a3cea640abab
Author: Matthew Bauer <mjbauer95@gmail.com>
Commit: Matthew Bauer <mjbauer95@gmail.com>
Add support nix 2.4 flakes in search
This lets you search flakes like so:
M-x nix-search<RET>
abc
---
nix-search.el | 30 ++++++++++++++++++------------
nix-shell.el | 13 +++++++++++++
nix.el | 26 +++++++++++++++++++++++++-
3 files changed, 56 insertions(+), 13 deletions(-)
diff --git a/nix-search.el b/nix-search.el
index ccd0f03645..435e17d45a 100644
--- a/nix-search.el
+++ b/nix-search.el
@@ -17,24 +17,29 @@
(require 'json)
;;;###autoload
-(defun nix-search--search (search file &optional no-cache)
+(defun nix-search--search (search file &optional no-cache use-flakes)
(with-temp-buffer
- (call-process nix-executable nil (list t nil) nil
- "search" "--json" (if no-cache "--no-cache" "") "--file" file search)
+ (if use-flakes
+ (call-process nix-executable nil (list t nil) nil
+ "search" "--json" file (if (string= search "") "."
search))
+ (call-process nix-executable nil (list t nil) nil
+ "search" "--json" (if no-cache "--no-cache" "") "--file"
file search))
(goto-char (point-min))
(json-read)))
;;;###autoload
-(defun nix-search--display (results &optional display-buffer)
+(defun nix-search--display (results &optional display-buffer use-flakes)
(unless display-buffer (setq display-buffer (generate-new-buffer "*nix
search*")))
(with-current-buffer display-buffer
(dolist (entry results)
(widget-insert
- (format "attr: %s\nname: %s\nversion: %s\ndescription: %s\n\n"
- (car entry)
- (alist-get 'pkgName (cdr entry))
- (alist-get 'version (cdr entry))
- (alist-get 'description (cdr entry))))))
+ (format "attr: %s\nname: %s\nversion: %s\ndescription: %s\n\n"
+ (car entry)
+ (if use-flakes
+ (alist-get 'pname (cdr entry))
+ (alist-get 'pkgName (cdr entry)))
+ (alist-get 'version (cdr entry))
+ (alist-get 'description (cdr entry))))))
(display-buffer display-buffer))
;;;###autoload
@@ -43,10 +48,11 @@
SEARCH a search term to use.
FILE a Nix expression to search in."
(interactive "snix-search> \n")
- (setq file (or file (nix-read-file)))
- (let ((results (nix-search--search search file)))
+ (setq use-flakes (nix-has-flakes))
+ (setq file (or file (if use-flakes (nix-read-flake) (nix-read-file))))
+ (let ((results (nix-search--search search file nil use-flakes)))
(when (called-interactively-p 'any)
- (nix-search--display results))
+ (nix-search--display results nil use-flakes))
results))
(defun nix-search-read-attr (file)
diff --git a/nix-shell.el b/nix-shell.el
index e8b5c8d21f..dcab7e5df4 100644
--- a/nix-shell.el
+++ b/nix-shell.el
@@ -60,6 +60,12 @@ Should only be set in dir-locals.el file."
:type 'stringp
:group 'nix-shell)
+(defcustom nix-flake nil
+ "Nix flake to build expressions from.
+Should only be set in dir-locals.el file."
+ :type 'stringp
+ :group 'nix-shell)
+
(defcustom nix-attr nil
"Nix attribute path to use.
Should only be set in dir-locals.el file."
@@ -80,6 +86,13 @@ ATTR is the attribute to unpack."
"Get nix attribute from user."
(read-string "Nix attr: "))
+(defun nix-read-flake ()
+ "Get nix flake from user."
+ (cond
+ (nix-flake nix-flake)
+ ((and (nix-has-flakes) (file-exists-p "flake.nix")) ".")
+ (t (read-string "Nix flake: " "nixpkgs"))))
+
(defun nix-read-file ()
"Get nix file from user."
(cond
diff --git a/nix.el b/nix.el
index 0507ae7e7d..ede66d7790 100644
--- a/nix.el
+++ b/nix.el
@@ -78,6 +78,17 @@
(kill-buffer stdout)
result)))
+(defun nix-show-config ()
+ "Show nix config."
+ (let ((stdout (generate-new-buffer "nix config"))
+ result)
+ (call-process nix-executable nil (list stdout nil) nil "show-config"
"--json")
+ (setq result (with-current-buffer stdout
+ (goto-char (point-min))
+ (json-read)))
+ (kill-buffer stdout)
+ result))
+
(defvar nix-commands
'("add-to-store"
"build"
@@ -187,10 +198,23 @@ OPTIONS a list of options to accept."
((or (string= "-s" last-arg) (string= "--substituter" last-arg))
(pcomplete-here))))))
+(defun nix-is-24 ()
+ "Whether Nix is a version with Flakes support."
+ ;; earlier versions reported as 3, now it’s just nix-2.4
+ (let ((version (nix-version)))
+ (or (string-prefix-p "nix (Nix) 3" version)
+ (string-prefix-p "nix (Nix) 2.4" version))))
+
+(defun nix-has-flakes ()
+ "Whether Nix is a version with Flakes support."
+ ;; earlier versions reported as 3, now it’s just nix-2.4
+ (and (nix-is-24)
+ (seq-contains-p (alist-get 'value (alist-get 'experimental-features
(nix-show-config))) "flakes")))
+
;;;###autoload
(defun pcomplete/nix ()
"Completion for the nix command."
- (if (string-prefix-p "nix (Nix) 3" (nix-version))
+ (if (nix-is-24)
(let ((stdout (generate-new-buffer "nix-completions"))
(process-environment
(cons (format "NIX_GET_COMPLETIONS=%s" (1- (length
pcomplete-args)))
- [nongnu] elpa/nix-mode 588246b499 229/500: Fix escaping of characters, (continued)
- [nongnu] elpa/nix-mode 588246b499 229/500: Fix escaping of characters, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode a5bf79a563 425/500: Merge pull request #120 from znewman01/master, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 7593b023a7 405/500: Merge pull request #110 from leungbk/repl-history, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 1fdf8e654a 444/500: Merge pull request #132 from league/master, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 8e20de5ba7 462/500: Merge pull request #134 from nagy/store-path, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 01e37b6761 464/500: Merge pull request #139 from akirak/fix/nix-24-for-25, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 8a05b88eb3 448/500: Fix a typo, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 207e5c0a92 455/500: nix-format.el: Add nix-format-before-save, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 86b7195b3e 010/500: Use warning font lock for upper case vars, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode c81c03b35e 403/500: nix-repl: use history file, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode c19e103eee 430/500: Add support nix 2.4 flakes in search,
ELPA Syncer <=
- [nongnu] elpa/nix-mode 5fa017c6ad 393/500: Merge pull request #105 from rossabaker/completions, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 0380e03203 406/500: Merge pull request #109 from yilinwei/master, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode aef98227cc 419/500: Merge branch 'master' into derived-nix-drv-mode, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode ffcab906b8 407/500: Makefile: add nix-mode project directory to 'load-path' in 'run' target, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode da7e638f2f 451/500: Spell out command argument, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode c4abb64a64 494/500: nix-flake: Add a comment, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 21ed086cca 008/500: Fix flycheck complaints., ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 4fe6058fb4 142/500: allow escape sequences inside sh-mode block, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 1268096ba7 136/500: Merge pull request #27 from ljli/close-open-fix, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 676cc65daf 153/500: Add some README doc., ELPA Syncer, 2022/01/29