{ config, pkgs, lib, ... }: let doom-pkgs = with pkgs; [ fira fira-code-nerdfont emacs-all-the-icons-fonts ]; doom-path-pkgs = with pkgs; [ (ripgrep.override {withPCRE2 = true;}) binutils cmake editorconfig-core-c fd gcc git gnumake gnutls imagemagick ispell libtool mermaid-filter mlocate nodejs pandoc pandoc-katex python311Packages.grip zstd ]; wrapped-emacs = pkgs.symlinkJoin { name = "wrapped-emacs"; paths = [pkgs.emacs29]; nativeBuildInputs = [pkgs.makeBinaryWrapper]; postBuild = '' wrapProgram $out/bin/emacs \ --prefix PATH : ${lib.makeBinPath doom-path-pkgs} \ --add-flags "--init-directory=${config.xdg.configHome}/doom-emacs" \ --set DOOMDIR "${config.home.sessionVariables.DOOMDIR}" \ --set DOOMLOCALDIR "${config.home.sessionVariables.DOOMLOCALDIR}" wrapProgram $out/bin/emacsclient \ --prefix PATH : ${lib.makeBinPath doom-path-pkgs} \ --set DOOMDIR "${config.home.sessionVariables.DOOMDIR}" \ --set DOOMLOCALDIR "${config.home.sessionVariables.DOOMLOCALDIR}" ''; }; doom-setup = pkgs.writeShellScript "doom-setup" '' export PATH="$PATH:${lib.makeBinPath doom-path-pkgs}" export EMACS="${wrapped-emacs}/bin/emacs" export DOOMDIR="${config.home.sessionVariables.DOOMDIR}" export DOOMLOCALDIR="${config.home.sessionVariables.DOOMLOCALDIR}" if [ ! -d "$DOOMLOCALDIR" ]; then ${config.xdg.configHome}/doom-emacs/bin/doom install --force --no-env else ${config.xdg.configHome}/doom-emacs/bin/doom "$@" fi ''; in { programs.emacs = { enable = true; package = wrapped-emacs; }; home = { sessionPath = ["${config.xdg.configHome}/doom-emacs/bin"]; sessionVariables = { DOOMDIR = "${config.xdg.configHome}/doom-config"; DOOMLOCALDIR = "${config.xdg.configHome}/doom-local"; }; }; xdg = { enable = true; configFile = { "doom-config/splash.png" = { source = ./static/doom-config/splash.png; }; "doom-config/config.el" = { source = ./static/doom-config/config.el; }; "doom-config/init.el" = { source = ./static/doom-config/init.el; onChange = "${doom-setup} sync --force -e"; }; "doom-config/packages.el" = { source = ./static/doom-config/packages.el; onChange = "${doom-setup} sync --force -u -e"; }; "doom-emacs" = { source = builtins.fetchGit { url = "https://github.com/doomemacs/doomemacs"; rev = "9620bb45ac4cd7b0274c497b2d9d93c4ad9364ee"; }; onChange = "${doom-setup} --force sync -u -e"; }; }; desktopEntries = { emacs = { name = "Doom Emacs"; genericName = "Text Editor"; icon = ./static/doom-config/icon.png; exec = "${wrapped-emacs}/bin/emacs %F"; terminal = false; categories = ["Application" "Development" "TextEditor"]; mimeType = ["text/*"]; settings = { StartupWMClass = "Doom Emacs"; }; }; emacsclient = { name = "Doom Emacs (Client)"; genericName = "Text Editor"; icon = ./static/doom-config/icon.png; exec = '' sh -c "if [ -n \\"\\$*\\" ]; then exec ${wrapped-emacs}/bin/emacsclient --alternate-editor= --display=\\"\\$DISPLAY\\" \\"\\$@\\"; else exec emacsclient --alternate-editor= --create-frame; fi" sh %F ''; terminal = false; categories = ["Application" "Development" "TextEditor"]; mimeType = ["text/*"]; settings = { StartupWMClass = "Doom Emacs"; }; }; }; }; home.packages = doom-pkgs; }