Skip to content

Commit

Permalink
feat: use twist lib to byte compile init files
Browse files Browse the repository at this point in the history
  • Loading branch information
terlar committed Oct 28, 2024
1 parent abd73ed commit f571ea1
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 52 deletions.
46 changes: 21 additions & 25 deletions default.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
lib,
stdenv,
trivialBuild,
buildElispPackage,
elispInputs,
emacs-all-the-icons-fonts,
emacsPackages,
iosevka-bin,
Expand All @@ -11,41 +12,36 @@
let
tree-sitter = emacsPackages.treesit-grammars.with-all-grammars;

init = trivialBuild {
pname = "config-init";
version = "1";
init = buildElispPackage {
ename = "config-init";

src = lib.sourceByRegex ./. [ "init.org" ];
files = [ "init.org" ];
lispFiles = [
"early-init.el"
"init.el"
];

inherit elispInputs;
nativeCompileAhead = true;
wantExtraOutputs = false;
errorOnWarn = true;
doTangle = false;

preBuild = ''
export HOME="$NIX_BUILD_TOP/.home"
mkdir -p "$HOME/.config/emacs"
emacs --batch --quick \
--load org \
*.org \
--funcall org-babel-tangle
'';

buildPhase = ''
runHook preBuild
export HOME="$(mktemp -d)"
rm *.org
mkdir -p "$HOME/.emacs.d"
ln -s ${tree-sitter}/lib "$HOME/.emacs.d/tree-sitter"
emacs --batch --quick \
--eval '(setq byte-compile-error-on-warn t)' \
--funcall batch-byte-compile \
*.el
runHook postBuild
ln -s ${tree-sitter}/lib "$HOME/.config/emacs/tree-sitter"
'';

# Temporary hack because the Emacs native load path is not respected.
fixupPhase = ''
if [ -d "$HOME/.emacs.d/eln-cache" ]; then
mv $HOME/.emacs.d/eln-cache/* $out/share/emacs/native-lisp
fi
'';
meta = { };
};
in
stdenv.mkDerivation {
Expand Down
11 changes: 7 additions & 4 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,14 @@
);

emacs-config = prev.callPackage inputs.self {
trivialBuild = final.emacsPackages.trivialBuild.override {
emacs = final.emacs-env.overrideScope (
_: tprev: { inherit (tprev.emacs) meta withNativeCompilation; }
);
buildElispPackage = (inputs.twist.lib.buildElispPackage final).override {
emacs = emacsPackage;
};

elispInputs = prev.lib.pipe final.emacs-env.elispPackages [
builtins.attrValues
(builtins.filter prev.lib.isDerivation)
];
};
}
)
Expand Down
13 changes: 0 additions & 13 deletions nix/inputOverrides.nix
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
{ lib, ... }:
{
bbdb = _: prev: {
files =
(builtins.removeAttrs prev.files [
# Unused integrations.
"lisp/bbdb-notmuch.el"
"lisp/bbdb-vm.el"
"lisp/bbdb-vm-aux.el"
])
// {
"lisp/bbdb-site.el.in" = "bbdb-site.el.in";
};
};

ghelp = _: prev: {
files = builtins.removeAttrs prev.files [
# Unused integrations.
Expand Down
10 changes: 0 additions & 10 deletions nix/packageOverrides.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,6 @@
unzip,
}:
_final: prev: {
bbdb = prev.bbdb.overrideAttrs (old: {
preBuild = ''
substituteInPlace bbdb-site.el.in \
--replace "@pkgdatadir@" $out/share/emacs/site-lisp/tex/ \
--replace "@PACKAGE_VERSION@" ${old.version};
mv bbdb-site.el{.in,}
'';
});

jinx = prev.jinx.overrideAttrs (
old:
let
Expand Down

0 comments on commit f571ea1

Please sign in to comment.