From 32c47479b1ffa6916276db7ae4d2951bb69d2a16 Mon Sep 17 00:00:00 2001 From: materus Date: Wed, 15 Nov 2023 00:07:16 +0100 Subject: [PATCH] emacs: create one config file --- .../profile/home/editor/emacs/default.nix | 84 +++++-------------- .../profile/home/editor/emacs/init.nix | 24 ++++++ extraFiles/config/emacs/early-init.el | 30 +++++++ extraFiles/config/emacs/{materus => }/init.el | 24 +----- extraFiles/config/emacs/materus-config.el | 5 -- extraFiles/config/emacs/materus/packages.el | 11 --- extraFiles/config/emacs/packages.el | 33 ++++++++ 7 files changed, 110 insertions(+), 101 deletions(-) create mode 100644 configurations/profile/home/editor/emacs/init.nix create mode 100644 extraFiles/config/emacs/early-init.el rename extraFiles/config/emacs/{materus => }/init.el (61%) delete mode 100644 extraFiles/config/emacs/materus-config.el delete mode 100644 extraFiles/config/emacs/materus/packages.el create mode 100644 extraFiles/config/emacs/packages.el diff --git a/configurations/profile/home/editor/emacs/default.nix b/configurations/profile/home/editor/emacs/default.nix index ee0cbac..775c0c6 100644 --- a/configurations/profile/home/editor/emacs/default.nix +++ b/configurations/profile/home/editor/emacs/default.nix @@ -1,5 +1,8 @@ { config, lib, pkgs, materusArg, ... }: let + configPath = "${materusArg.cfg.path}" + "/extraFiles/config/emacs/"; + + inits = import ./init.nix {path = configPath; inherit pkgs;}; packages = epkgs: with epkgs; [ load-relative elcord @@ -61,61 +64,24 @@ let default-config = '' (defvar materus/nix-packages t) (defvar materus/init-from-home nil) - (defvar materus/init-from-default nil) - (when (not materus/init-from-home) - (setq-default materus/home-dir (concat user-emacs-directory "materus/" )) - (setq-default materus/init-from-default t) - (message "Config loading not from homeDir, need "materus/init-from-home" variable in init.el") - + (unless materus/init-from-home + (message "Config loading not from homeDir, need \"materus/init-from-home\" variable in init.el") ${setNixInit} - (require 'materus-config) + ${inits.initText} ) ''; - - - materus-config = epkgs: epkgs.trivialBuild rec { - pname = "materus-config"; - src = pkgs.symlinkJoin { - name = "materus-emacs-config"; - paths = [ - configPath - ]; - }; - version = "1.0"; - packageRequires = (packages epkgs); - buildPhase = '' - runHook preBuild - - emacs -L . --batch -f batch-byte-compile **/*.el - emacs -L . --batch -f batch-byte-compile *.el - - runHook postBuild - ''; - - installPhase = '' - runHook preInstall - - LISPDIR=$out/share/emacs/site-lisp - install -d $LISPDIR - install **.el **.elc $LISPDIR - cp -r materus $LISPDIR - emacs --batch -l package --eval "(package-generate-autoloads \"${pname}\" \"$LISPDIR\")" - - runHook postInstall - ''; - }; - - - - cfg = config.materus.profile.editor.emacs; - configPath = "${materusArg.cfg.path}" + "/extraFiles/config/emacs/"; emacsPkgs = with pkgs;[ python3 lua multimarkdown git ]; + + + cfg = config.materus.profile.editor.emacs; + + setNixInit = '' (setenv "PATH" (concat (getenv "PATH") ":${lib.makeBinPath emacsPkgs}")) ${builtins.concatStringsSep "\n" (builtins.map (x: "(setq exec-path (append exec-path '(\""+x+"/bin\")))" ) emacsPkgs)} @@ -129,32 +95,26 @@ in home.activation.emacsCompile = lib.hm.dag.entryAfter [ "linkGeneration" ] '' ${config.programs.emacs.finalPackage}/bin/emacs --batch \ --eval '(setq warning-minimum-log-level :error)' \ - --eval '(byte-recompile-directory "${config.xdg.configHome}/emacs/materus" 0 t)' \ - --eval '(byte-recompile-file "${config.xdg.configHome}/emacs/init.el")' + --eval '(byte-compile-file "${config.xdg.configHome}/emacs/early-init.el")' \ + --eval '(byte-compile-file "${config.xdg.configHome}/emacs/init.el")' ''; xdg.configFile."emacs/init.el".text = '' - (setq inhibit-defaul-init 1) - (setq native-comp-speed 3) (defvar materus/nix-packages nil) (defvar materus/init-from-home t) - (defvar materus/init-from-default nil) - ${setNixInit} (setq-default materus/init-from-home t) - (setq-default materus/home-dir (concat user-emacs-directory "materus/" )) - (setq-default materus/nix-packages (require 'materus-config nil 'noerror)) - (when (not materus/nix-packages) - (load (concat user-emacs-directory "materus/init")) - (message "Config loaded from user dir") - ) + + ${setNixInit} + ${inits.initText} ''; - xdg.configFile."emacs/materus" = { - source = configPath + "materus"; - recursive = true; - }; + + xdg.configFile."emacs/early-init.el".text = '' + ${inits.earlyInitText} + ''; + programs.emacs = { enable = true; package = with pkgs; lib.mkDefault (emacs29.override { withX = true; withGTK3 = true; withAlsaLib = true; withGconf = true; withImageMagick = true; withXwidgets = true; }); - extraPackages = epkgs: ((packages epkgs) ++ [(materus-config epkgs)]); + extraPackages = epkgs: ((packages epkgs)); extraConfig = default-config; }; diff --git a/configurations/profile/home/editor/emacs/init.nix b/configurations/profile/home/editor/emacs/init.nix new file mode 100644 index 0000000..385dc94 --- /dev/null +++ b/configurations/profile/home/editor/emacs/init.nix @@ -0,0 +1,24 @@ +{path, pkgs}: +{ + + earlyInitText = '' + ${builtins.readFile (path + "early-init.el")} + ''; + initText = '' + (defvar materus/init-early nil) + (unless materus/init-early + (tool-bar-mode -1) + (setq initial-major-mode 'fundamental-mode) + (setq-default package-quickstart t) + (setq native-comp-speed 3) + ) + (defvar materus/init-from-home nil) + (when materus/init-from-home + (setq-default inhibit-defaul-init 1) + ) + (setq-default materus/nix-packages (require 'doom-themes nil 'noerror)) + ${builtins.readFile (path + "packages.el")} + ${builtins.readFile (path + "init.el")} + ''; + +} diff --git a/extraFiles/config/emacs/early-init.el b/extraFiles/config/emacs/early-init.el new file mode 100644 index 0000000..3746dcd --- /dev/null +++ b/extraFiles/config/emacs/early-init.el @@ -0,0 +1,30 @@ + + + +(defvar materus/init-early t) +(setq materus/init-early t) + +(tool-bar-mode -1) +(setq initial-major-mode 'fundamental-mode) +(setq-default package-quickstart t) +(setq native-comp-speed 3) + +(unless (daemonp) + (setq gc-cons-threshold most-positive-fixnum ; 2^61 bytes + gc-cons-percentage 0.6) + (setq package-enable-at-startup nil) + + (add-hook 'emacs-startup-hook (lambda () (package-initialize) + (setq gc-cons-threshold 16777216 ; 16mb + gc-cons-percentage 0.1) + )) + + + (advice-add #'tty-run-terminal-initialization :override #'ignore) + (add-hook 'window-setup-hook + (lambda () + (advice-remove #'tty-run-terminal-initialization #'ignore) + (tty-run-terminal-initialization (selected-frame) nil t) + ) + ) +) diff --git a/extraFiles/config/emacs/materus/init.el b/extraFiles/config/emacs/init.el similarity index 61% rename from extraFiles/config/emacs/materus/init.el rename to extraFiles/config/emacs/init.el index c63a165..8580c39 100644 --- a/extraFiles/config/emacs/materus/init.el +++ b/extraFiles/config/emacs/init.el @@ -1,31 +1,9 @@ -(defvar materus/nix-packages nil) -(defvar materus/init-from-home nil) -(defvar materus/home-dir (concat user-emacs-directory "materus/" )) + (setq native-comp-async-report-warnings-errors nil) (setq package-enable-at-startup nil) (setq frame-inhibit-implied-resize t) -(when (not materus/nix-packages) - (message "Not using config from nix packages, using straight") - (defvar bootstrap-version) - (let ((bootstrap-file - (expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory)) - (bootstrap-version 6)) - (unless (file-exists-p bootstrap-file) - (with-current-buffer - (url-retrieve-synchronously - "https://raw.githubusercontent.com/radian-software/straight.el/develop/install.el" - 'silent 'inhibit-cookies) - (goto-char (point-max)) - (eval-print-last-sexp))) - (load bootstrap-file nil 'nomessage)) - (declare-function straight-use-package "straight" (&optional ARG)) - (declare-function load-relative "load-relative" (&optional ARG)) - (straight-use-package 'load-relative) - (load-relative "packages") -) - (require 'telephone-line) (require 'elcord) (require 'dashboard) diff --git a/extraFiles/config/emacs/materus-config.el b/extraFiles/config/emacs/materus-config.el deleted file mode 100644 index 36c398f..0000000 --- a/extraFiles/config/emacs/materus-config.el +++ /dev/null @@ -1,5 +0,0 @@ -(message "Config loading from package") -(setq-default materus/nix-packages t) -(require 'load-relative) -(load-relative "materus/init") -(provide 'materus-config) \ No newline at end of file diff --git a/extraFiles/config/emacs/materus/packages.el b/extraFiles/config/emacs/materus/packages.el deleted file mode 100644 index 8e8ceae..0000000 --- a/extraFiles/config/emacs/materus/packages.el +++ /dev/null @@ -1,11 +0,0 @@ - (straight-use-package 'use-package) - (straight-use-package 'telephone-line) - (straight-use-package 'elcord) - (straight-use-package 'dashboard) - (straight-use-package 'minions) - (straight-use-package 'lsp-mode) - (straight-use-package 'lsp-ui) - - (straight-use-package 'moe-theme) - (straight-use-package 'doom-themes) - diff --git a/extraFiles/config/emacs/packages.el b/extraFiles/config/emacs/packages.el new file mode 100644 index 0000000..6d7a806 --- /dev/null +++ b/extraFiles/config/emacs/packages.el @@ -0,0 +1,33 @@ + (defvar materus/nix-packages nil) + + + + (when (not materus/nix-packages) + (message "Not using config from nix packages, using straight") + (defvar bootstrap-version) + (let ((bootstrap-file + (expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory)) + (bootstrap-version 6)) + (unless (file-exists-p bootstrap-file) + (with-current-buffer + (url-retrieve-synchronously + "https://raw.githubusercontent.com/radian-software/straight.el/develop/install.el" + 'silent 'inhibit-cookies) + (goto-char (point-max)) + (eval-print-last-sexp))) + (load bootstrap-file nil 'nomessage)) + (declare-function straight-use-package "straight" (&optional ARG)) + (straight-use-package 'load-relative) + + (straight-use-package 'use-package) + (straight-use-package 'telephone-line) + (straight-use-package 'elcord) + (straight-use-package 'dashboard) + (straight-use-package 'minions) + (straight-use-package 'lsp-mode) + (straight-use-package 'lsp-ui) + + (straight-use-package 'moe-theme) + (straight-use-package 'doom-themes) + ) +