{ config, inputs, lib, localUsername ? lib.my.username, pkgs, this, ... }: with lib; let cfg = config.nixfiles.modules.emacs; in { options.nixfiles.modules.emacs.enable = mkEnableOption "GNU Emacs"; config = mkIf cfg.enable { secrets.authinfo = { file = "${inputs.self}/secrets/authinfo"; owner = localUsername; }; nixfiles.modules = { fonts.enable = true; git.client.enable = true; gnupg.enable = true; password-store.enable = true; profiles.dev.enable = true; profiles.email.enable = true; }; hm = { xdg.configFile = mapAttrs (_: value: value // { onChange = with config.hm.programs; '' export EMACSDIR="''${XDG_CONFIG_HOME:-$HOME/.config}/emacs" export DOOMDIR="''${XDG_CONFIG_HOME:-$HOME/.config}/doom" if [[ ! -d "$EMACSDIR/.git" ]]; then ${getExe git.package} clone --depth=1 --branch=master \ "https://github.com/doomemacs/doomemacs" "$EMACSDIR" fi if [[ ! -d "$DOOMDIR" ]]; then mkdir -p "$DOOMDIR/snippets" fi if [[ -x "$EMACSDIR/bin/doom" ]]; then if [[ ! -d "$EMACSDIR/.local" ]]; then PATH="''${PATH:-/bin:/usr/bin:/usr/local/bin}:${emacs.package}/bin:${git.package}/bin" \ "$EMACSDIR/bin/doom" install --force --verbose fi PATH="''${PATH:-/bin:/usr/bin:/usr/local/bin}:${emacs.package}/bin:${git.package}/bin" \ "$EMACSDIR/bin/doom" sync -e -p --force --verbose fi ''; }) { "doom/init.el".source = ./doom/init.el; "doom/packages.el".source = ./doom/packages.el; "doom/config.el" = { text = concatLines [ ( let # NOTE Packages required for vterm here are mostly only used for # initially compiling the libvterm library. extraBins = with pkgs; [ (aspellWithDicts (p: with p; [en ru])) # :checkers (spell +aspell) asmfmt # :editor format cargo # :lang rust clang-tools # :lang (cc +lsp) :editor format cmake # :lang cc :term vterm cmake-format # :lang cc :editor format cmigemo # :lang japanese dockerfile-language-server-nodejs # :tools (docker +lsp) dockfmt # :tools docker :editor format editorconfig-core-c # :tools editorconfig fd # doom! gcc # :lang cc :term vterm ghc # :lang haskell gnumake # :term vterm gnuplot # :lang (org +gnuplot) gnutls # doom! go # :lang go gocode # :lang go org godef # :lang go gomodifytags # :lang go gopls # :lang (go +lsp) gore # :lang go gotests # :lang go gotools # :lang go graphviz # :lang (org +roam2) :lang plantuml haskellPackages.cabal-fmt # :lang haskell :editor format haskellPackages.cabal-install # :lang haskell haskellPackages.haskell-language-server # :lang (haskell +lsp) haskellPackages.hoogle # :lang haskell haskellPackages.ormolu # :lang haskell :editor format html-tidy # :lang web :editor format jre # :lang plantuml libtool # :term vterm libxml2 # :lang data :editor format nil # :lang (nix +lsp) nodePackages.bash-language-server # :lang (sh +lsp) nodePackages.eslint # :lang (json +lsp) nodePackages.js-beautify # :lang web nodePackages.prettier # :editor format nodePackages.stylelint # :lang web nodejs # :tools debugger pandoc # :lang org markdown latex perl # :term vterm pinentry-emacs # doom! pipenv # :lang python pre-commit # :tools magit python3 # :lang python python3Packages.black # :lang python :editor format python3Packages.isort # :lang python :editor format python3Packages.nose # :lang python python3Packages.pyflakes # :lang python :editor format python3Packages.pytest # :lang python python3Packages.python-lsp-server # :lang python :editor format racket # :lang racket scheme :editor format ripgrep # doom! rust-analyzer # :lang (rust +lsp) rustc # :lang rust rustfmt # :lang rust sbcl # :lang common-lisp 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) zig # :lang zig :editor format zls # :lang (zig +lsp) zstd # :emacs undo ] ++ ( # GDB doesn't support[1] Apple Silicon. # # [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 ); in '' ;; 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 }")) (appendq! auth-sources '(("${config.secrets.authinfo.path}"))) (setq emacsql-sqlite-executable "${getExe pkgs.emacsql-sqlite}") ;; The font must be set to n+2, 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) ;; :app irc (setq circe-default-nick "${my.username}" circe-default-realname "${my.email}" circe-default-user circe-default-nick) ;; :lang plantuml (setq plantuml-jar-path "${pkgs.plantuml}/lib/plantuml.jar" plantuml-executable-path "${getExe' pkgs.plantuml "plantuml"}" org-plantuml-jar-path plantuml-jar-path org-plantuml-executable-path plantuml-executable-path) ;; :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") ;; :lang nix ;; HACK Trick `nix-mode' to use alejandra instead of nixfmt. (setq nix-nixfmt-bin "${pkgs.writeShellScript "nixfmt" '' ${getExe pkgs.alejandra} "$@" ''}") '' ) (with config.hm.accounts.email; let mu4eAccounts = let muAccounts = filter (a: a.mu.enable) (attrValues accounts); in concatMapStringsSep "\n" (a: with a; let personalAddresses = concatMapStringsSep " " (v: ''"${v}"'') aliases; in '' (set-email-account! "${name}" '((user-full-name . "${realName}") (user-mail-address . "${address}") (mu4e-inbox-folder . "/${name}/${folders.inbox}") (mu4e-sent-folder . "/${name}/${folders.sent}") (mu4e-drafts-folder . "/${name}/${folders.drafts}") (mu4e-trash-folder . "/${name}/${folders.trash}") (mu4e-refile-folder . "/${name}/Archive") (+mu4e-personal-addresses . (${personalAddresses}))) t) '') muAccounts; in '' ;; HACK Load missing site-lisp for `mu4e'. (add-to-list 'load-path "${pkgs.mu.mu4e}/share/emacs/site-lisp/mu4e") (setq mu4e-root-maildir "${maildirBasePath}") ${mu4eAccounts} '') (builtins.readFile ./doom/config.el) ]; }; }; programs.emacs = { enable = true; package = (pkgs.emacs29.override (finalAttrs: { stdenv = with pkgs; useMoldLinker (withCFlags ["-O3"] (impureUseNativeOptimizations finalAttrs.stdenv)); })) .overrideAttrs (_: final: { configureFlags = final.configureFlags ++ [ "--without-mailutils" "--without-pop" ]; }); }; }; }; }