emacs: create one config file

This commit is contained in:
Mateusz Słodkowicz 2023-11-15 00:07:16 +01:00
parent cf3a2d98c7
commit 32c47479b1
Signed by: materus
GPG Key ID: 28D140BCA60B4FD1
7 changed files with 110 additions and 101 deletions

View File

@ -1,5 +1,8 @@
{ config, lib, pkgs, materusArg, ... }: { config, lib, pkgs, materusArg, ... }:
let let
configPath = "${materusArg.cfg.path}" + "/extraFiles/config/emacs/";
inits = import ./init.nix {path = configPath; inherit pkgs;};
packages = epkgs: with epkgs; [ packages = epkgs: with epkgs; [
load-relative load-relative
elcord elcord
@ -61,61 +64,24 @@ let
default-config = '' default-config = ''
(defvar materus/nix-packages t) (defvar materus/nix-packages t)
(defvar materus/init-from-home nil) (defvar materus/init-from-home nil)
(defvar materus/init-from-default nil) (unless materus/init-from-home
(when (not materus/init-from-home) (message "Config loading not from homeDir, need \"materus/init-from-home\" variable in init.el")
(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")
${setNixInit} ${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;[ emacsPkgs = with pkgs;[
python3 python3
lua lua
multimarkdown multimarkdown
git git
]; ];
cfg = config.materus.profile.editor.emacs;
setNixInit = '' setNixInit = ''
(setenv "PATH" (concat (getenv "PATH") ":${lib.makeBinPath emacsPkgs}")) (setenv "PATH" (concat (getenv "PATH") ":${lib.makeBinPath emacsPkgs}"))
${builtins.concatStringsSep "\n" (builtins.map (x: "(setq exec-path (append exec-path '(\""+x+"/bin\")))" ) 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" ] '' home.activation.emacsCompile = lib.hm.dag.entryAfter [ "linkGeneration" ] ''
${config.programs.emacs.finalPackage}/bin/emacs --batch \ ${config.programs.emacs.finalPackage}/bin/emacs --batch \
--eval '(setq warning-minimum-log-level :error)' \ --eval '(setq warning-minimum-log-level :error)' \
--eval '(byte-recompile-directory "${config.xdg.configHome}/emacs/materus" 0 t)' \ --eval '(byte-compile-file "${config.xdg.configHome}/emacs/early-init.el")' \
--eval '(byte-recompile-file "${config.xdg.configHome}/emacs/init.el")' --eval '(byte-compile-file "${config.xdg.configHome}/emacs/init.el")'
''; '';
xdg.configFile."emacs/init.el".text = '' xdg.configFile."emacs/init.el".text = ''
(setq inhibit-defaul-init 1)
(setq native-comp-speed 3)
(defvar materus/nix-packages nil) (defvar materus/nix-packages nil)
(defvar materus/init-from-home t) (defvar materus/init-from-home t)
(defvar materus/init-from-default nil)
${setNixInit}
(setq-default materus/init-from-home t) (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)) ${setNixInit}
(when (not materus/nix-packages) ${inits.initText}
(load (concat user-emacs-directory "materus/init"))
(message "Config loaded from user dir")
)
''; '';
xdg.configFile."emacs/materus" = {
source = configPath + "materus"; xdg.configFile."emacs/early-init.el".text = ''
recursive = true; ${inits.earlyInitText}
}; '';
programs.emacs = { programs.emacs = {
enable = true; enable = true;
package = with pkgs; lib.mkDefault (emacs29.override { withX = true; withGTK3 = true; withAlsaLib = true; withGconf = true; withImageMagick = true; withXwidgets = 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; extraConfig = default-config;
}; };

View File

@ -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")}
'';
}

View File

@ -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)
)
)
)

View File

@ -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 native-comp-async-report-warnings-errors nil)
(setq package-enable-at-startup nil) (setq package-enable-at-startup nil)
(setq frame-inhibit-implied-resize t) (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 'telephone-line)
(require 'elcord) (require 'elcord)
(require 'dashboard) (require 'dashboard)

View File

@ -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)

View File

@ -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)

View File

@ -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)
)