about summary refs log tree commit diff
path: root/users/sterni/emacs/default.nix
blob: 9ff7da3812b63a5f3e77350d6c2629e3f010f5b6 (plain) (blame)
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
{ depot, pkgs, lib, ... }:

let
  inherit (pkgs.stdenv.hostPlatform) is64bit;

  # emacsPgtk is defined in emacs-overlay
  emacs = (pkgs.emacsPackagesFor pkgs.emacsPgtk).withPackages (epkgs: [
    epkgs.bqn-mode
    #epkgs.elpaPackages.ada-mode
    epkgs.elpaPackages.rainbow-mode
    epkgs.elpaPackages.undo-tree
    epkgs.elpaPackages.which-key
    epkgs.melpaPackages.adoc-mode
    epkgs.melpaPackages.cmake-mode
    epkgs.melpaPackages.direnv
    epkgs.melpaPackages.dockerfile-mode
    epkgs.melpaPackages.editorconfig
    epkgs.melpaPackages.elfeed
    epkgs.melpaPackages.evil
    epkgs.melpaPackages.evil-collection
    epkgs.melpaPackages.flycheck
    epkgs.melpaPackages.haskell-mode
    epkgs.melpaPackages.hl-todo
    epkgs.melpaPackages.jq-mode
    epkgs.melpaPackages.lsp-haskell
    epkgs.melpaPackages.lsp-mode
    epkgs.melpaPackages.lsp-ui
    epkgs.melpaPackages.magit
    epkgs.melpaPackages.markdown-mode
    epkgs.melpaPackages.meson-mode
    epkgs.melpaPackages.nix-mode
    epkgs.melpaPackages.org-clock-csv
    epkgs.melpaPackages.paredit
    epkgs.melpaPackages.rainbow-delimiters
    epkgs.melpaPackages.sly
    epkgs.melpaPackages.use-package
    epkgs.melpaPackages.yaml-mode
    epkgs.rust-mode
    epkgs.tvlPackages.tvl
    epkgs.urweb-mode
  ] ++ lib.optionals is64bit [
    epkgs.melpaPackages.languagetool
  ]);

  configDirectory = pkgs.symlinkJoin {
    name = "emacs.d";
    paths = [
      ./.
      (pkgs.writeTextFile {
        name = "injected-emacs.d";
        destination = "/nix-inject.el";
        text =
          # Java doesn't seem to be available for non 64bit platforms in nixpkgs
          # CBQN doesn't seem to support i686 at least
          lib.optionalString is64bit ''
            ;; bqn-mode
            (setq bqn-interpreter-path "${pkgs.cbqn}/bin/BQN")

            ;; languagetool
            (setq languagetool-java-bin "${pkgs.jre}/bin/java"
                  languagetool-console-command "${pkgs.languagetool}/share/languagetool-commandline.jar"
                  languagetool-server-command "${pkgs.languagetool}/share/languagetool-server.jar")
          '' + ''

            ;; use bash instead of fish from SHELL for some things, as it plays
            ;; nicer with TERM=dumb, as I don't need/want vterm anyways.
            ;; We want it to source /etc/profile for some extra setup that
            ;; kicks in if TERM=dumb, meaning we can't use dash/sh mode.
            (setq shell-file-name "${pkgs.bash}/bin/bash"
                  explicit-bash-args '("-l"))

            (provide 'nix-inject)
        '';
      })
    ];
    postBuild = ''
      rm "$out/default.nix"
    '';
  };
in

# sadly we can't give an init-file via the command line
(pkgs.writeShellScriptBin "emacs" ''
  exec ${emacs}/bin/emacs          \
    --no-init-file                 \
    --directory ${configDirectory} \
    --eval "(require 'init)"       \
    "$@"
'').overrideAttrs (super: {
  buildCommand = ''
    ${super.buildCommand}

    ln -s "${emacs}/bin/emacsclient" "$out/bin/emacsclient"
  '';
})