Refactor full init.el building

This commit is contained in:
Marien Zwart 2024-06-01 20:37:09 +10:00
parent 9d01c40caf
commit b16774f129
No known key found for this signature in database
4 changed files with 46 additions and 27 deletions

View file

@ -0,0 +1,34 @@
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
{
callPackage,
doomSource,
emacs,
}:
{
doomDirWithAllModules = callPackage ./doomscript.nix {
name = "doom-full-init";
inherit doomSource emacs;
script = ./full-init;
scriptArgs = "-o $out";
};
doomDirWithAllModulesAndFlags = callPackage ./doomscript.nix {
name = "doom-full-init";
inherit doomSource emacs;
script = ./full-init;
scriptArgs = "--flags -o $out";
};
}

View file

@ -13,6 +13,7 @@
# limitations under the License.
{
callPackages,
emptyDirectory,
lib,
linkFarm,
@ -22,11 +23,14 @@
writeText,
writeTextDir,
doomSource,
makeDoomPackages,
toInit,
}:
let
inherit (lib.generators) toPretty;
inherit (callPackages ./build-helpers/full-init.nix { inherit doomSource; })
doomDirWithAllModules doomDirWithAllModulesAndFlags;
common = {
doomLocalDir = "~/.local/share/nix-doom-unstraightened";
experimentalFetchTree = true;
@ -34,8 +38,6 @@ let
mkDoom = args: (makeDoomPackages (common // args)).doomEmacs;
mkDoomDir = args: writeTextDir "init.el" (toInit args);
minimalDoomDir = mkDoomDir { config = [ "default" ]; };
allModsDoomDir = (makeDoomPackages (common // { doomDir = emptyDirectory; })).doomDirWithAllModules;
allFlagsDoomDir = (makeDoomPackages (common // { doomDir = emptyDirectory; })).doomDirWithAllModulesAndFlags;
doomTest = name: init: doomArgs: testers.testEqualContents {
assertion = "name = ${name}; modules = ${toPretty {} init}; args = ${toPretty {} doomArgs};";
expected = writeText "doom-expected" "Doom functions";
@ -68,8 +70,8 @@ in {
doomDir = minimalDoomDir;
extraPackages = epkgs: [ epkgs.vterm epkgs.treesit-grammars.with-all-grammars ];
};
allModules = mkDoom { doomDir = allModsDoomDir; };
allModulesAndFlags = mkDoom { doomDir = allFlagsDoomDir; };
allModules = mkDoom { doomDir = doomDirWithAllModules; };
allModulesAndFlags = mkDoom { doomDir = doomDirWithAllModulesAndFlags; };
example = mkDoom { doomDir = ./doomdir; };
example-without-loader = mkDoom {
doomDir = ./doomdir;

View file

@ -56,22 +56,6 @@ let
inherit (lib) optionalAttrs optionalString;
inherit (import ./fetch-overrides.nix) extraPins extraUrls;
# This doesn't belong here: it does not depend on doomDir (only on doomSource).
# But this is where all my doomscript execution lives.
doomDirWithAllModules = callPackage ./build-helpers/doomscript.nix {
name = "doom-full-init";
inherit doomSource emacs;
script = ./build-helpers/full-init;
scriptArgs = "-o $out";
};
doomDirWithAllModulesAndFlags = callPackage ./build-helpers/doomscript.nix {
name = "doom-full-init";
inherit doomSource emacs;
script = ./build-helpers/full-init;
scriptArgs = "--flags -o $out";
};
# Step 1: determine which Emacs packages to pull in.
#
# Inputs: Doom, original DOOMDIR (only init.el and packages.el are used).
@ -419,5 +403,5 @@ let
'';
in
{
inherit doomDirWithAllModules doomDirWithAllModulesAndFlags doomEmacs emacsWithDoom;
inherit doomEmacs emacsWithDoom;
}

View file

@ -77,6 +77,7 @@
in {
checks = perSystemPackages (pkgs: pkgs.callPackages ./checks.nix {
inherit toInit;
doomSource = doomemacs;
makeDoomPackages = doomFromPackages pkgs;
});
packages = perSystemPackages (pkgs: {
@ -91,17 +92,15 @@
}).doomEmacs;
# TODO: cache more packages, cache for more Emacsen.
cachix-packages = let
# (Shouldn't need doomFromPackages, see doomDirWithAllModules definition)
fullDoomDir = (doomFromPackages pkgs {
doomDir = pkgs.emptyDirectory;
doomLocalDir = "~/.local/share/nix-doom-unstraightened";
}).doomDirWithAllModules;
inherit (pkgs.callPackages ./build-helpers/full-init.nix {
doomSource = doomemacs;
}) doomDirWithAllModules;
in
pkgs.linkFarm "unstraightened-cachix-packages" {
inherit doomemacs;
full-emacs29 = (doomFromPackages pkgs {
emacs = pkgs.emacs29;
doomDir = fullDoomDir;
doomDir = doomDirWithAllModules;
doomLocalDir = "~/.local/share/nix-doom-unstraightened";
experimentalFetchTree = true;
}).doomEmacs.emacsWithPackages.deps;