Remove the old buildConfig in favor of the new build.el

This commit is contained in:
Sameer Rahmani 2024-04-14 21:07:12 +01:00
parent c9cdb0a83e
commit 74d36d5ae1
Signed by: lxsameer
GPG Key ID: 8741FACBF412FFA5
8 changed files with 119 additions and 76 deletions

View File

@ -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 <lxsameer@gnu.org>
;;
;; Author: Sameer Rahmani <lxsameer@gnu.org>
;; 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 <http://www.gnu.org/licenses/>.
;;
;;; 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)

View File

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

View File

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

View File

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

View File

@ -0,0 +1,40 @@
;;; FG42 --- The mighty editor for the emacsians -*- lexical-binding: t; -*-
;;
;; Copyright (c) 2010-2024 Sameer Rahmani & Contributors
;;
;; Author: Sameer Rahmani <lxsameer@gnu.org>
;; 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 <http://www.gnu.org/licenses/>.
;;
;;; 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

View File

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

View File

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

View File

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