From ab7790b983d85a3de9d9dffeb02a919aded6eba6 Mon Sep 17 00:00:00 2001 From: Evie Litherland-Smith Date: Thu, 20 Jun 2024 16:25:50 +0100 Subject: [PATCH] Move Emacs font settings to theme, which is then loaded in extraConfig --- programs/emacs/default.nix | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/programs/emacs/default.nix b/programs/emacs/default.nix index 5123599..5d700d7 100644 --- a/programs/emacs/default.nix +++ b/programs/emacs/default.nix @@ -23,20 +23,31 @@ enable = true; package = pkgs.emacs29-pgtk; extraConfig = let - shell = "${pkgs.zsh}/bin/zsh"; - font = "${fonts.monospace.name}-${toString fonts.sizes.applications}"; fixed-font-family = "${fonts.monospace.name}"; variable-font-family = "${fonts.sansSerif.name}"; - alpha = "100"; # "90"; + custom-theme-name = "nix"; + custom-theme = pkgs.writeTextFile { + name = "custom-emacs-theme"; + destination = "/${custom-theme-name}-theme.el"; + text = '' + (deftheme ${custom-theme-name} + "Use Nix customised fonts for main faces") + + (custom-theme-set-faces + '${custom-theme-name} + '(default ((t (:family "${fixed-font-family}" :height 120)))) + '(fixed-pitch ((t (:family "${fixed-font-family}")))) + '(fixed-pitch-serif ((t (:family "${fixed-font-family}")))) + '(variable-pitch ((t (:family "${variable-font-family}"))))) + + (provide-theme '${custom-theme-name}) + ''; + }; + custom-theme-hash = builtins.hashFile "sha256" "${custom-theme}/${custom-theme-name}-theme.el"; in '' - (customize-set-variable 'shell-file-name "${shell}") - (add-to-list 'initial-frame-alist '(font . "${font}")) - (add-to-list 'default-frame-alist '(font . "${font}")) - (set-face-attribute 'fixed-pitch nil :family "${fixed-font-family}") - (set-face-attribute 'fixed-pitch-serif nil :family "${fixed-font-family}") - (set-face-attribute 'variable-pitch nil :family "${variable-font-family}") - (add-to-list 'initial-frame-alist '(alpha-background . ${alpha})) - (add-to-list 'default-frame-alist '(alpha-background . ${alpha})) + (add-to-list 'custom-theme-load-path "${custom-theme}") + (add-to-list 'custom-safe-themes "${custom-theme-hash}") + (load-theme '${custom-theme-name}) ''; extraPackages = epkgs: with epkgs; [