From c50ceed902ff06315688153acb7e229d3582fa0f Mon Sep 17 00:00:00 2001 From: Marien Zwart Date: Tue, 5 Mar 2024 22:23:40 +1100 Subject: [PATCH] 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. --- cli.el | 15 +++++++++++++++ elisp-packages.nix | 32 ++++++++++++++++++++++++++++++++ package.nix | 24 +++++------------------- 3 files changed, 52 insertions(+), 19 deletions(-) diff --git a/cli.el b/cli.el index e6da364..0f0451a 100755 --- a/cli.el +++ b/cli.el @@ -12,6 +12,21 @@ ;; 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))) diff --git a/elisp-packages.nix b/elisp-packages.nix index b2c11ca..54cf165 100644 --- a/elisp-packages.nix +++ b/elisp-packages.nix @@ -4,6 +4,7 @@ esuper, git, makeWrapper, + writeText, }: { # Doom uses using emacs-straight/auctex, which still contains parts of @@ -98,4 +99,35 @@ 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 ]; + }; } diff --git a/package.nix b/package.nix index f2c4e34..7fbe21d 100644 --- a/package.nix +++ b/package.nix @@ -119,7 +119,7 @@ let # something package.el understands as satisfying dependencies. # This is necessary if we're replacing a pinned ELPA dependency # of an unpinned ELPA package. - esuper.melpaBuild ({ + esuper.melpaBuild { pname = name; # Nix requires that we set version. Inherit it from the # original if available: package.el currently does not check @@ -132,25 +132,11 @@ let description = "trivial build for doom-emacs"; }; # Just enough to make melpa2nix work. - # TODO: pass "files" through, drop postUnpack hack below? - recipe = writeText "generated-recipe" - "(${name} :fetcher github :repo \"marienz/made-up\")"; + recipe = writeText "generated-recipe" '' + (${name} :fetcher github :repo "marienz/made-up" + ${optionalString (p ? recipe.files) ":files ${lib.debug.traceValSeq p.recipe.files}"})''; 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 = if (p.recipe.host or "") == "github" && p ? recipe.repo then "https://github.com/${p.recipe.repo}"