about summary refs log tree commit diff
path: root/modules/common/emacs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--modules/common/emacs/default.nix163
-rw-r--r--modules/common/emacs/doom/config.el (renamed from modules/nixfiles/emacs/doom/config.el)14
-rw-r--r--modules/common/emacs/doom/init.el (renamed from modules/nixfiles/emacs/doom/init.el)24
-rw-r--r--modules/common/emacs/doom/packages.el (renamed from modules/nixfiles/emacs/doom/packages.el)2
4 files changed, 184 insertions, 19 deletions
diff --git a/modules/common/emacs/default.nix b/modules/common/emacs/default.nix
new file mode 100644
index 0000000..7395c51
--- /dev/null
+++ b/modules/common/emacs/default.nix
@@ -0,0 +1,163 @@
+{
+  config,
+  inputs,
+  lib,
+  pkgs,
+  pkgsStable,
+  this,
+  ...
+}:
+with lib; let
+  cfg = config.nixfiles.modules.emacs;
+in {
+  options.nixfiles.modules.emacs.enable = mkEnableOption "GNU Emacs";
+
+  config = mkIf cfg.enable {
+    nixfiles.modules = {
+      fonts.enable = true;
+      git.client.enable = true;
+      gnupg.enable = true;
+    };
+
+    hm = {
+      xdg.configFile = {
+        "doom/init.el".source = ./doom/init.el;
+        "doom/packages.el".source = ./doom/packages.el;
+        "doom/config.el" = {
+          text = concatStringsSep "\n" [
+            (let
+              # NOTE gopls will require the "go" executable which must be provided
+              # by the project's flake/shell.
+              extraBins = with pkgs;
+                [
+                  enchant # :checkers (spell +enchant)
+                  (python3.withPackages (p:
+                    with p; [
+                      black # :lang python :editor format
+                      isort # :lang python
+                      pyflakes # :lang python
+                      python-lsp-server # :lang (python +lsp)
+                    ]))
+                  asmfmt # :editor format
+                  bash-language-server # :lang (sh +lsp)
+                  clang-tools # :lang (cc +lsp) :editor format
+                  cmake-format # :lang cc :editor format
+                  cmigemo # :lang japanese
+                  css-language-server # :lang (web +lsp)
+                  dhall-language-server # :lang (dhall +lsp)
+                  dockerfile-language-server # :tools (docker +lsp)
+                  editorconfig # :tools editorconfig
+                  fd # doom!
+                  gnuplot # :lang (org +gnuplot)
+                  gnutls # doom!
+                  go-language-server # :lang (go +lsp)
+                  gomodifytags # :lang go
+                  gore # :lang go
+                  gotests # :lang go
+                  gotools # :lang go
+                  graphviz # :lang (org +roam2) :lang plantuml
+                  html-language-server # :lang (web +lsp)
+                  html-tidy # :lang web
+                  jre # :lang plantuml
+                  json-language-server # :lang (json +lsp)
+                  nix-language-server # :lang (nix +lsp)
+                  nixfmt # :lang nix :editor format
+                  nodePackages.js-beautify # :lang web
+                  nodePackages.prettier # :editor format
+                  nodePackages.stylelint # :lang web
+                  nodejs # :tools debugger
+                  pandoc # :lang org markdown latex
+                  pinentry-emacs # doom!
+                  pre-commit # :tools magit
+                  ripgrep # doom!
+                  rust-analyzer # :lang (rust +lsp)
+                  rustfmt # :lang rust
+                  shellcheck # :lang sh
+                  shfmt # :lang sh :editor format
+                  sqlite # :lang (org +roam2) :tools lookup
+                  texlab # lang (tex +lsp)
+                  texlive.combined.scheme-full # :lang org tex
+                  unzip # :tools debugger
+                  wordnet # :tools (lookup +dictionary +offline)
+                  yaml-language-server # :lang (yaml +lsp)
+                  zls # :lang (zig +lsp)
+                  zstd # :emacs undo
+                ]
+                ++ (
+                  #
+                  # GDB doesn't support[1] Apple Silicon on MacOS.
+                  #
+                  # [1]: https://inbox.sourceware.org/gdb/6b48224b-9e2e-518d-793b-df4fc5514884@arm.com/
+                  if (this.system != "aarch64-darwin")
+                  then [gdb] # :tools debugger
+                  else [lldb] # :tools debugger
+                )
+                ++ optionals (!pkgs.stdenv.isDarwin)
+                [
+                  # NOTE Haskell is pretty much broken every couple of days on
+                  # MacOS and I usually don't write anything in Haskell while
+                  # I'm on my work laptop, so... ShellCheck seems to be working,
+                  # though.
+                  haskellPackages.ormolu # :lang haskell :editor format
+                  haskellPackages.haskell-language-server # :lang (haskell +lsp)
+                  haskellPackages.cabal-fmt # :lang haskell :editor format
+                  haskellPackages.cabal-install # :lang haskell
+                  haskellPackages.hoogle # :lang haskell
+                ];
+            in ''
+              ;; This will integrate packages which are required by various
+              ;; modules without polluting the user's profile.
+              (setq exec-path (append exec-path '(${
+                concatMapStringsSep " " (x: ''"${x}/bin"'') extraBins
+              })))
+              (setenv "PATH" (concat (getenv "PATH") ":${
+                concatMapStringsSep ":" (x: "${x}/bin") extraBins
+              }"))
+
+              ;; Font must be set to N+2 because otherwise it looks too small.
+              (setq doom-font (font-spec :family "${config.fontScheme.monospaceFont.family}"
+                                          :size ${toString (config.fontScheme.monospaceFont.size + 2)})
+                    doom-unicode-font doom-font)
+
+              (setq user-full-name "${my.fullname}"
+                    user-mail-address "${my.email}")
+
+              ;; :app irc
+              (setq circe-default-nick "${my.username}"
+                    circe-default-realname "${my.email}"
+                    circe-default-user circe-default-nick)
+
+              ;; :lang plantuml
+              (setq org-plantuml-jar-path "${pkgs.plantuml}/lib/plantuml.jar")
+
+              ;; :input japanese
+              (setq migemo-dictionary "${pkgs.cmigemo}/share/migemo/utf-8/migemo-dict")
+
+              ;; :input japanese
+              (setq skk-large-jisyo "${pkgs.skk-dicts}/share/skk/SKK-JISYO.L")
+            '')
+            (builtins.readFile ./doom/config.el)
+          ];
+          onChange = with config.hm.programs; ''
+            if [[ -x "''${XDG_CONFIG_HOME:~/.config}/emacs/bin/doom" ]]; then
+               oldpath="$PATH"
+               export PATH="''${PATH:-/bin}:${emacs.package}/bin:${git.package}/bin"
+
+               "''${XDG_CONFIG_HOME:~/.config}/emacs/bin/doom" sync
+
+               export PATH="$oldpath"
+               unset oldpath
+            fi
+          '';
+        };
+      };
+
+      programs.emacs = {
+        enable = true;
+        package = pkgs.emacs28; # Pin to avoid surprises.
+        # For some reason latest libvterm is not picked up by Emacs.
+        extraPackages = _: with pkgsStable.emacsPackages; [vterm];
+      };
+    };
+  };
+}
diff --git a/modules/nixfiles/emacs/doom/config.el b/modules/common/emacs/doom/config.el
index 9fa9984..9284e0b 100644
--- a/modules/nixfiles/emacs/doom/config.el
+++ b/modules/common/emacs/doom/config.el
@@ -1,5 +1,3 @@
-;;; config.el -*- lexical-binding: t; -*-
-
 ;;
 ;;; Misc
 ;;
