Pareto Optimal Dev

Replacing straight.el with Nix to manage emacs packages

Why?

In short, for better reproducability and to free me from manual intervention because packages broke later.

For more details you can see my history of package.el -> straight.el -> Nix for managing emacs packages in Package management and configuration in emacs.

The simple case

straight.el configuration

early-init.el

(setq package-enable-at-startup nil)

init.el

  (defvar bootstrap-version)
  (let ((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
	   "https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el"
	   'silent 'inhibit-cookies)
	(goto-char (point-max))
	(eval-print-last-sexp)))
    (load bootstrap-file nil 'nomessage))

(setq straight-use-package-by-default t)

(straight-use-package 'use-package)

(use-package magit)

nix configuration

From NixOS

  • early-init.el

    (setq package-enable-at-startup nil)
    ;; let's be really sure package.el isn't used
    (setq use-package-ensure-function 'ignore)
    (setq package-archives nil)
    
  • configuration.nix

    { config, pkgs, ... }:
    
    # note: you can store this in an external file like the NixOS manual example as well:
    # https://nixos.org/manual/nixos/stable/index.html#module-services-emacs-adding-packages
    let customEmacs = let
          myEmacs = pkgs.emacs;
          emacsWithPackages = (pkgs.emacsPackagesFor myEmacs).emacsWithPackages;
        in
          emacsWithPackages (epkgs: (with epkgs.melpaPackages; [ magit ]))
    in
    {
      # ... other configuration
    
     environment.systemPackages = with pkgs; [
       # ... other packages
       myEmacs
     ];
      # ... other configuration
    }
    
  • init.el

    (use-package magit)
    

Using another distro with Nix: the package manager

TODO

From DevOS (nix flake configuration framework)

TODO

Install source version of a package

using straight.el

using nix

From NixOS

TODO

Using another distro with Nix: the package manager

TODO

From DevOS (nix flake configuration framework)

TODO

Downsides of using Nix emacs packages

I have to restart emacs when I install a new package

I could figure out how to modify the load-path appropriately and it’s on my backlog, but I’ve never gotten around to it.

Future possibilities

Managing your emacs configuration, system configuration, and all dependencies in a single org file