From ffe76864706519bdf5b16a35fd8ff8330efc6b5e Mon Sep 17 00:00:00 2001 From: Sameer Rahmani Date: Sun, 18 Feb 2024 15:50:18 +0000 Subject: [PATCH] Fix several discrepancies on dependencies --- core/cubes/project.el | 2 -- core/cubes/python.el | 2 -- core/fpkg.el | 46 ++++++++++++++++++++++++++----------------- core/fpkg/core.el | 32 ++++++++++++++++++------------ deps.el | 6 +----- fg42-config.el | 11 ++++++++++- flake.nix | 19 +++++++++++++++--- nix/fg42.nix | 37 +++++++++++++++------------------- 8 files changed, 90 insertions(+), 65 deletions(-) diff --git a/core/cubes/project.el b/core/cubes/project.el index f528132..b7149cb 100644 --- a/core/cubes/project.el +++ b/core/cubes/project.el @@ -51,7 +51,5 @@ :after projectile))) - - (provide 'cubes/project) ;;; project.el ends here diff --git a/core/cubes/python.el b/core/cubes/python.el index 90f54a2..d9214a8 100644 --- a/core/cubes/python.el +++ b/core/cubes/python.el @@ -90,7 +90,6 @@ interactive `pyvenv-workon' function before `lsp'" :flag-default t (fpkg/use lsp-pyright - :ensure t :after (python lsp-mode) :hook (python-mode . (lambda () @@ -129,7 +128,6 @@ interactive `pyvenv-workon' function before `lsp'" (pyvenv-post-deactivate-hooks . pyvenv-restart-python))) (fpkg/use pyenv-mode - :ensure t :after python :hook (python-mode-hook . pyenv-mode)) diff --git a/core/fpkg.el b/core/fpkg.el index ffd968a..d6667ce 100644 --- a/core/fpkg.el +++ b/core/fpkg.el @@ -24,36 +24,46 @@ ;; Simple package manager for FG42 ;; ;;; Code: -;;(require 'use-package) + +(require 'map) (defvar package-names ()) +(eval-when-compile + (defvar fg42-use-nix)) ;; defined in fg42-config.el + (defun inject-straight (args) "Inject `:straight t' to ARGS it the key was missing." - (if (member :straight args) - args - (append args '(:straight t)))) + (if fg42-use-nix + ;; We don't use straight with nix + (map-delete args :straight) + (if (member :straight args) + args + (append args '(:straight t))))) -(defun inject-defer (args) - "Inject `:defer t' to ARGS it the key was missing." - (if (member :defer args) - args - (append args '(:defer t)))) +(defun inject-params (args) + "Inject required `use-package' params to ARGS if the key is missing." + (if fg42-use-nix + (append '(:ensure nil) args) + ;; (if (member :defer args) + ;; args + ;; (append args '(:defer t))) + args)) (defmacro fpkg/use (pkg &rest details) - "Install the given package DETAILS PKG via use-package and straight." + "Install the given package DETAILS PKG via `use-package' and straight." (declare (indent defun)) - (if (and (listp details) (< 0 (length details))) - (let ((params (inject-straight (inject-defer details)))) - (progn - (add-to-list 'package-names pkg) - `(use-package ,pkg ,@params))) - (progn - (add-to-list 'package-names pkg) - `(use-package ,pkg :straight t :defer t)))) + (let ((params (inject-straight (inject-params details)))) + + `(progn + (require ,pkg) + (use-package ,pkg ,@params))) + `(progn + (require ,pkg) + (use-package ,pkg :defer t :ensure nil)))) (defmacro fpkg/require (pkg) diff --git a/core/fpkg/core.el b/core/fpkg/core.el index de84eb7..1d48985 100644 --- a/core/fpkg/core.el +++ b/core/fpkg/core.el @@ -36,28 +36,34 @@ (defun fpkg/install-and-load-use-package () - "Install and load the use-package in compile time." + "Install and load the `use-package' in compile time." ;; TODO Enable use-package on compile time ;;(eval-when-compile) - (straight-use-package 'use-package) - (setq use-package-always-ensure t) + + (if fg42-use-nix + (setq use-package-always-ensure nil) + (progn + (setq use-package-always-ensure t) + (straight-use-package 'use-package))) (require 'use-package)) (defun fpkg/initialize () "Initialize FPKG." - (let ((bootstrap-file - (expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))) + (if (null fg42-use-nix) + (let ((bootstrap-file + (expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))) - (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) + (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) + (fpkg/install-and-load-use-package)) (fpkg/install-and-load-use-package))) diff --git a/deps.el b/deps.el index 3b221e0..e9ddbde 100644 --- a/deps.el +++ b/deps.el @@ -71,18 +71,14 @@ poetry lsp-pyright python-black - lsp-java flycheck-gradle gradle-mode groovy-mode - + use-package vterm - projectile-ripgrep - go-mode - company-box company lsp-ui diff --git a/fg42-config.el b/fg42-config.el index 4b5d184..680e099 100644 --- a/fg42-config.el +++ b/fg42-config.el @@ -22,12 +22,21 @@ ;;; Commentary: ;;; Code: (setq debug-on-error t) -(defvar fg42-v3 "true") + +(eval-when-compile + (defvar package-archives) + (defvar use-package-ensure-function)) + +(defvar fg42-use-nix (or (getenv "FG42_USE_NIX") nil)) (add-to-list 'load-path (concat (getenv "FG42_HOME") "/core")) ;; Prevent package.el to install anything at startup (setq package-enable-at-startup nil) +(setq package-archives nil) + +(when fg42-use-nix + (setq use-package-ensure-function 'ignore)) (setq tab-width 2) diff --git a/flake.nix b/flake.nix index f5d25c1..1b71e66 100644 --- a/flake.nix +++ b/flake.nix @@ -26,6 +26,12 @@ inherit system; overlays = [ inputs.emacs-overlay.overlays.package ]; }; + + lemacs = pkgs.emacs29.override { + withGTK3 = false; + toolkit = "lucid"; + }; + elispDepsFile = ./deps.el; elispPkgs = pkgs.callPackage ./nix/deps.nix { @@ -37,18 +43,23 @@ fg42 = pkgs.callPackage ./nix/fg42.nix { inherit elispPkgs ourPackages; srcDir = ./.; + emacs = lemacs; }; in { inherit pkgs; + packages.emacs = fg42.emacsInUse; packages.default = pkgs.writeScriptBin "fg42" '' #!${pkgs.stdenv.shell} export FG42_HOME=${fg42}/fg42 - LIBRARY_PATH="$(cc -print-file-name=libgccjit.so):$LIBRARY_PATH" FG42_WM=false emacs \ + export FG42_USE_NIX=true; + + LIBRARY_PATH="$(cc -print-file-name=libgccjit.so):$LIBRARY_PATH" \ + FG42_WM=false ${fg42.emacsInUse}/bin/emacs \ --name FG42 \ - --no-site-file --no-site-lisp \ + -q \ --no-splash --title FG42 \ -l $FG42_HOME/fg42-config.el "$@" ''; @@ -74,8 +85,10 @@ #export QT_IM_MODULE=xim #export CLUTTER_IM_MODULE=xim + export FG42_USE_NIX=true; export FG42_HOME=${fg42}/fg42 - LIBRARY_PATH=$(cc -print-file-name=libgccjit.so):$LIBRARY_PATH FG42_WM=true emacs \ + LIBRARY_PATH=$(cc -print-file-name=libgccjit.so):$LIBRARY_PATH \ + FG42_WM=true ${fg42.emacsInUse}/bin/emacs \ --name FG42 \ --no-site-file --no-site-lisp \ --no-splash --title FG42 \ diff --git a/nix/fg42.nix b/nix/fg42.nix index e1bf1e7..f651c05 100644 --- a/nix/fg42.nix +++ b/nix/fg42.nix @@ -17,6 +17,7 @@ stdenv, elispPkgs, srcDir, + emacsPackagesFor, emacsPackages, ourPackages, writeScriptBin, @@ -33,11 +34,16 @@ }: with builtins; let - getEpkg = (x: if hasAttr x emacsPackages - then getAttr x emacsPackages - else getAttr x ourPackages); + getEpkg = epkgs: x: + if hasAttr x epkgs + then getAttr x epkgs + else getAttr x ourPackages; - epkgs = (map getEpkg elispPkgs); + epkgSet = emacsPackagesFor emacs; + #epkgs = (map getEpkg elispPkgs); + emacsBundle = epkgSet.emacsWithPackages (epkgs: + (map (getEpkg epkgs) elispPkgs) + ); in stdenv.mkDerivation (final: rec{ pname = "fg42"; @@ -46,8 +52,6 @@ in stdenv.mkDerivation (final: rec{ src = srcDir; outputs = [ "out" ]; - FG42_USE_NIX = true; - buildPhase = '' mkdir -p $out/fg42 mkdir -p $out/bin/ @@ -64,6 +68,7 @@ in stdenv.mkDerivation (final: rec{ runHook postBuild ''; + installPhase = '' runHook preInstall @@ -75,26 +80,16 @@ in stdenv.mkDerivation (final: rec{ runHook postInstall ''; - - # scripts = symlinkJoin { - # name = "fg42_scripts"; - # paths = [ - # editor - # wm - # ]; - # }; - - #nativeBuildInputs = deps; - buildInputs = epkgs ++ [ + propagatedUserEnvPkgs = [ + emacsBundle ripgrep git texinfo vazir-fonts fira-code nerdfonts - #scripts ]; - # depsTargetTarget = [ - # pkgs.emacs - # ]; + buildInputs = propagatedUserEnvPkgs; + + emacsInUse = emacsBundle; })