nix-doom-emacs-unstraightened/cli.el
Marien Zwart c50ceed902
Fix :files handling
Exposes what I think is a pre-existing problem with too many directories
getting added to load-path, because we now install a directory
containing a file named "default" that was previously omitted.
2024-03-05 22:23:40 +11:00

32 lines
1.5 KiB
EmacsLisp
Executable file

;;; cli.el -*- lexical-binding: t; -*-
(require 'json)
(doom-require 'doom-cli 'packages)
(defcli! dump-for-nix-build
((output-directory ("-o" dir) "Directory to dump into.")
(&flag full? ("--full")))
"Dump intermediates for nix-doom-emacs-unstraightened."
(let* ((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
;; path to escape: avoid it by just filtering ignored packages here.
(packages (seq-remove (lambda (p) (plist-get (cdr p) :ignore)) packages))
;; For recipes with :files, print it to a string before json-encode.
;; Otherwise it is serialized as a plist if it starts with :defaults.
;; We either ignore this or pass it to melpa2nix in a recipe.
(packages
(mapcar (lambda (p)
(let* ((plist (cdr p))
(recipe (plist-get plist :recipe))
(files (plist-get recipe :files)))
(when files
(setcdr p
(plist-put plist :recipe
(plist-put recipe :files
(prin1-to-string files)))))
p))
packages))
(json (json-encode packages))
(json-path (expand-file-name "packages.json" output-directory)))
(write-region json nil json-path)))