From 74d36d5ae1380124f2dfdb810901fa162a410231 Mon Sep 17 00:00:00 2001 From: Sameer Rahmani Date: Sun, 14 Apr 2024 21:07:12 +0100 Subject: [PATCH] Remove the old buildConfig in favor of the new build.el --- lisp/build.el | 45 +++++++++++++++++++++-- nix/fg42/derivation.nix | 49 ++++---------------------- nix/fg42/unit.nix | 15 ++++++-- nix/modules/editor/default.nix | 5 +-- nix/modules/editor/lisp/fg42/config.el | 40 +++++++++++++++++++++ nix/modules/editor/lisp/fg42/editor.el | 5 ++- nix/modules/editor/lisp/fg42/themes.el | 26 +++++--------- nix/modules/editor/lisp/fpkg.el | 10 +++--- 8 files changed, 119 insertions(+), 76 deletions(-) create mode 100644 nix/modules/editor/lisp/fg42/config.el diff --git a/lisp/build.el b/lisp/build.el index 0f888fd..b72b23e 100644 --- a/lisp/build.el +++ b/lisp/build.el @@ -29,6 +29,44 @@ (when (not (json-available-p)) (error "Error: libjasson support is missing")) +(defvar file-header " ;;; FG42 --- The mighty editor for the emacsians -*- lexical-binding: t; -*- +;; +;; Copyright (c) 2010-2024 Sameer Rahmani +;; +;; Author: Sameer Rahmani +;; URL: https://devheroes.codes/FG42/FG42 +;; Version: 4.0.0 +;; +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. +;; +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. +;; +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . +;; +;;; Commentary: +;; This is the builder script that takes the config.json from the input +;; (typically provided by Nix). And generates appropriate Elisp file +;; for the main FG42 Elsip code to load and use. +;; +;; Please note that this file runs with Emacs and not FG42. +;;; Code: +;; ============================================================================ +;; This file is auto generated by FG42. Don't modify it. +;; ============================================================================ +") + +(defvar file-footer " +(require 'fg42) +(provide 'fg42_init) +;; fg42_init.el ends here +") ;; Elisp's hashtables are not functional so I have to store the ;; state like this, Ewwwwww! @@ -55,9 +93,10 @@ `(eval-when-compile ,@(mapcar (lambda (pkg) `(require ',(intern pkg))) elisp-pkgs))))) + (defun generate-generic-vars (k v) "Generate a list of vars for K and value V." - (add-to-list 'build-state `(defvar ,(intern (format "fg42/%s" k)) ,v))) + (add-to-list 'build-state `(defvar ,(intern (format "fg42/config/%s" k)) ,v))) (defun fg42-config-key-handler (k v) @@ -91,7 +130,9 @@ CONFIG maps to the collective `config' value of Nix modules." ;; rist though (maphash #'handle-top-level j) (with-temp-file (cadr command-line-args-left) - (mapc (lambda (x) (print x (current-buffer))) build-state))) + (insert file-header) + (mapc (lambda (x) (print x (current-buffer))) build-state) + (insert file-footer))) (provide 'build) diff --git a/nix/fg42/derivation.nix b/nix/fg42/derivation.nix index caf7e4e..70abfa9 100644 --- a/nix/fg42/derivation.nix +++ b/nix/fg42/derivation.nix @@ -50,48 +50,12 @@ let # Fonts are obviously runtime dependency as well runtimeDependencies = cfg.paths ++ cfg.fonts ++ cfg.elispPackages; - # addToList = epkg: ''(add-to-list 'directories-to-autogen "${epkg}")''; - - # sexprs = [ - # '' - # (require 'loaddefs-gen) - # (defvar directories-to-autogen '()) - # (defvar output-file (getenv "LOADEF_OUTPUT")) - # '' - # ] ++ (map addToList cfg.elispPackages) ++ [ - # '' - # (message ">> %s ----- %s" directories-to-autogen output-file) - # (loaddefs-generate directories-to-autogen - # output-file) - # (provide 'loaddef-generator) - # '' - # ]; - # loaddefGenerator = writeText "loaddef-generator.el" (concatStringsSep "\n" sexprs); - # loaddefScript = writeShellApplication { - # name = "loaddef"; - - # text = '' - # #!${stdenv.shell} - # set +x - # LOADEF_OUTPUT="$1" ${emacsBundle}/bin/emacs -Q -q --batch -l ${loaddefGenerator} - # ''; - # }; - - configFile = writeTextFile { name = "config.json"; text = (toJSON config); executable = false; }; - - startupPackage = cfg.startUp; - - - # elsipFiles = map (file: ) cfg.elispPackages; - # nativeCompiler = epkgs: '' - # emacs -L . --batch -f batch-native-compile ${elispFiles} - # ''; in stdenv.mkDerivation rec { inherit version; @@ -103,6 +67,8 @@ stdenv.mkDerivation rec { runHook preBuild LISPDIR=$out/share/fg42/ + STARTUP_FILE=$LISPDIR/lisp/fg42_init.el + mkdir -p $out/bin mkdir -p $out/share/applications/ @@ -119,7 +85,7 @@ stdenv.mkDerivation rec { export FONTCONFIG_FILE="$LISPDIR/fonts.conf" chmod 755 $LISPDIR -R - emacs --batch -l $LISPDIR/lisp/build.el $LISPDIR/config.json $LISPDIR/lisp/fg42_init.el + emacs --batch -l $LISPDIR/lisp/build.el $LISPDIR/config.json $STARTUP_FILE @@ -153,12 +119,13 @@ stdenv.mkDerivation rec { export PATH=${pathsStr}:$PATH export FONTCONFIG_FILE="$LISPDIR/fonts.conf" + export STARTUP_FILE=$LISPDIR/lisp/fg42_init.el LIBRARY_PATH="\$(${stdenv.cc}/bin/cc -print-file-name=libgccjit.so):\$LIBRARY_PATH" \ FG42_WM=fales ${emacsBundle}/bin/emacs \ --name FG42 \ -q --no-splash --title FG42 \ - -l ${cfg.startUp} "\$@" + -l "$STARTUP_FILE" "\$@" EOF chmod +x $out/bin/fg42 @@ -172,11 +139,9 @@ stdenv.mkDerivation rec { cat >> $out/bin/fg42-wm << EOF #!${stdenv.shell} - export FG42_HOME=${placeholder "out"}/share/fg42/ - export FG42_EMACSD=~/.fg42/v4/emacs.d - export FG42_USE_NIX=true; export PATH=${pathsStr}:\$PATH export FONTCONFIG_FILE="$LISPDIR/fonts.conf" + export STARTUP_FILE=$LISPDIR/lisp/fg42_init.el # Disable access control for the current user. ${xorg.xhost}/bin/xhost +SI:localuser:\$USER @@ -200,7 +165,7 @@ stdenv.mkDerivation rec { FG42_WM=true ${emacsBundle}/bin/emacs \ --name FG42 \ -q --no-splash --title FG42 \ - -l \$FG42_HOME/lisp/fg42/fg42.el "\$@" + -l $STARTUP_FILE "\$@" EOF chmod +x $out/bin/fg42-wm diff --git a/nix/fg42/unit.nix b/nix/fg42/unit.nix index 2dac561..5bdd1b9 100644 --- a/nix/fg42/unit.nix +++ b/nix/fg42/unit.nix @@ -86,10 +86,19 @@ with lib; description = "The default font for FG42"; }; - fg42.startUp = mkOption { - type = types.uniq types.path; - description = "The main startup file to load first. This is usually fg42.el"; + + fg42.theme = mkOption { + type = types.str; + description = "The theme name to use with FG42."; }; + fg42.theme-package-name = mkOption + { + type = types.str; + description = '' + The theme package name to use with FG42. The package should be added + to `elispPackages` already; + ''; + }; }; diff --git a/nix/modules/editor/default.nix b/nix/modules/editor/default.nix index b406db0..6d7368f 100644 --- a/nix/modules/editor/default.nix +++ b/nix/modules/editor/default.nix @@ -38,6 +38,7 @@ let yasnippet yasnippet-snippets flycheck + base16-theme ]); drv = makeFG42Drv { pname = "fg42-editor"; @@ -51,7 +52,6 @@ in { config = { fg42.elispPackages = [ drv ] ++ deps; - fg42.startUp = lib.mkDefault "${drv}/share/emacs/site-lisp/fg42.el"; fg42.fonts = (with pkgs;[ vazir-fonts @@ -66,6 +66,7 @@ in ]); fg42.font = lib.mkDefault '''("Fira Mono" 11)''; - fg42.requires = [ "fg42/cpp" ]; + fg42.theme = lib.mkDefault "base16-eighties"; + fg42.theme-package-name = lib.mkDefault "base16-theme"; }; } diff --git a/nix/modules/editor/lisp/fg42/config.el b/nix/modules/editor/lisp/fg42/config.el new file mode 100644 index 0000000..f34c414 --- /dev/null +++ b/nix/modules/editor/lisp/fg42/config.el @@ -0,0 +1,40 @@ +;;; FG42 --- The mighty editor for the emacsians -*- lexical-binding: t; -*- +;; +;; Copyright (c) 2010-2024 Sameer Rahmani & Contributors +;; +;; Author: Sameer Rahmani +;; URL: https://devheroes.codes/FG42/FG42 +;; Version: 4.0.0 +;; +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. +;; +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. +;; +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . +;; +;;; Commentary: +;;; Code: + +(defmacro fg42/config-get (key) + "Return the value for KEY or raise an error." + (let ((sym (intern (format "fg42/config/%s" key)))) + (if (boundp sym) + `,sym + `(error "Can't find config '%s'" ,key)))) + +(defmacro fg42/config-get-or (key &optional default) + "Return the value for KEY or DEFAULT." + (let ((sym (intern (format "fg42/config/%s" key)))) + (if (boundp sym) + `,sym + `,default))) + +(provide 'fg42/config) +;;; config.el ends here diff --git a/nix/modules/editor/lisp/fg42/editor.el b/nix/modules/editor/lisp/fg42/editor.el index 0141c9b..0a99620 100644 --- a/nix/modules/editor/lisp/fg42/editor.el +++ b/nix/modules/editor/lisp/fg42/editor.el @@ -25,7 +25,7 @@ (require 'fpkg) ;; We build this file via the main FG42's Nix derivation. It ;; contains the final Nix configuration of FG42. - (require 'fg42/build-config) + (require 'fg42/config) (require 'fg42/themes) ;; ;; Language support ;; (require 'fg42/autocomplete) @@ -48,7 +48,6 @@ (require 'server) (require 'fg42/utils) - (defun fg42/setup-font () "Set the default font of `FG42' to FONT-NAME and FONT-SIZE." (let ((name (car fg42/font)) @@ -207,7 +206,7 @@ contextual information." ;; In the following section we're setting some default behavior of FG42. ;; Most of these configuration are opiniated and I think most of people ;; shared the same opinion or don't care at all. - (fg42/setup-font) + ;;(fg42/setup-font) (add-hook 'fg42/after-init-hook (lambda () (set-default 'cursor-type 'bar) diff --git a/nix/modules/editor/lisp/fg42/themes.el b/nix/modules/editor/lisp/fg42/themes.el index db49111..48d2bf7 100644 --- a/nix/modules/editor/lisp/fg42/themes.el +++ b/nix/modules/editor/lisp/fg42/themes.el @@ -27,7 +27,7 @@ ;;; Code: (eval-when-compile (require 'fpkg) - (require 'fg42/build-config)) + (require 'fg42/config)) (require 'fg42/utils) @@ -42,27 +42,17 @@ It executes way before the rest of the cubes.") "The hook to plug any configuration to after initialize event of themes.") -(defmacro fg42/setup-theme! (&rest body) +(defmacro fg42/setup-theme! () "Grab the them provided by `fg42/theme' and load it. Load the theme via `use!' and pass the BODY to the `use!' macroro. If the theme name and the theme package name are different the package -name can be set via `fg42/theme-package'". - - (declare (indent defun)) - (let ((pkg (if (not (null fg42/theme-package)) - fg42/theme-package - fg42/theme))) - `(use! ,pkg - "Setting up the ,pkg package." - :config - (load-theme fg42/theme t) - ,@body))) - -;; (use! base16-theme -;; "Load base16 based themes in FG42." -;; :config -;; (load-theme 'base16-eighties t)) +name can be set via `fg42/theme-package'." + `(use! ,(intern (fg42/config-get-or theme-package-name (fg42/config-get theme))) + "Setting up the ,pkg package." + :config + (progn + (load-theme ',(intern (fg42/config-get theme)) t)))) (provide 'fg42/themes) diff --git a/nix/modules/editor/lisp/fpkg.el b/nix/modules/editor/lisp/fpkg.el index 0bc5bf6..56b2afe 100644 --- a/nix/modules/editor/lisp/fpkg.el +++ b/nix/modules/editor/lisp/fpkg.el @@ -45,10 +45,8 @@ (declare (indent defun)) (if (and (listp details) (< 0 (length details))) (let ((p (inject-params details))) - `(progn - (use-package ,pkg ,@p))) - `(progn - (use-package ,pkg :defer t :ensure nil)))) + `(use-package ,pkg ,@p)) + `(use-package ,pkg :defer t :ensure nil))) (defmacro use! (pkg docs &rest details) @@ -60,8 +58,8 @@ DOCS is the documentation of the package." (when (not (stringp docs)) (error "Missing docstring for '%s' package" pkg)) - (let ((disabled (or (member pkg fg42/disabled-features) nil))) - (when (not disabled) + (let ((disabled (member pkg fg42/disabled-features))) + (when (null disabled) `(use-package ,pkg ,@details))))