| git.druid.rocks | index | druid520 | radium | radium-bootstrap.el |
radium-bootstrap.el
;;; radium-bootstrap.el, package archives + use-package -*- lexical-binding: t; -*-
(require 'package)
(require 'gnutls)
;; netbsd/pkgsrc gnutls certs land under one of these, but neither path
;; is in emacs's own default gnutls-trustfiles (which knows debian,
;; rhel, opensuse, freebsd and openbsd, but not netbsd) - without this,
;; every https package fetch below fails tls verification even when
;; mozilla-rootcerts is installed and `mozilla-rootcerts install` has
;; been run as root.
(dolist (f '("/etc/openssl/certs/ca-certificates.crt"
"/usr/pkg/etc/openssl/certs/ca-certificates.crt"))
(when (and (file-exists-p f) (not (member f gnutls-trustfiles)))
(push f gnutls-trustfiles)))
;; emacs built without internal gnutls isn't a problem by itself: emacs
;; falls back to the external `gnutls-cli` binary for https, and that
;; path works fine (my install does exactly this). i only scream when
;; *neither* internal gnutls nor the external client exists, because
;; then tls package fetches genuinely can't happen.
(unless (or (gnutls-available-p) (executable-find "gnutls-cli"))
(message "err: no gnutls at all - emacs has none built in and no \
gnutls-cli on path, so https package fetches will fail; install \
gnutls (pkgsrc has it) or rebuild pkgsrc's emacs with \
PKG_OPTIONS.emacs+=gnutls in /etc/mk.conf."))
;; every package below gets byte-compiled once on first install, and
;; plenty of them (mostly unmaintained or just old) trip compiler
;; warnings that have nothing to do with radium - silence compilation
;; output for installs, not for anything i actually write (none of my
;; own files ever get byte-compiled, see .gitignore).
(setq byte-compile-warnings nil)
;; package.el's own archive install goes through `package--compile',
;; which re-binds byte-compile-warnings on its own and so spews those
;; third-party warnings regardless of the setq above. i advise it to
;; keep the noise out the whole time the archive install runs, while
;; still letting a genuine compile failure raise its error. the
;; lexical-cookie warning has its own separate kill switch (an internal
;; emacs 30 var), so that gets bound too - harmless on older emacs.
(defun radium-package--compile (orig pkg-desc &rest args)
"call ORIG with compilation warnings silenced for an archive install."
(let ((byte-compile-warnings nil)
(byte-compile-verbose nil)
(bytecomp--inhibit-lexical-cookie-warning t))
(apply orig pkg-desc args)))
(when (fboundp 'package--compile)
(advice-add 'package--compile :around #'radium-package--compile))
;; upstream packages ship test files that require dev deps (wgrep's
;; want ag + ert) and spew reload errors when package.el compiles
;; them. test files never matter to an installed package, so i make
;; package--compile skip them the same way it honors .elpaignore.
(defun radium-package--parse-elpaignore (result)
(append result (list "[-/]\\(test\\|tests\\|subtest\\)\\([-/]\\|\\.el\\'\\)")))
(when (fboundp 'package--parse-elpaignore)
(advice-add 'package--parse-elpaignore :filter-return
#'radium-package--parse-elpaignore))
(setq package-archives
'(("gnu" . "https://elpa.gnu.org/packages/")
("nongnu" . "https://elpa.nongnu.org/nongnu/")
("melpa" . "https://melpa.org/packages/"))
package-archive-priorities
'(("gnu" . 3) ("nongnu" . 2) ("melpa" . 1)))
(package-initialize)
(unless package-archive-contents
(package-refresh-contents))
;; a stale archive cache points at tars the archives no longer keep
;; (gnu elpa rebuilds pull old versions - e.g. a cached diff-hl 1.11.0
;; 404s the day 1.11.1 replaces it), which turns a fresh install into a
;; download error. refresh the cache once whenever it's older than 2
;; days, not on every startup.
(let ((cache (expand-file-name "archives/gnu/archive-contents" package-user-dir)))
(when (and (file-exists-p cache)
(> (float-time
(time-since
(file-attribute-modification-time (file-attributes cache))))
(* 2 86400)))
(message "radium: package cache stale, refreshing...")
(package-refresh-contents)))
(unless (package-installed-p 'use-package)
(package-install 'use-package))
(require 'use-package)
(setq use-package-always-ensure t
use-package-verbose nil)
(provide 'radium-bootstrap)