diff --git a/build-helpers/full-init b/build-helpers/full-init index 46e85d4..eae7e02 100755 --- a/build-helpers/full-init +++ b/build-helpers/full-init @@ -15,9 +15,21 @@ ;; See the License for the specific language governing permissions and ;; limitations under the License. +;; Simple recursive walk of packages.el to extract (modulep! +flag) +;; +;; Does not cover (modulep! :cat mod +flag). That is: assumes each flag is +;; referenced at least once by shortened form in the module itself. +;; +;; No attempt at efficiency, but package.el files are small... + +(defun walk-package-exp (l) + (cond ((not (consp l)) nil) + ((and (= 2 (length l)) (eq 'modulep! (car l))) (cdr l)) + (t (mapcan #'walk-package-exp l)))) + (defcli! full-init ((output-directory ("-o" dir) "Directory to write init.el into.") - (&flag full? ("--full"))) + (&flag flags? ("--flags"))) "Write init.el with all modules." (with-temp-buffer (insert ";;; init.el -*- no-byte-compile: t; -*- @@ -30,8 +42,18 @@ (let ((cat (car kp)) (name (cdr kp))) (when name - (if full? - (error "unimplemented") + (if-let ((flags?) + (packages-path (doom-module-locate-path + cat name doom-module-packages-file)) + (tree (with-temp-buffer + (insert "(\n") + (insert-file-contents packages-path) + (goto-char (point-max)) + (insert ")\n") + (goto-char (point-min)) + (read (current-buffer)))) + (flags (walk-package-exp tree))) + (insert (format " %s %s\n" cat (cons name flags))) (insert (format " %s %s\n" cat name)))))) (insert ")\n") (write-region nil nil (expand-file-name "init.el" output-directory)))) diff --git a/checks.nix b/checks.nix index 6e680f8..07d6d0c 100644 --- a/checks.nix +++ b/checks.nix @@ -37,7 +37,8 @@ let mkDoom = args: (makeDoomPackages (common // args)).doomEmacs; mkDoomDir = args: writeTextDir "init.el" (toInit args); minimalDoomDir = mkDoomDir { config = [ "default" ]; }; - fullDoomDir = (makeDoomPackages (common // { doomDir = emptyDirectory; })).doomDirWithAllModules; + 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"; @@ -66,7 +67,8 @@ in { minimalEmacs = (makeDoomPackages (common // { doomDir = minimalDoomDir; })).emacsWithDoom; - full = mkDoom { doomDir = fullDoomDir; }; + allModules = mkDoom { doomDir = allModsDoomDir; }; + allModulesAndFlags = mkDoom { doomDir = allFlagsDoomDir; }; example = mkDoom { doomDir = ./doomdirs/example; }; example-without-loader = mkDoom { doomDir = ./doomdirs/example; diff --git a/default.nix b/default.nix index ab543d7..e460f7e 100644 --- a/default.nix +++ b/default.nix @@ -71,6 +71,22 @@ let ${runtimeShell} ${doomSource}/bin/doomscript ${./build-helpers/full-init} -o $out ''; + doomDirWithAllModulesAndFlags = runCommandLocal "doom-full-init" + { + env = { + EMACS = lib.getExe emacs; + # Enable this to troubleshoot failures at this step. + #DEBUG = "1"; + }; + # We set DOOMLOCALDIR somewhere harmless below to stop Doom from trying to + # create it somewhere read-only. + } '' + mkdir $out + export DOOMLOCALDIR=$(mktemp -d) + ${runtimeShell} ${doomSource}/bin/doomscript ${./build-helpers/full-init} --flags -o $out + ''; + + # Step 1: determine which Emacs packages to pull in. # # Inputs: Doom, original DOOMDIR (only init.el and packages.el are used). @@ -426,5 +442,5 @@ let ''; in { - inherit doomDirWithAllModules doomEmacs emacsWithDoom; + inherit doomDirWithAllModules doomDirWithAllModulesAndFlags doomEmacs emacsWithDoom; }