nixos-config/home-manager/modules/emacs/default.nix

90 lines
2.2 KiB
Nix

{ pkgs
, config
, lib
, ...
}:
with lib; let
cfg = config.eboskma.programs.emacs;
tangleEmacsConfig = initFile: pkgs.runCommand "tangled-emacs-${initFile}" { } ''
cp ${./config.org} ./config.org
${cfg.package}/bin/emacs --batch --quick --load org ./config.org --funcall org-babel-tangle
cp ${initFile} $out
'';
emacsWithPackages = pkgs.emacsWithPackagesFromUsePackage {
config =
let
tangledOrgConfig = tangleEmacsConfig "init.el";
in
builtins.readFile tangledOrgConfig;
defaultInitFile = true;
package = cfg.package;
alwaysEnsure = true;
alwaysTangle = true;
extraEmacsPackages = epkgs: [
epkgs.emacsql
epkgs.emacsql-sqlite
];
};
orgProtocolDesktop = pkgs.makeDesktopItem {
name = "org-protocol";
desktopName = "Emacs Org Protocol Handler";
icon = "emacs";
categories = [ "Development" "TextEditor" ];
keywords = [ "org-protocol" ];
type = "Application";
exec = "${emacsWithPackages}/bin/emacsclient -- %u";
terminal = false;
mimeTypes = [ "x-scheme-handler/org-protocol" ];
startupWMClass = "Emacs";
};
in
{
options.eboskma.programs.emacs = {
enable = mkEnableOption "activate emacs";
package = mkPackageOption pkgs "emacs" { };
daemon = mkOption {
description = "Whether to enable emacs daemon";
type = types.bool;
default = true;
example = false;
};
};
config = mkIf cfg.enable {
programs.emacs = {
enable = true;
package = emacsWithPackages;
};
services.emacs = mkIf cfg.daemon {
enable = true;
package = emacsWithPackages;
client.enable = true;
socketActivation.enable = true;
};
home.file."emacs.d/early-init.el".source = tangleEmacsConfig "early-init.el";
home.packages = with pkgs; [
(texlive.combine {
inherit (texlive) scheme-small wrapfig ulem capt-of;
})
orgProtocolDesktop
nodePackages.bash-language-server
aspell
nil
nixpkgs-fmt
python3
lldb
] ++
(with aspellDicts; [ en en-computers en-science fy nl ]) ++
(lib.optional (versionOlder cfg.package.version "29") (tree-sitter.withPlugins builtins.attrValues));
};
}