From e41bb2e0e569f5404e412080a34bd15471a4eb53 Mon Sep 17 00:00:00 2001 From: Marien Zwart Date: Thu, 25 Apr 2024 16:09:42 +1000 Subject: [PATCH] Use doomscript instead of cli.el for dumping Removes the need to build a stage1 DOOMDIR, we can just use the user's DOOMDIR directly. The same approach should work for the next stage, removing the need to leave our cli.el in the final DOOMDIR. --- cli1.el => build-helpers/dump | 9 +++++++-- doom.nix | 14 ++++---------- 2 files changed, 11 insertions(+), 12 deletions(-) rename cli1.el => build-helpers/dump (90%) diff --git a/cli1.el b/build-helpers/dump similarity index 90% rename from cli1.el rename to build-helpers/dump index e4c44ea..1092531 100755 --- a/cli1.el +++ b/build-helpers/dump @@ -1,11 +1,14 @@ -;;; cli.el -*- lexical-binding: t; -*- +#!/usr/bin/env doomscript +;; -*- lexical-binding: t; -*- (require 'json) -(defcli! dump-for-nix-build +(defcli! dump ((output-directory ("-o" dir) "Directory to dump into.") (&flag full? ("--full"))) "Dump intermediates for nix-doom-emacs-unstraightened." + ;; Load the user's init.el, or we'll dump only core packages. + (load! doom-module-init-file doom-user-dir t) (let* ((all-packages (doom-package-list full?)) ;; For built-in packages, the :ignore property is the location of the ;; built-in library, which is a Nix store path. We do not want that @@ -49,3 +52,5 @@ (when (not (plist-get p :disable)) (insert "(package! " (symbol-name (car kp)) " :ignore t)\n")))) (write-region nil nil (expand-file-name "packages.el" output-directory))))) + +(run! "dump" (cdr (member "--" argv))) diff --git a/doom.nix b/doom.nix index f97af34..0a13381 100644 --- a/doom.nix +++ b/doom.nix @@ -38,25 +38,19 @@ makeBinaryWrapper, }: let - inherit (lib) optional optionalAttrs optionalString; + inherit (lib) optionalAttrs optionalString; doomInitFile = "${doomDir}/init.el"; - doomPrivateModule = "${doomDir}/packages.el"; # Step 1: determine which Emacs packages to pull in. # - # Inputs: unpatched Doom, a DOOMDIR with the provided init.el and packages.el. + # Inputs: Doom, original DOOMDIR (only init.el and packages.el are used). # Outputs: # - Packages Doom normally loads using Straight (as json) # - modified packages.el that claims all packages are system-installed # # Uses Doom's CLI framework, which does not require anything else is installed # (not even straight). - stage1DoomDir = linkFarm "doom-dir-stage1" ( - [{ name = "cli.el"; path = ./cli1.el; }] - ++ optional (lib.pathExists doomInitFile) { name = "init.el"; path = doomInitFile; } - ++ optional (lib.pathExists doomPrivateModule) { name = "packages.el"; path = doomPrivateModule; } - ); # XXX this may need to be runCommandLocal just in case conditionals an init.el # / packages.el evaluate differently on build systems. @@ -64,7 +58,7 @@ let { env = { EMACS = lib.getExe emacs; - DOOMDIR = stage1DoomDir; + DOOMDIR = "${doomDir}"; # Enable this to troubleshoot failures at this step. #DEBUG = "1"; }; @@ -73,7 +67,7 @@ let } '' mkdir $out export DOOMLOCALDIR=$(mktemp -d) - ${runtimeShell} ${doomSource}/bin/doom dump-for-nix-build \ + ${runtimeShell} ${doomSource}/bin/doomscript ${./build-helpers/dump} \ ${optionalString full "--full"} -o $out '';