{ pkgs, lib, config, sources, ... }: let editor = pkgs.symlinkJoin { name = "${config.services.emacs.package.name}-editor"; buildInputs = with pkgs; [ makeWrapper ]; paths = [ config.services.emacs.package ]; postBuild = '' wrapProgram $out/bin/emacsclient \ --inherit-argv0 \ --add-flags ${lib.escapeShellArg (lib.escapeShellArgs config.services.emacs.client.arguments)} ''; }; in { config = { home.persistence."/persistent".directories = [ ".local/state/emacs/saves" ".local/state/emacs/undo" ]; programs.emacs = { enable = true; package = pkgs.emacs-pgtk; extraPackages = epkgs: with epkgs; [ evil evil-dvorak undo-tree magit haskell-tng-mode nix-mode yaml-mode json-mode shakespeare-mode smart-mode-line highlight-parentheses highlight-symbol ag sass-mode lua-mode fira-code-mode use-package wanderlust # notmuch git-gutter scratch edit-server mediawiki editorconfig typescript-mode markdown-mode nftables-mode rustic lsp-mode lsp-ui direnv company projectile tomorrow-night-paradise-theme treesit-grammars.with-all-grammars magit-delta scad-mode typst-ts-mode ]; overrides = self: super: { tomorrow-night-paradise-theme = super.trivialBuild { inherit (sources.tomorrow-night-paradise-theme) pname version src; }; scratch = pkgs.stdenv.mkDerivation { inherit (sources.emacs-scratch_el) pname version src; phases = [ "unpackPhase" "installPhase" ]; installPhase = '' install -Dt $out/share/emacs/site-lisp scratch.el ''; }; }; }; xdg.configFile."emacs/init.el".source = pkgs.substitute { src = ./emacs.el; substitutions = [ "--subst-var-by" "ksshaskpass" (lib.getExe pkgs.kdePackages.ksshaskpass) ]; }; home.sessionVariables.EDITOR = lib.getExe' editor "emacsclient"; services.emacs = { enable = true; socketActivation.enable = true; client = { enable = true; arguments = lib.mkForce ["--create-frame" "--alternate-editor" (lib.getExe config.services.emacs.package)]; }; }; }; }