summaryrefslogtreecommitdiff
path: root/accounts/gkleen@skadhi/emacs/default.nix
blob: 4cf6b0b9c99c2ad8a5d6b4a5c4742a8eb84cf3f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
{ 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)];
      };
    };
  };
}