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.
This commit is contained in:
Marien Zwart 2024-03-05 22:23:40 +11:00
parent ad3ddef70b
commit c50ceed902
No known key found for this signature in database
3 changed files with 52 additions and 19 deletions

15
cli.el
View file

@ -12,6 +12,21 @@
;; built-in library, which is a Nix store path. We do not want that ;; 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. ;; path to escape: avoid it by just filtering ignored packages here.
(packages (seq-remove (lambda (p) (plist-get (cdr p) :ignore)) packages)) (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 (json-encode packages))
(json-path (expand-file-name "packages.json" output-directory))) (json-path (expand-file-name "packages.json" output-directory)))
(write-region json nil json-path))) (write-region json nil json-path)))

View file

@ -4,6 +4,7 @@
esuper, esuper,
git, git,
makeWrapper, makeWrapper,
writeText,
}: }:
{ {
# Doom uses using emacs-straight/auctex, which still contains parts of # Doom uses using emacs-straight/auctex, which still contains parts of
@ -98,4 +99,35 @@
description = "build cmake-mode from emacsmirror for Doom"; description = "build cmake-mode from emacsmirror for Doom";
}; };
}; };
# Doom uses a recipe with :files (:defaults "*"), which MELPA's package-build
# rejects because it includes dotfiles
# (https://github.com/melpa/package-build/pull/67).
# Use a melpaBuild here so the package ends up in its own directory:
# it uses that directory as a snippets directory, and using site-lisp/ as that
# might go wrong.
#
# XXX this results in all snippets directories being added to load-path...
# This makes a mess (`(load "default")` ends up loading a snippet...).
#
# Does not look doom-snippets-specific, I also have
#
# /nix/store/...-emacs-packages-deps/share/emacs/site-lisp/elpa/ansible-20240212.325/snippets/text-mode/ansible/f5
#
# and so forth.
doom-snippets = esuper.melpaBuild {
pname = "doom-snippets";
version = "1";
# melpa2nix requires that we set this. TODO: set correctly.
commit = "unset";
meta = {
description = "trivial build of doom-snippets";
};
# The directories we want to match must be mode names: assume those are
# sensibly named (they currently are).
recipe = writeText "doom-snippets-recipe" ''
(doom-snippets :fetcher github :repo "doomemacs/snippets"
:files (:defaults "*-mode"))
'';
packageRequires = [ eself.yasnippet ];
};
} }

View file

@ -119,7 +119,7 @@ let
# something package.el understands as satisfying dependencies. # something package.el understands as satisfying dependencies.
# This is necessary if we're replacing a pinned ELPA dependency # This is necessary if we're replacing a pinned ELPA dependency
# of an unpinned ELPA package. # of an unpinned ELPA package.
esuper.melpaBuild ({ esuper.melpaBuild {
pname = name; pname = name;
# Nix requires that we set version. Inherit it from the # Nix requires that we set version. Inherit it from the
# original if available: package.el currently does not check # original if available: package.el currently does not check
@ -132,25 +132,11 @@ let
description = "trivial build for doom-emacs"; description = "trivial build for doom-emacs";
}; };
# Just enough to make melpa2nix work. # Just enough to make melpa2nix work.
# TODO: pass "files" through, drop postUnpack hack below? recipe = writeText "generated-recipe" ''
recipe = writeText "generated-recipe" (${name} :fetcher github :repo "marienz/made-up"
"(${name} :fetcher github :repo \"marienz/made-up\")"; ${optionalString (p ? recipe.files) ":files ${lib.debug.traceValSeq p.recipe.files}"})'';
buildInputs = (map (name: eself.${name}) reqlist); buildInputs = (map (name: eself.${name}) reqlist);
} // optionalAttrs (p ? recipe.files && p.recipe.files != { defaults = "*"; }) { });
# HACK: files can contain :defaults, which splices in defaults.
# If files starts with :defaults, the entire thing gets
# misinterpreted as a proplist when exported to json.
# This currently only happens for `(:defaults "*")`, which we can
# safely ignore (skipping a few excludes).
postUnpack = ''
filteredSrc=$PWD/filteredSrc
mkdir $filteredSrc
pushd $sourceRoot
cp -r ${builtins.toString p.recipe.files} $filteredSrc
popd
sourceRoot=$filteredSrc
'';
}));
url = url =
if (p.recipe.host or "") == "github" && p ? recipe.repo if (p.recipe.host or "") == "github" && p ? recipe.repo
then "https://github.com/${p.recipe.repo}" then "https://github.com/${p.recipe.repo}"