forked from FG42/FG42
1
0
Fork 0

Add support for installing packages temporarily via Nix.

This patch creates a new macro on fpkg called `try!` which
is similar to `use!` but only for the running session.
This commit is contained in:
Sameer Rahmani 2024-04-28 19:06:45 +01:00
parent 5f2662ded6
commit b6abd6fce9
Signed by: lxsameer
GPG Key ID: 8741FACBF412FFA5
4 changed files with 201 additions and 144 deletions

View File

@ -50,14 +50,16 @@
''; '';
}; };
fg42 = pkgs.callPackage ./nix/fg42 { app = pkgs.callPackage ./nix/fg42 {
inherit nixpkgs; inherit nixpkgs;
extraPackages = { extraPackages = {
noether = inputs.noether.outputs.packages.${system}.default; noether = inputs.noether.outputs.packages.${system}.default;
}; };
}; };
fg42-wm = pkgs.callPackage ./nix/fg42 { fg42 = app.drv;
fg42-wm = pkgs.callPackage ./nix/fg42
{
inherit nixpkgs; inherit nixpkgs;
modules = [ modules = [
./nix/modules/editor ./nix/modules/editor
@ -69,7 +71,7 @@
extraPackages = { extraPackages = {
noether = inputs.noether.outputs.packages.${system}.default; noether = inputs.noether.outputs.packages.${system}.default;
}; };
}; }.drv;
run-test-wm = pkgs.writeShellApplication { run-test-wm = pkgs.writeShellApplication {
name = "run-test-wm"; name = "run-test-wm";
@ -82,7 +84,7 @@
in in
{ {
packages = { packages = app.emacsPkgs // {
default = fg42; default = fg42;
wm = fg42-wm; wm = fg42-wm;
}; };

View File

@ -64,10 +64,12 @@ let
}; };
in in
stdenv.mkDerivation rec { {
emacsPkgs = (emacsPackagesFor emacs);
drv =
stdenv.mkDerivation rec {
inherit version src pname; inherit version src pname;
buildPhase = '' buildPhase = ''
runHook preBuild runHook preBuild
@ -138,6 +140,7 @@ stdenv.mkDerivation rec {
export PATH=${pathsStr}:$PATH export PATH=${pathsStr}:$PATH
export FONTCONFIG_FILE="$LISPDIR/fonts.conf" export FONTCONFIG_FILE="$LISPDIR/fonts.conf"
export STARTUP_FILE=$LISPDIR/lisp/fg42_init.el export STARTUP_FILE=$LISPDIR/lisp/fg42_init.el
export FG42_PATH=$out
LIBRARY_PATH="\$(${stdenv.cc}/bin/cc -print-file-name=libgccjit.so):\$LIBRARY_PATH" \ LIBRARY_PATH="\$(${stdenv.cc}/bin/cc -print-file-name=libgccjit.so):\$LIBRARY_PATH" \
FG42_WM=fales ${emacsBundle}/bin/emacs \ FG42_WM=fales ${emacsBundle}/bin/emacs \
@ -162,6 +165,7 @@ stdenv.mkDerivation rec {
export PATH=${pathsStr}:\$PATH export PATH=${pathsStr}:\$PATH
export FONTCONFIG_FILE="$LISPDIR/fonts.conf" export FONTCONFIG_FILE="$LISPDIR/fonts.conf"
export STARTUP_FILE=$LISPDIR/lisp/fg42_init.el export STARTUP_FILE=$LISPDIR/lisp/fg42_init.el
export FG42_PATH=$out
# Disable access control for the current user. # Disable access control for the current user.
${xorg.xhost}/bin/xhost +SI:localuser:\$USER ${xorg.xhost}/bin/xhost +SI:localuser:\$USER
@ -192,6 +196,12 @@ stdenv.mkDerivation rec {
runHook postBuild runHook postBuild
''; '';
postInstall = ''
nixDir=$out/share/fg42/;
mkdir -p $nixDir
cp -rv flake.nix flake.lock nix/ $nixDir
'';
buildInputs = [ emacs emacsBundle git texinfo gcc bash ]; buildInputs = [ emacs emacsBundle git texinfo gcc bash ];
addEmacsNativeLoadPath = true; addEmacsNativeLoadPath = true;
@ -211,4 +221,6 @@ stdenv.mkDerivation rec {
''; '';
license = lib.licenses.gpl3Plus; license = lib.licenses.gpl3Plus;
}; };
};
} }

View File

@ -29,11 +29,18 @@
(defvar package-archives) (defvar package-archives)
(defvar use-package-ensure-function)) (defvar use-package-ensure-function))
(defun fg42-version () (defun fg42-version ()
"Return FG42's version." "Return FG42's version."
(interactive) (interactive)
(message "FG42 Version %s" (fg42/config-get "version"))) (message "FG42 Version %s" (fg42/config-get "version")))
(defun fg42-path ()
"Return the path to FG42's installation."
(or (getenv "FG42_PATH") (error "'FG42_PATH' is not set!")))
(defun defer-garbage-collection () (defun defer-garbage-collection ()
"Disable garbage collection." "Disable garbage collection."
(setq gc-cons-threshold fg42/-gc-cons-threshold)) (setq gc-cons-threshold fg42/-gc-cons-threshold))

View File

@ -74,5 +74,41 @@ same NAME is set to t."
(use! ,name ,docs ,@details))) (use! ,name ,docs ,@details)))
(defun add-to-emacs-load-path (p)
"Add the path P to Emacs's load path."
(when (file-directory-p p)
(add-to-list 'load-path p)))
(defun add-emacs-vars (p)
"Make the path P available to Emacs."
(require 'f)
(require 'seq)
(seq-reduce
(lambda (acc x)
(when (not (member x acc))
(when (f-glob "*.el" x)
(cons x acc)
(add-to-emacs-load-path x))))
(append
(f-directories (format "%s/share/emacs/site-lisp" p) nil t)
(f-directories (format "%s/share/emacs/native-lisp" p) nil t))
nil))
(defmacro try! (pkg &rest details)
"Try the PKG with the given DETAILS in the running session."
(let ((flake-dir (format "%s/share/fg42" (fg42-path)))
(cwd (getenv "PWD")))
(cd flake-dir)
(let* ((output (shell-command-to-string
(format "nix build '.#%s' --no-link --print-out-paths" pkg)))
(out (car (string-split output "\n" t))))
(add-emacs-vars out)
(cd cwd)
out)))
(provide 'fpkg) (provide 'fpkg)
;;; fpkg.el ends here ;;; fpkg.el ends here