I’ve been trying to up my use-package
game recently and converted my hand rolled package check and installer to use-package
. I usually prefer to use packages from melpa-stable
so I pin the default package source used by use-package
to melpa-stable
and override it where necessary That’s working well in general and looks something like this:
(setq use-package-always-pin "melpa-stable")
(use-package js2-mode
:ensure t
:defer t
:custom
(progn (js-indent-level 2)
(js2-include-node-externs t)))
(use-package kotlin-mode
:ensure t
:pin melpa)
So in other words, if I’m on a machine that doesn’t have js2-mode
and kotlin-mode
installed, use-package
will install js2-mode
from melpa-stable
and kotlin-mode
from melpa
. So far, so good.
The problem I’m currently running into is that I use several packages that install dependencies if said dependencies are not already installed - for example both elpy
and magit
depend on a few other packages. From what I can tell so far, installing these packages automatically ends up pulling the dependent packages from melpa
rather than melpa-stable
, so I end up with a mix of regular and stable packages. While this isn’t a huge issue in the grand scheme of things, I ended up putting together a workaround by using the underlying package managers pinning feature to also pin the dependent packages to melpa-stable
where desired. This looks something like this:
(when (boundp 'package-pinned-packages)
(setq package-pinned-packages
'((bm . "melpa-stable")
(smex . "melpa-stable")
(pkg-info . "melpa-stable")
(rainbow-delimiters . "melpa-stable")
(icicles . "melpa")
(magit-section . "melpa-stable")
(git-commit . "melpa-stable")
(transient . "melpa-stable")
(use-package . "melpa-stable")
(smart-mode-line . "melpa-stable")
(smart-mode-line-powerline . "melpa-stable")
(smart-mode-line-powerline-theme . "melpa-stable")
(with-editor . "melpa-stable")
(dash . "melpa-stable")
(highlight-indentation . "melpa-stable")
(pyvenv . "melpa-stable")
(s . "melpa-stable")
(yasnippet . "melpa-stable")
)))
And yes, you’re correct - not all of the packages pinned above are dependencies of other packages, some of them I just haven’t cleaned up or converted to use-package yet.
Anyway, the above works and delivers the desired results, it just feels a little clunky. Does anybody have a recommendation how to achieve the same thing in a slightly more elegant manner?