-
Notifications
You must be signed in to change notification settings - Fork 8
Make safety checks optional and add nix-buffer-with-string #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 5 commits
0a24fdf
f2e8a93
d93aef4
e82a4fd
25b0497
ce9a1b5
32c9bc3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -102,18 +102,21 @@ LISP-FILE The file in question." | |
| (defvar nix-buffer-after-load-hook nil | ||
| "Hook run after ‘nix-buffer’ loads an expression.") | ||
|
|
||
| (defun nix-buffer--load-result (expr-file out) | ||
| (defun nix-buffer--load-result (expr-file out &optional skip-safety) | ||
| "Load the result of a ‘nix-buffer’ build, checking for safety. | ||
| EXPR-FILE The nix expression being built. | ||
|
|
||
| OUT The build result." | ||
| (when (or (gethash out nix-buffer--trusted-exprs) | ||
| OUT The build result. | ||
|
|
||
| SKIP-SAFETY whether to skip safety checks." | ||
| (when (or skip-safety | ||
| (gethash out nix-buffer--trusted-exprs) | ||
| (nix-buffer--query-safety expr-file out)) | ||
| (load out t t nil t) | ||
| (run-hooks 'nix-buffer-after-load-hook))) | ||
|
|
||
| (defun nix-buffer--sentinel | ||
| (out-link last-out expr-file user-buf err-buf process event) | ||
| (out-link last-out expr-file user-buf err-buf skip-safety process event) | ||
| "Handle the results of the nix build. | ||
| OUT-LINK The path to the output symlink. | ||
|
|
||
|
|
@@ -125,6 +128,8 @@ USER-BUF The buffer to apply the results to. | |
|
|
||
| ERR-BUF The standard error buffer of the nix-build | ||
|
|
||
| SKIP-SAFETY Skip safety checks. | ||
|
|
||
| PROCESS The process whose status changed. | ||
|
|
||
| EVENT The process status change event string." | ||
|
|
@@ -138,7 +143,7 @@ EVENT The process status change event string." | |
| (ignore-errors (delete-file out-link)) | ||
| (unless (string= last-out cur-out) | ||
| (with-current-buffer user-buf | ||
| (nix-buffer--load-result expr-file cur-out))))) | ||
| (nix-buffer--load-result expr-file cur-out skip-safety))))) | ||
| (with-current-buffer | ||
| (get-buffer-create "*nix-buffer errors*") | ||
| (insert "nix-build for nix-buffer for " | ||
|
|
@@ -152,42 +157,56 @@ EVENT The process status change event string." | |
| (kill-buffer out-buf) | ||
| (kill-buffer err-buf)))))) | ||
|
|
||
| (defun nix-buffer--nix-build (root expr-file) | ||
| (defun nix-buffer--nix-build (expr-file &optional root skip-safety) | ||
| "Start the nix build. | ||
| EXPR-FILE The file containing the nix expression to build. | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should these be switched back? |
||
|
|
||
| ROOT The path we started from. | ||
|
|
||
| EXPR-FILE The file containing the nix expression to build." | ||
| SKIP-SAFETY whether to skip the safety checks." | ||
| (let* ((state-dir (f-join nix-buffer-directory-name | ||
| (nix-buffer--unique-filename root))) | ||
| (nix-buffer--unique-filename (or root | ||
| buffer-file-name)))) | ||
| (out-link (f-join state-dir "result")) | ||
| (current-out (file-symlink-p out-link)) | ||
| (err (generate-new-buffer " nix-buffer-nix-build-stderr"))) | ||
| (err (generate-new-buffer " nix-buffer-nix-build-stderr")) | ||
| (command (list "nix-build" expr-file | ||
| "--out-link" out-link))) | ||
| (ignore-errors (make-directory state-dir t)) | ||
| (when root | ||
| (push "--arg" 'command) | ||
| (push "root" 'command) | ||
| (push root 'command)) | ||
| (make-process | ||
| :name "nix-buffer-nix-build" | ||
| :buffer (generate-new-buffer " nix-buffer-nix-build-stdout") | ||
| :command (list | ||
| "nix-build" | ||
| "--arg" "root" root | ||
| "--out-link" out-link | ||
| expr-file | ||
| ) | ||
| :command command | ||
| :noquery t | ||
| :sentinel (apply-partially 'nix-buffer--sentinel | ||
| out-link | ||
| current-out | ||
| expr-file | ||
| (current-buffer) | ||
| err) | ||
| err | ||
| skip-safety) | ||
| :stderr err) | ||
| (when current-out | ||
| (nix-buffer--load-result expr-file current-out)))) | ||
| (nix-buffer--load-result expr-file current-out skip-safety)))) | ||
|
|
||
| (defcustom nix-buffer-root-file "dir-locals.nix" | ||
| "File name to use for determining Nix expression to use." | ||
| :group 'nix-buffer | ||
| :type '(string)) | ||
|
|
||
| ;;;###autoload | ||
| (defun nix-buffer-with-string (expression) | ||
| "Start ‘nix-buffer’ but with a string EXPRESSION." | ||
| (interactive) | ||
| (let ((expr-file (make-temp-file "nix-buffer"))) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, can't we just use
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually that's probably a good idea. I had thought it would save on code duplication but it won't make a big difference. |
||
| (with-temp-file expr-file | ||
| (insert expression)) | ||
| (nix-buffer--nix-build expr-file nil t))) | ||
|
|
||
| ;;;###autoload | ||
| (defun nix-buffer () | ||
| "Set up the buffer according to the directory-local nix expression. | ||
|
|
@@ -224,7 +243,7 @@ is removed." | |
| (expr-dir (locate-dominating-file root nix-buffer-root-file))) | ||
| (when expr-dir | ||
| (let ((expr-file (f-expand nix-buffer-root-file expr-dir))) | ||
| (nix-buffer--nix-build root expr-file))))) | ||
| (nix-buffer--nix-build expr-file root nil))))) | ||
|
|
||
| (add-hook 'kill-emacs-hook 'nix-buffer-unload-function) | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Erm, why is
rootoptional?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it will break anything that needs 'root' like haskellMonoRepo. My thinking was in the context of 'nix-buffer-with-string' you wouldn't want to have a 'root' path set. For instance, you could use it in a script that didn't have any directory or buffer associated.