;ELC ;;; Compiled ;;; in Emacs version 28.0.50 ;;; with all optimizations. (byte-code "\300\301!\210\300\302!\210\303\304\305\306\307\310\311\312\313\314& \207" [require f subr-x custom-declare-group nix-buffer nil "Customization for nix-buffer." :prefix "nix-buffer-" :group environment :package-version ('nix-buffer . "3.1.1")] 10) #@119 Defcustom setter for ‘nix-buffer-directory-name’. OPT The option we're setting. VAL The value it's being set to. (defalias 'nix-buffer--directory-name-setter #[(opt val) "\301!\207" [val nix-buffer-update-directory-name] 2 (#$ . 347)]) #@138 Path where ‘nix-buffer’ keeps its data. To update this variable outside of Customize, please use 'nix-buffer-update-directory-name'. (custom-declare-variable 'nix-buffer-directory-name '(locate-user-emacs-file "nix-buffer") '(#$ . 596) :group 'nix-buffer :type '(directory) :set 'nix-buffer--directory-name-setter :initialize 'custom-initialize-default :risky t) (defvar nix-buffer--trust-exprs-file (f-join nix-buffer-directory-name "trusted-exprs")) #@42 Load the trusted ‘nix-buffer’ exprs. (defalias 'nix-buffer--load-trusted-exprs #[nil "\3031\304\305\306\"rq\210\307\216\310 !\210\311p!+0\202\210\312\313\n!\203(\n\202,\314\315\316\")\207" [#1=#:temp-buffer nix-buffer--trust-exprs-file tbl (error) generate-new-buffer " *temp*" t #[nil "\301!\205 \302!\207" [#1# buffer-name kill-buffer] 2] insert-file-contents-literally read nil hash-table-p make-hash-table :test equal] 3 (#$ . 1058)]) (defvar nix-buffer--trusted-exprs (nix-buffer--load-trusted-exprs)) #@97 Update the ‘nix-buffer’ state directory. PATH The path to store the ‘nix-buffer’ state. (defalias 'nix-buffer-update-directory-name #[(path) "\304 \305\"\306 \211\207" [path nix-buffer-directory-name nix-buffer--trust-exprs-file nix-buffer--trusted-exprs f-join "trusted-exprs" nix-buffer--load-trusted-exprs] 3 (#$ . 1587)]) #@23 Save state on unload. (defalias 'nix-buffer-unload-function #[nil "\3041 \305\306\"0\210\202\210\307\310\306\"r q\210\311\216\312\np\"\210\313\314\211 #\210+\314\207" [nix-buffer-directory-name #1=#:temp-buffer nix-buffer--trusted-exprs nix-buffer--trust-exprs-file (error) make-directory t generate-new-buffer " *temp*" #[nil "\301!\205 \302!\207" [#1# buffer-name kill-buffer] 2] prin1 write-region nil] 4 (#$ . 1931)]) #@91 Create a unix-safe filename from an entire path. PATH the path to generate the name from. (defalias 'nix-buffer--unique-filename #[(path) "\301\302\303#\207" [path replace-regexp-in-string "[|\\/]" #[(str) "\301\232\203\302\207\303P\207" [str "/" "|" "\\\\"] 2]] 4 (#$ . 2367)]) #@128 Ask the user whether to trust a Lisp file. EXPR-FILE The nix expression leading to this file. LISP-FILE The file in question. (defalias 'nix-buffer--query-safety #[(expr-file lisp-file) "\304\305 \306R!\307 \n #\210\n)\207" [expr-file lisp-file res nix-buffer--trusted-exprs yes-or-no-p " resulted in unknown Lisp file " "; trust it? " puthash] 5 (#$ . 2658)]) #@54 Hook run after ‘nix-buffer’ loads an expression. (defvar nix-buffer-after-load-hook nil (#$ . 3028)) #@132 Load the result of a ‘nix-buffer’ build, checking for safety. EXPR-FILE The nix expression being built. OUT The build result. (defalias 'nix-buffer--load-result #[(expr-file out) "\303 \"\204\304\n\"\205\305\306\211\307\306%\210\310\311!\207" [out nix-buffer--trusted-exprs expr-file gethash nix-buffer--query-safety load t nil run-hooks nix-buffer-after-load-hook] 6 (#$ . 3140)]) #@355 Handle the results of the nix build. OUT-LINK The path to the output symlink. LAST-OUT The previous build result, if any. EXPR-FILE The nix expression being built. USER-BUF The buffer to apply the results to. ERR-BUF The standard error buffer of the nix-build PROCESS The process whose status changed. EVENT The process status change event string. (defalias 'nix-buffer--sentinel #[(out-link last-out expr-file user-buf err-buf process event) "\306!?\205q\307!\310!\311U\203Hr q\210\312\313 !)\211\314\230\2033\3151/\316 !0\210\202D\210\202D\f\n\230\204Dr q\210\317\n\"\210))\202er\320\321!q\210\322\323 !\324\312!\325\261\210\326!\210\327p!\210)\330\331 !\210\331!*\207" [process out-buf cur-out out-link last-out user-buf process-live-p process-buffer process-exit-status 0 string-trim-right buffer-string "" (error) delete-file nix-buffer--load-result get-buffer-create "*nix-buffer errors*" "nix-build for nix-buffer for " buffer-name " " " with error output: \n" insert-buffer-substring pop-to-buffer nil kill-buffer expr-file event err-buf kill-buffer-query-functions] 6 (#$ . 3541)]) #@113 Start the nix build. ROOT The path we started from. EXPR-FILE The file containing the nix expression to build. (defalias 'nix-buffer--nix-build #[(root expr-file) "\306\307 !\"\306\n\310\"\311 !\312\313!\3141!\315\n\316\"0\210\202\"\210\317\320\321\322\312\323!\324\325\326\327 \330 \257\331\316\332\333\334 \fp &\335 &\f\210\f\205O\336\f\",\207" [nix-buffer-directory-name root state-dir out-link current-out err f-join nix-buffer--unique-filename "result" file-symlink-p generate-new-buffer " nix-buffer-nix-build-stderr" (error) make-directory t make-process :name "nix-buffer-nix-build" :buffer " nix-buffer-nix-build-stdout" :command "nix-build" "--arg" "root" "--out-link" :noquery :sentinel apply-partially nix-buffer--sentinel :stderr nix-buffer--load-result expr-file] 17 (#$ . 4669)]) #@57 File name to use for determining Nix expression to use. (custom-declare-variable 'nix-buffer-root-file "dir-locals.nix" '(#$ . 5487) :group 'nix-buffer :type '(string)) #@1429 Set up the buffer according to the directory-local nix expression. Looks for dir-locals.nix upward from the current directory. If found, asynchronously builds the derivation defined there with the 'root' arg set to the current buffer file name or directory and evaluates the resulting elisp if safe to do so. 'nix-buffer-after-load-hook' can be used to detect when the elisp load occurs. If we have previously built dir-locals.nix for the current file or directory, the elisp corresponding to the last build is evaluated synchronously and the new elisp is evaluated when the build completes, unless the newly-built file is identical. As such, the elisp generated by dir-locals.nix should be written with multiple evaluations in mind. Because in practice dir-locals.nix will always want to do things that are unsafe in dir-locals.el (e.g. append to 'exec-path'), we don't reuse that mechanism and instead just load the file as elisp. Because this allows arbitrary code execution, the first time we're asked to load a particular store path we query the user to verify if it's safe to load beforehand. The Lisp code generated by dir-locals.nix should limit itself to modifying buffer-local variables, but there is no actual enforcement of this. 'setq-local' is your friend. If dir-locals.nix does not evaluate to any derivations (e.g. it evaluates to {}), then nothing is loaded and the cached result, if any, is removed. (defalias 'nix-buffer #[nil "\305\306\307 \206!!\310 \n\"\211\205\305\n \"\311 \f\")*\207" [default-directory root nix-buffer-root-file expr-dir expr-file f-expand directory-file-name buffer-file-name locate-dominating-file nix-buffer--nix-build] 4 (#$ . 5664) nil]) (byte-code "\300\301\302\"\210\303\304!\207" [add-hook kill-emacs-hook nix-buffer-unload-function provide nix-buffer] 3)