[emacs-berlin] Reproducible Emacs installations

Arne Brasseur arne.brasseur at gmail.com
Mon Jan 4 10:19:03 UTC 2021


Hi jman,

Thanks for sharing. This looks like a great template for a
melpa/use-package based setup, but I would not call it "reproducible". That
usually means that you get the exact same code each time, whereas with this
you can run the same setup two minutes apart and get a different
combination of package versions. Melpa only has the option of downloading
the latest version of a package (latest release or latest commit depending
on if you are using melpa stable or not, but still only the latest of each).

So if you want to do truly "reproducible" installs you have to use
straight, I don't think there's any other packager right now that is able
to do it. It's fairly straightforward though, and you can still
`use-package` in the same way

```
;;;; Install straight
(defvar bootstrap-version)

(let ((install-url "
https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el")
      (bootstrap-file (expand-file-name
"straight/repos/straight.el/bootstrap.el" user-emacs-directory))
      (bootstrap-version 5))
  (unless (file-exists-p bootstrap-file)
    (with-current-buffer (url-retrieve-synchronously install-url 'silent
'inhibit-cookies)
      (goto-char (point-max))
      (eval-print-last-sexp)))
  (load bootstrap-file nil 'nomessage))

;;;; Tell it to hook into use-package
(straight-use-package 'use-package)
(setq straight-use-package-by-default t)

;;;; Install whatever packages you like
(use-package ...)
(use-package ...)
(use-package ...)

;;;; Create a version file if it does not yet exist
(when (not (file-exists-p (expand-file-name "straight/versions/default.el"
straight-base-dir)))
  (straight-freeze-versions))
```

Straight uses melpa's recipes, but it does not actually install packages
from MELPA, instead it gets them directly via git. The versions.el file
contains the exact commit hash for each package, so when you use this
config on a different computer you'll get the exact same
code/commit/version for each package. True reproducibility!

If you keep your emacs config in a git repository then you can use these
gitignore patterns to make sure the version file is checked in, another
common approach is to keep it in a dotfiles repo and symlink it.

/straight/*
!/straight/versions


Hope that helps! This has become something I care about deeply, as I've had
my emacs setup break so many times when upgrading or reinstalling. Now I
finally have control over which packages are upgraded when, and most
importantly if an upgrade breaks something I can easily revert.

Best wishes for 2021!
Arne

On Mon, 21 Dec 2020 at 19:22, jman <emacs-berlin at storiepvtride.it> wrote:

>
> Hello folks!
>
> A little while ago I wanted to solve a puzzle: a complete and
> reproducible unattended emacs installation from scratch.
> This is useful to set up emacs on different machines or (in my case)
> provision your workstation using tools such as Ansible or Nix
> packages. And emacs is one of the first thing I need to have immediately
> available.
>
> Fermin (hi fermin!) gave some hints [0] and from there I finally reached
> a good enough solution. I'm using `use-package` and didn't want
> to also install `straight` (my config is confusing enough already ^_^).
>
> Here's the relevant snippet (commented):
>
> ```
> ;; add MELPA repository
> (package-initialize)
> (require 'package)
> (add-to-list 'package-archives
>   '("melpa" . "https://melpa.org/packages/") t)
>
> ;; fetch the list of packages available *now*
> (unless package-archive-contents
>   (package-refresh-contents))
>
> ;; if not installed, force installation of "use-package" *now*
> (unless (package-installed-p 'use-package)
>   (package-install 'use-package))
>
> ;; install a new package automatically if not already present
> (require 'use-package-ensure)
>  (setq use-package-always-ensure t)
> ```
>
> from now on any package will be downloaded and installed with:
>
> (use-package a-new-package)
>
> here's a link [1] if anyone wants to have a look (first 20
> lines are relevant).
>
> As usual, comments and suggestions are welcome.
>
> happy hacking!
>
>
> [0] https://mailb.org/pipermail/emacs-berlin/2020/000752.html
> [1]
> https://git.sr.ht/~jman/dotfiles/tree/master/item/emacs/.config/emacs/init.el
> _______________________________________________
> emacs-berlin mailing list
> emacs-berlin at emacs-berlin.org
> https://mailb.org/mailman/listinfo/emacs-berlin
>


-- 
Arne Brasseur
Gaiwan GmbH
Phone +49 176 97468014
https://lambdaisland.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailb.org/pipermail/emacs-berlin/attachments/20210104/eae294b9/attachment.htm>


More information about the emacs-berlin mailing list