[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/nix-mode a4e6560902 223/500: Add nix-instantiate.el
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/nix-mode a4e6560902 223/500: Add nix-instantiate.el |
Date: |
Sat, 29 Jan 2022 08:27:08 -0500 (EST) |
branch: elpa/nix-mode
commit a4e65609023f1d06a76f7a75716d860bd27cfb68
Author: Matthew Bauer <matthew.bauer@obsidian.systems>
Commit: Matthew Bauer <matthew.bauer@obsidian.systems>
Add nix-instantiate.el
---
nix-instantiate.el | 100 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 100 insertions(+)
diff --git a/nix-instantiate.el b/nix-instantiate.el
new file mode 100644
index 0000000000..25dbcca8da
--- /dev/null
+++ b/nix-instantiate.el
@@ -0,0 +1,100 @@
+;;; nix-instantiate.el -- run nix commands in Emacs -*- lexical-binding: t -*-
+
+;; Author: Matthew Bauer <mjbauer95@gmail.com>
+;; Homepage: https://github.com/NixOS/nix-mode
+;; Keywords: nix
+
+;; This file is NOT part of GNU Emacs.
+
+;;; Commentary:
+
+;;; Code:
+
+(require 'nix)
+(require 'json)
+
+(defun nix-instantiate--parsed (drv)
+ "Get the parsed version of the .drv file.
+DRV file to load from."
+ (let ((stdout (generate-new-buffer "nix show-derivation")))
+ (call-process nix-executable nil (list stdout nil) nil
+ "show-derivation" drv)
+ (cdar (with-current-buffer stdout
+ (when (eq (buffer-size) 0)
+ (error
+ "Error: nix show-derivation %s failed to produce any output"
+ drv))
+ (goto-char (point-min))
+ (json-read)))))
+
+;;;###autoload
+(defun nix-instantiate (nix-file &optional attribute)
+ "Run nix-instantiate on a Nix expression.
+NIX-FILE the file to instantiate.
+ATTRIBUTE an attribute of the Nix file to use."
+ (interactive "fNix file: ")
+ (setq nix-file (expand-file-name nix-file))
+ (let ((stdout (generate-new-buffer "nix-instantiate"))
+ result)
+ (if attribute
+ (call-process nix-instantiate-executable nil (list stdout nil) nil
+ nix-file "-A" attribute)
+ (call-process nix-instantiate-executable nil (list stdout nil) nil
+ nix-file))
+ (with-current-buffer stdout
+ (when (eq (buffer-size) 0)
+ (error
+ "Error: nix-instantiate %s failed to produce any output"
+ nix-file))
+ (setq result (nix-instantiate--parsed
+ (substring (buffer-string) 0 (- (buffer-size) 1)))))
+ (kill-buffer stdout)
+ result))
+
+(defvar nix-instantiate--running-processes nil)
+
+(defun nix-instantiate--sentinel (prop err proc event)
+ "Make a nix-instantiate process.
+PROP the prop name of nix-instantiate--running-processes.
+ERR the error buffer.
+PROC the process that has been run.
+EVENT the event that was fired."
+ (when (string= event "finished\n")
+ (with-current-buffer (process-buffer proc)
+ (unless (eq (buffer-size) 0)
+ (let ((drv (nix-instantiate--parsed
+ (substring (buffer-string) 0 (- (buffer-size) 1)))))
+ (dolist
+ (callback (lax-plist-get nix-instantiate--running-processes prop))
+ (funcall callback drv)))))
+ (setq nix-instantiate--running-processes
+ (lax-plist-put nix-instantiate--running-processes prop nil))
+ (kill-buffer (process-buffer proc))
+ (kill-buffer err)))
+
+;;;###autoload
+(defun nix-instantiate-async (callback nix-file &optional attribute)
+ "Run nix-instantiate on a Nix expression, asynchronously.
+CALLBACK the function to call when instantiate completes.
+NIX-FILE the file to instantiate
+ATTRIBUTE an attribute of the Nix file to use."
+ (setq nix-file (expand-file-name nix-file))
+ (let* ((prop (if attribute
+ (expand-file-name attribute nix-file) nix-file))
+ (data (lax-plist-get nix-instantiate--running-processes prop))
+ (stdout (generate-new-buffer "nix-instantiate"))
+ (stderr (generate-new-buffer "nix-instantiate error")))
+ (setq nix-instantiate--running-processes
+ (lax-plist-put nix-instantiate--running-processes
+ prop (cons callback data)))
+ (make-process
+ :name "nix-instantiate"
+ :buffer stdout
+ :command (append (list nix-instantiate-executable nix-file)
+ (when attribute ("-A" attribute)))
+ :noquery t
+ :sentinel (apply-partially 'nix-instantiate--sentinel prop stderr)
+ :stderr stderr)))
+
+(provide 'nix-instantiate)
+;;; nix-instantiate.el ends here
- [nongnu] elpa/nix-mode d5e839692a 160/500: Fix byte-compile, (continued)
- [nongnu] elpa/nix-mode d5e839692a 160/500: Fix byte-compile, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 895f88eff4 174/500: Add abbrev table, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 0fde15d938 197/500: Prefix unused lexical argument to avoid byte-compilation warning, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 478de28a4e 186/500: Make nix-build use async-shell-command, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode ecee0e39e9 150/500: Add second options for nix-shell, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode f24abeb736 205/500: Don’t prompt with nix-build, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode a820e9adad 210/500: Add electric indentation, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode e298244f55 222/500: Add nix-search.el, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 149d924f6f 221/500: Add nix-store.el, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 429a92a59e 225/500: Group configs in nix-shell, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode a4e6560902 223/500: Add nix-instantiate.el,
ELPA Syncer <=
- [nongnu] elpa/nix-mode 00d099602a 226/500: Fix linter warning, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode cfdeffd066 228/500: Add new files to Cask, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 5aaf80392f 231/500: Avoid recursive loop, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 3aeec264e0 236/500: nix-search: add nix-search-read-attr, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode fea066cec6 241/500: Fix run phase, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 6532fcf244 244/500: Don’t expand nix-file in nix-shell., ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 097b7bb992 257/500: Add nix-build.el, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode a6571fa877 260/500: Add nix-log.el, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 0c2807f037 262/500: Cleanup nix-build.el, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode b62c395b65 264/500: Remove nix-shell-haskell.el, ELPA Syncer, 2022/01/29