yeet
This commit is contained in:
57
.config/emacs/modules/lang/nix/README.org
Normal file
57
.config/emacs/modules/lang/nix/README.org
Normal file
@@ -0,0 +1,57 @@
|
||||
#+TITLE: lang/nix
|
||||
#+DATE: May 4, 2020
|
||||
#+SINCE: v2.0.7
|
||||
#+STARTUP: inlineimages nofold
|
||||
|
||||
* Table of Contents :TOC_3:noexport:
|
||||
- [[#description][Description]]
|
||||
- [[#maintainers][Maintainers]]
|
||||
- [[#module-flags][Module Flags]]
|
||||
- [[#plugins][Plugins]]
|
||||
- [[#prerequisites][Prerequisites]]
|
||||
- [[#features][Features]]
|
||||
- [[#keybindings][Keybindings]]
|
||||
- [[#configuration][Configuration]]
|
||||
- [[#troubleshooting][Troubleshooting]]
|
||||
|
||||
* Description
|
||||
Adds many tools for [[https://nixos.org/][Nix(OS)]] users in nice package for Doom users.
|
||||
|
||||
+ Syntax highlighting
|
||||
+ Completion through ~company~ / ~helm~
|
||||
+ Nix option lookup
|
||||
+ Formatting (~nixfmt~)
|
||||
|
||||
** Maintainers
|
||||
This module has no dedicated maintainers.
|
||||
|
||||
** Module Flags
|
||||
This module provides no flags.
|
||||
|
||||
** Plugins
|
||||
+ [[https://github.com/NixOS/nix-mode][nix-mode]]
|
||||
+ [[https://github.com/jwiegley/nix-update-el][nix-update]]
|
||||
|
||||
* Prerequisites
|
||||
+ ~nixfmt~ is required to use formatting
|
||||
+ If you have Nix(OS) installed it can be installed through Nix configuration ~environment.systemPackages = with pkgs; [ nixfmt ];~ (recommended)
|
||||
+ Or through nix-env ~nix-env -iA nixpkgs.nixfmt~
|
||||
+ Or through nix-shell ~nix-shell -f https://github.com/serokell/nixfmt/archive/master.tar.gz -i~
|
||||
+ ~:editor format~ ~format-all~ also supports ~nixfmt~ so you can use that also to format Nix code, default binding is ~SPC c f~ in evil.
|
||||
|
||||
* Features
|
||||
** Keybindings
|
||||
| Binding | Description |
|
||||
|-------------------+----------------------|
|
||||
| ~<localleader> b~ | ~nix-build~ |
|
||||
| ~<localleader> f~ | ~nix-update-fetch~ |
|
||||
| ~<localleader> o~ | ~+nix/lookup-option~ |
|
||||
| ~<localleader> p~ | ~nix-format-buffer~ |
|
||||
| ~<localleader> r~ | ~nix-repl-show~ |
|
||||
| ~<localleader> s~ | ~nix-repl-shell~ |
|
||||
| ~<localleader> u~ | ~nix-unpack~ |
|
||||
|
||||
* Configuration
|
||||
|
||||
* Troubleshooting
|
||||
+ There aren't any known problems.
|
||||
75
.config/emacs/modules/lang/nix/autoload.el
Normal file
75
.config/emacs/modules/lang/nix/autoload.el
Normal file
@@ -0,0 +1,75 @@
|
||||
;;; lang/nix/autoload.el -*- lexical-binding: t; -*-
|
||||
|
||||
(defun +nix--options-action (candidate)
|
||||
(switch-to-buffer-other-window
|
||||
(nixos-options-doc-buffer
|
||||
(nixos-options-get-documentation-for-option candidate))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +nix/open-repl ()
|
||||
"Open a nix repl."
|
||||
(interactive)
|
||||
(nix-repl-show)
|
||||
(current-buffer))
|
||||
|
||||
;;;###autoload
|
||||
(defun +nix/lookup-option (&optional initial-input)
|
||||
"Look up documentation on a nix option."
|
||||
(interactive
|
||||
(list
|
||||
;; REVIEW Must be a better way to do this
|
||||
(when (and (looking-at-p "[a-zA-Z0-9-_\\.]")
|
||||
(not (doom-point-in-string-or-comment-p)))
|
||||
(buffer-substring-no-properties
|
||||
(save-excursion
|
||||
(skip-chars-backward "^ ")
|
||||
(point))
|
||||
(save-excursion
|
||||
(skip-chars-forward "^ ")
|
||||
(point))))))
|
||||
(cond ((featurep! :completion helm)
|
||||
(require 'helm-nixos-options)
|
||||
;; REVIEW We reimplment `helm-nixos-options' so we can supply
|
||||
;; `initial-input'. Maybe use `helm-attrset' instead?
|
||||
(helm :sources `(,(helm-source-nixos-options-search))
|
||||
:buffer "*helm-nixos-options*"
|
||||
:input initial-input))
|
||||
((featurep! :completion ivy)
|
||||
(require 'nixos-options)
|
||||
(ivy-read "NixOS options: "
|
||||
nixos-options
|
||||
:require-match t
|
||||
:initial-input initial-input
|
||||
:action #'+nix--options-action
|
||||
:caller '+nix/options))
|
||||
;; TODO Add general `completing-read' support
|
||||
((user-error "No search engine is enabled. Enable helm or ivy!")))
|
||||
;; Tell lookup module to let us handle things from here
|
||||
'deferred)
|
||||
|
||||
;;;###autoload
|
||||
(defun +nix-shell-init-mode ()
|
||||
"Resolve a (cached-)?nix-shell shebang to the correct major mode."
|
||||
(save-excursion
|
||||
(goto-char (point-min))
|
||||
(save-match-data
|
||||
(if (not (and (re-search-forward "\\_<nix-shell " (line-end-position 2) t)
|
||||
(re-search-forward "-i +\"?\\([^ \"\n]+\\)" (line-end-position) t)))
|
||||
(message "Couldn't determine mode for this script")
|
||||
(let* ((interp (match-string 1))
|
||||
(mode
|
||||
(assoc-default
|
||||
interp
|
||||
(mapcar (lambda (e)
|
||||
(cons (format "\\`%s\\'" (car e))
|
||||
(cdr e)))
|
||||
interpreter-mode-alist)
|
||||
#'string-match-p)))
|
||||
(when mode
|
||||
(prog1 (set-auto-mode-0 mode)
|
||||
(when (eq major-mode 'sh-mode)
|
||||
(sh-set-shell interp))
|
||||
;; HACK Without this, quickrun tries to evaluate code directly
|
||||
;; with (cached)?nix-shell.
|
||||
;; TODO Use the nix-shell/cached-nix-shell-given interpreter
|
||||
(setq-local quickrun-option-shebang nil))))))))
|
||||
49
.config/emacs/modules/lang/nix/config.el
Normal file
49
.config/emacs/modules/lang/nix/config.el
Normal file
@@ -0,0 +1,49 @@
|
||||
;;; lang/nix/config.el -*- lexical-binding: t; -*-
|
||||
|
||||
(after! tramp
|
||||
(add-to-list 'tramp-remote-path "/run/current-system/sw/bin"))
|
||||
|
||||
|
||||
;;
|
||||
;;; Plugins
|
||||
|
||||
(use-package! nix-mode
|
||||
:interpreter ("\\(?:cached-\\)?nix-shell" . +nix-shell-init-mode)
|
||||
:mode "\\.nix\\'"
|
||||
:init
|
||||
;; Treat flake.lock files as json. Fall back to js-mode because it's faster
|
||||
;; than js2-mode, and its extra features aren't needed there.
|
||||
(add-to-list 'auto-mode-alist
|
||||
(cons "/flake\\.lock\\'"
|
||||
(if (featurep! :lang json)
|
||||
'json-mode
|
||||
'js-mode)))
|
||||
:config
|
||||
(set-repl-handler! 'nix-mode #'+nix/open-repl)
|
||||
(set-company-backend! 'nix-mode 'company-nixos-options)
|
||||
(set-lookup-handlers! 'nix-mode
|
||||
:documentation '(+nix/lookup-option :async t))
|
||||
(set-popup-rule! "^\\*nixos-options-doc\\*$" :ttl 0 :quit t)
|
||||
|
||||
;; Fix #3927: disable idle completion because `company-nixos-options' is
|
||||
;; dreadfully slow. It can still be invoked manually..
|
||||
(setq-hook! 'nix-mode-hook company-idle-delay nil)
|
||||
|
||||
(map! :localleader
|
||||
:map nix-mode-map
|
||||
"f" #'nix-update-fetch
|
||||
"p" #'nix-format-buffer
|
||||
"r" #'nix-repl-show
|
||||
"s" #'nix-shell
|
||||
"b" #'nix-build
|
||||
"u" #'nix-unpack
|
||||
"o" #'+nix/lookup-option))
|
||||
|
||||
(use-package! nix-drv-mode
|
||||
:mode "\\.drv\\'")
|
||||
|
||||
(use-package! nix-update
|
||||
:commands nix-update-fetch)
|
||||
|
||||
(use-package! nix-repl
|
||||
:commands nix-repl-show)
|
||||
9
.config/emacs/modules/lang/nix/doctor.el
Normal file
9
.config/emacs/modules/lang/nix/doctor.el
Normal file
@@ -0,0 +1,9 @@
|
||||
;; -*- lexical-binding: t; no-byte-compile: t; -*-
|
||||
;;; lang/nix/doctor.el
|
||||
|
||||
(unless (executable-find "nix")
|
||||
(warn! "Couldn't find the nix package manager. nix-mode won't work."))
|
||||
|
||||
(unless (executable-find "nixfmt")
|
||||
(warn! "Couldn't find nixfmt. nix-format-buffer won't work."))
|
||||
|
||||
11
.config/emacs/modules/lang/nix/packages.el
Normal file
11
.config/emacs/modules/lang/nix/packages.el
Normal file
@@ -0,0 +1,11 @@
|
||||
;; -*- no-byte-compile: t; -*-
|
||||
;;; lang/nix/packages.el
|
||||
|
||||
(package! nix-mode :pin "8e20de5ba7061d810b08df5557b1fdb60c94b639")
|
||||
(package! nix-update :pin "fc6c39c2da3fcfa62f4796816c084a6389c8b6e7")
|
||||
|
||||
(when (featurep! :completion company)
|
||||
(package! company-nixos-options :pin "053a2d5110ce05b7f99bcc2ac4804b70cbe87916"))
|
||||
|
||||
(when (featurep! :completion helm)
|
||||
(package! helm-nixos-options :pin "053a2d5110ce05b7f99bcc2ac4804b70cbe87916"))
|
||||
Reference in New Issue
Block a user