aboutsummaryrefslogtreecommitdiff
path: root/gui/emacs.nix
blob: 8d3e1238917ef6811e3a51b5a62434263ca69e1c (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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
{ config, pkgs, ... }:

{
  programs.emacs = let
    akr-color-theme = pkgs.stdenv.mkDerivation {
      name = "emacs-color-theme-akr";
      src = ./conf/metakr.org;
      phases = [ "installPhase" ];
      installPhase = ''
        cp $src metakr.org
        ${pkgs.emacs}/bin/emacs --batch --eval "(require 'org)" --eval "(setq org-confirm-babel-evaluate nil)" --eval '(org-babel-tangle-file "metakr.org")'
        rm metakr.org
        mkdir -p $out/share/emacs/site-lisp
        mv akr-theme.el $out/share/emacs/site-lisp/
      '';
    };

    custom-runtime-env-el = let
      tex = pkgs.texlive.combine {
        inherit (pkgs.texlive) scheme-full dvipng;
      };
    in pkgs.writeTextFile {
      name = "custom-runtime-env.el";
      text = ''
        (setenv "PATH" (concat (getenv "PATH")
                               ":${tex}/bin:${pkgs.pandoc}/bin:${pkgs.bibtex2html}/bin"))
        (add-to-list 'exec-path "${tex}/bin")
        (add-to-list 'exec-path "${pkgs.graphviz}/bin")
        (add-to-list 'exec-path "${pkgs.gnuplot}/bin")
        (add-to-list 'exec-path "${pkgs.sqlite}/bin")
        (add-to-list 'exec-path "${pkgs.universal-ctags}/bin")
        (add-to-list 'exec-path "${pkgs.global}/bin")
        (add-to-list 'exec-path "${pkgs.pandoc}/bin")
      '';
    };

    custom-runtime-env = pkgs.stdenv.mkDerivation {
      name = "emacs-custom-runtime-env";
      phases = [ "installPhase" ];

      installPhase = ''
        mkdir -p $out/share/emacs/site-lisp
        cp ${custom-runtime-env-el} $out/share/emacs/site-lisp/custom-runtime-env.el
      '';
    };
  in {
    enable = true;

    package = pkgs.emacsWithPackagesFromUsePackage {
      override = final: prev: {
        org = prev.org.overrideAttrs(old: { patches = []; } );
      };

      package = pkgs.emacs-unstable-pgtk;

      config = ./conf/init.el;
      alwaysEnsure = false;

      extraEmacsPackages = epkgs: (with epkgs.melpaPackages; [
        pdf-tools
        mu4e-alert
      ]) ++ (with epkgs.elpaPackages; [
        auctex
      ]) ++ (with epkgs.nongnuPackages; [
        org-contrib
      ])++ [
        epkgs.mu4e
        akr-color-theme
        custom-runtime-env
      ];
    };
  };

  home.packages = let
    org-protocol-shortcut = pkgs.writeTextFile {
      name        = "org-protocol";
      executable  = false;
      destination = "/share/applications/org-protocol.desktop";
      text = ''
        [Desktop Entry]
        Name=Emacs (Client, Protocol)
        Keywords=org-protocol;
        Icon=emacs
        Type=Application
        Exec=emacsclient -- %u
        Terminal=false
        StartupWMClass=Emacs
        MimeType=x-scheme-handler/org-protocol;
      '';
    };

    org-capture-todo = pkgs.writeScriptBin "org-capture-todo" ''
      #!/usr/bin/env bash
      emacsclient -c -e '(custom/org-capture-frame "t")' -F '((name . "**Capture**"))'
    '';
    org-show-agenda = pkgs.writeScriptBin "org-show-agenda" ''
      #!/usr/bin/env bash
      emacsclient -c -e '(custom/org-agenda-frame "a")' -F '((name . "**Agenda**"))'
    '';

  in with pkgs; [
    symbola
    (iosevka-bin.override { variant = "Aile"; })
    (iosevka-bin.override { variant = "Etoile"; })
    mu

    org-protocol-shortcut
    org-capture-todo
    org-show-agenda
  ];

  home.file.".emacs.d/init.el".source = config.lib.file.mkOutOfStoreSymlink "${config.home.homeDirectory}/dotfiles/home/gui/conf/init.el";

  systemd.user.services.emacs.Service.ExecStart = pkgs.lib.mkForce "${pkgs.runtimeShell} -l -c 'exec emacs --fg-daemon'";

  services.emacs = {
    enable = true;
  };

  xdg.desktopEntries.org-capture-todo = {
    name = "Org Capture: TODO";
    comment = "Capture new todo using Emacs org-mode";
    exec = "org-capture-todo";
    terminal = false;
    type = "Application";
  };

  xdg.desktopEntries.org-show-agenda = {
    name = "Org Agenda";
    comment = "Show today's agenda";
    exec = "org-show-agenda";
    terminal = false;
    type = "Application";
  };
}