@@ -80,7 +78,7 @@
 ;;; Haskell
 ;;
 
-(setq lsp-haskell-formatting-provider "brittany")
+(setq lsp-haskell-formatting-provider "ormolu")
 
 ;;
 ;;; Nix
@@ -95,9 +93,17 @@
 
 ;;
 ;;; YAML
-
 ;;
 
+(add-hook! 'yaml-mode-hook
+  (defun +disable-flycheck-for-yaml-helm-templates ()
+    (when (and buffer-file-name
+              (string-match-p "/templates/" buffer-file-name)
+              (or (string-suffix-p ".yaml" buffer-file-name)
+                  (string-suffix-p ".yml" buffer-file-name)))
+      (remove-hook! 'yaml-mode-local-vars-hook #'lsp!)
+      (pushnew! flycheck-disabled-checkers 'yaml-jsyaml 'yaml-ruby 'yaml-yamllint))))
+
 (setq-hook! 'yaml-mode-hook +format-with-lsp nil)
 
 ;;
diff --git a/modules/nixfiles/emacs/doom/init.el b/modules/common/emacs/doom/init.el
index 1016f40..cdab069 100644
--- a/modules/nixfiles/emacs/doom/init.el
+++ b/modules/common/emacs/doom/init.el
@@ -1,5 +1,3 @@
-;;; init.el -*- lexical-binding: t; -*-
-
 (doom! :input
        ;; japanese
 
@@ -12,6 +10,7 @@
        doom
        ;; doom-dashboard
        ;; doom-quit
+       ;; emoji
        hl-todo
        indent-guides
        ;; ligatures
@@ -20,12 +19,10 @@
        ophints
        (popup +defaults)
        ;; tabs
-       ;; (treemacs +lsp)
        ;; unicode
        (vc-gutter +diff-hl +pretty)
        window-select
        workspaces
-       zen
 
        :editor
        (evil +everywhere)
@@ -36,7 +33,7 @@
        ;; multiple-cursors
        parinfer
        ;; rotate-text
-       ;; snippets
+       snippets
        word-wrap
 
        :emacs
@@ -52,10 +49,10 @@
 
        :checkers
        syntax
-       (spell +aspell
+       (spell +enchant
               +everywhere
               +flyspell)
-       ;; grammar
+       grammar
 
        :tools
        ansible
@@ -64,6 +61,7 @@
        (docker +lsp)
        editorconfig
        (eval +overlay)
+       gist
        (lookup +dictionary +offline)
        (lsp +peek)
        (magit +forge)
@@ -72,7 +70,7 @@
        ;; pdf
        terraform
        tree-sitter
-       ;; upload
+       upload
 
        :os
        (:if IS-MAC macos)
@@ -87,10 +85,10 @@
        (emacs-lisp +lsp +tree-sitter)
        (go +lsp +tree-sitter)
        ;; graphql
-       (haskell +lsp +tree-sitter)
+       (:if IS-LINUX (haskell +lsp +tree-sitter))
        (java +lsp +tree-sitter)
        (javascript +lsp +tree-sitter)
-       json
+       (json +lsp +tree-sitter)
        (kotlin +lsp +tree-sitter)
        (latex +lsp +tree-sittter)
        (markdown +lsp +tree-sitter)
@@ -98,13 +96,13 @@
        (org +pandoc +roam2)
        plantuml
        (python +lsp +tree-sitter)
-       (racket +lsp +tree-sitter)
+       (:if IS-LINUX (racket +lsp +tree-sitter))
        ;; rst
        (rust +lsp +tree-sitter)
-       (scheme +lsp +tree-sitter +racket)
+       (:if IS-LINUX (scheme +lsp +tree-sitter +racket))
        (sh +lsp +tree-sitter)
        web
-       yaml
+       (yaml +lsp +tree-sitter)
        (zig +lsp +tree-sitter)
 
        :email
diff --git a/modules/nixfiles/emacs/doom/packages.el b/modules/common/emacs/doom/packages.el
index d3e6354..298a203 100644
--- a/modules/nixfiles/emacs/doom/packages.el
+++ b/modules/common/emacs/doom/packages.el
@@ -1,5 +1,3 @@
-;;; packages.el -*- lexical-binding: t; -*-
-
 (disable-packages! writegood-mode)
 
 (unpin! org-roam)

Consider giving Nix/NixOS a try! <3