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,26 +50,28 @@
'';
};
fg42 = pkgs.callPackage ./nix/fg42 {
app = pkgs.callPackage ./nix/fg42 {
inherit nixpkgs;
extraPackages = {
noether = inputs.noether.outputs.packages.${system}.default;
};
};
fg42-wm = pkgs.callPackage ./nix/fg42 {
inherit nixpkgs;
modules = [
./nix/modules/editor
./nix/modules/elisp
./nix/modules/graphics
./nix/modules/noether
./nix/modules/wm
];
extraPackages = {
noether = inputs.noether.outputs.packages.${system}.default;
};
};
fg42 = app.drv;
fg42-wm = pkgs.callPackage ./nix/fg42
{
inherit nixpkgs;
modules = [
./nix/modules/editor
./nix/modules/elisp
./nix/modules/graphics
./nix/modules/noether
./nix/modules/wm
];
extraPackages = {
noether = inputs.noether.outputs.packages.${system}.default;
};
}.drv;
run-test-wm = pkgs.writeShellApplication {
name = "run-test-wm";
@ -82,7 +84,7 @@
in
{
packages = {
packages = app.emacsPkgs // {
default = fg42;
wm = fg42-wm;
};

View File

@ -64,151 +64,163 @@ let
};
in
stdenv.mkDerivation rec {
inherit version src pname;
{
emacsPkgs = (emacsPackagesFor emacs);
drv =
stdenv.mkDerivation rec {
inherit version src pname;
buildPhase = ''
runHook preBuild
# =============================
# Building FG42 itself
# =============================
LISPDIR=$out/share/fg42/
STARTUP_FILE=$LISPDIR/lisp/fg42_init.el
mkdir -p $out/bin
mkdir -p $out/share/applications/
install -d $LISPDIR
mkdir -p $LISPDIR/lisp
cp -rv ${src}/lisp/build.el $LISPDIR/lisp
cp -rv ${src}/share $out/
cp -rv ${src}/snippets $LISPDIR/snippets
cp "${fontsConf}" $LISPDIR/fonts.conf
cp "${configFile}" $LISPDIR/config.json
export FONTCONFIG_FILE="$LISPDIR/fonts.conf"
chmod 755 $LISPDIR -R
emacs --batch -l $LISPDIR/lisp/build.el $LISPDIR/config.json $STARTUP_FILE
#emacs -Q --batch -l package --eval "(package-generate-autoloads \"fg42_init" \"$LISPDIR\")"
emacs --batch -l loaddefs-gen -f loaddefs-generate-batch $LISPDIR/lisp/ $LISPDIR/lisp/ ${emacsBundle}
cd $LISPDIR
#compile stuff
cd -
# =============================
# Creating the desktop file
# =============================
cat >> $out/share/applications/FG42.desktop << EOF
[Desktop Entry]
Encoding=UTF-8
Name=FG42
GenericName=FG42
Comment=The nix base Emacs bundle for advance users
MimeType=${mimeTypes}
Type=Application
Terminal=false
Categories=Development;TextEditor;
StartupWMClass=FG42
Exec=${placeholder "out"}/bin/fg42
Icon=fg42
Version=${version}
EOF
# =============================
# Adding the runtime deps to
# runtime closure
# =============================
cat >> $out/share/runtime_deps << EOF
${lib.strings.concatLines runtimeDependencies}
${emacsBundle}
EOF
buildPhase = ''
runHook preBuild
# =============================
# Creating fg42 command
# =============================
cat >> $out/bin/fg42 << EOF
#!${stdenv.shell}
# =============================
# Building FG42 itself
# =============================
LISPDIR=$out/share/fg42/
STARTUP_FILE=$LISPDIR/lisp/fg42_init.el
export PATH=${pathsStr}:$PATH
export FONTCONFIG_FILE="$LISPDIR/fonts.conf"
export STARTUP_FILE=$LISPDIR/lisp/fg42_init.el
export FG42_PATH=$out
mkdir -p $out/bin
mkdir -p $out/share/applications/
install -d $LISPDIR
mkdir -p $LISPDIR/lisp
cp -rv ${src}/lisp/build.el $LISPDIR/lisp
cp -rv ${src}/share $out/
cp -rv ${src}/snippets $LISPDIR/snippets
cp "${fontsConf}" $LISPDIR/fonts.conf
cp "${configFile}" $LISPDIR/config.json
export FONTCONFIG_FILE="$LISPDIR/fonts.conf"
chmod 755 $LISPDIR -R
emacs --batch -l $LISPDIR/lisp/build.el $LISPDIR/config.json $STARTUP_FILE
#emacs -Q --batch -l package --eval "(package-generate-autoloads \"fg42_init" \"$LISPDIR\")"
emacs --batch -l loaddefs-gen -f loaddefs-generate-batch $LISPDIR/lisp/ $LISPDIR/lisp/ ${emacsBundle}
cd $LISPDIR
#compile stuff
cd -
# =============================
# Creating the desktop file
# =============================
cat >> $out/share/applications/FG42.desktop << EOF
[Desktop Entry]
Encoding=UTF-8
Name=FG42
GenericName=FG42
Comment=The nix base Emacs bundle for advance users
MimeType=${mimeTypes}
Type=Application
Terminal=false
Categories=Development;TextEditor;
StartupWMClass=FG42
Exec=${placeholder "out"}/bin/fg42
Icon=fg42
Version=${version}
EOF
# =============================
# Adding the runtime deps to
# runtime closure
# =============================
cat >> $out/share/runtime_deps << EOF
${lib.strings.concatLines runtimeDependencies}
${emacsBundle}
EOF
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 "$STARTUP_FILE" "\$@"
EOF
chmod +x $out/bin/fg42
# =============================
# Creating fg42 command
# =============================
cat >> $out/bin/fg42 << EOF
#!${stdenv.shell}
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 "$STARTUP_FILE" "\$@"
EOF
chmod +x $out/bin/fg42
LISPDIR=$out/share/fg42/lisp/
mkdir -p $LISPDIR
#emacs --batch -l package --eval "(package-generate-autoloads \"${pname}\" \"$LISPDIR\")"
LISPDIR=$out/share/fg42/lisp/
mkdir -p $LISPDIR
#emacs --batch -l package --eval "(package-generate-autoloads \"${pname}\" \"$LISPDIR\")"
# =============================
# Creating the fg42-wm command
# =============================
cat >> $out/bin/fg42-wm << EOF
#!${stdenv.shell}
export PATH=${pathsStr}:\$PATH
export FONTCONFIG_FILE="$LISPDIR/fonts.conf"
export STARTUP_FILE=$LISPDIR/lisp/fg42_init.el
export FG42_PATH=$out
# =============================
# Creating the fg42-wm command
# =============================
cat >> $out/bin/fg42-wm << EOF
#!${stdenv.shell}
# Disable access control for the current user.
${xorg.xhost}/bin/xhost +SI:localuser:\$USER
export PATH=${pathsStr}:\$PATH
export FONTCONFIG_FILE="$LISPDIR/fonts.conf"
export STARTUP_FILE=$LISPDIR/lisp/fg42_init.el
# Make Java applications aware this is a non-reparenting window manager.
export _JAVA_AWT_WM_NONREPARENTING=1
# Disable access control for the current user.
${xorg.xhost}/bin/xhost +SI:localuser:\$USER
# Set default cursor.
xsetroot -cursor_name left_ptr
# Make Java applications aware this is a non-reparenting window manager.
export _JAVA_AWT_WM_NONREPARENTING=1
# Set keyboard repeat rate.
xset r rate 400 30
# Set default cursor.
xsetroot -cursor_name left_ptr
# Uncomment the following block to use the exwm-xim module.
# export XMODIFIERS=@im=exwm-xim
# export GTK_IM_MODULE=xim
# export QT_IM_MODULE=xim
# export CLUTTER_IM_MODULE=xim
# Set keyboard repeat rate.
xset r rate 400 30
LIBRARY_PATH="\$(${stdenv.cc}/bin/cc -print-file-name=libgccjit.so):\$LIBRARY_PATH" \
FG42_WM=true ${emacsBundle}/bin/emacs \
--name FG42 \
-q --no-splash --title FG42 \
-l $STARTUP_FILE "\$@"
EOF
chmod +x $out/bin/fg42-wm
# Uncomment the following block to use the exwm-xim module.
# export XMODIFIERS=@im=exwm-xim
# export GTK_IM_MODULE=xim
# export QT_IM_MODULE=xim
# export CLUTTER_IM_MODULE=xim
runHook postBuild
'';
LIBRARY_PATH="\$(${stdenv.cc}/bin/cc -print-file-name=libgccjit.so):\$LIBRARY_PATH" \
FG42_WM=true ${emacsBundle}/bin/emacs \
--name FG42 \
-q --no-splash --title FG42 \
-l $STARTUP_FILE "\$@"
EOF
chmod +x $out/bin/fg42-wm
postInstall = ''
nixDir=$out/share/fg42/;
mkdir -p $nixDir
cp -rv flake.nix flake.lock nix/ $nixDir
'';
runHook postBuild
'';
buildInputs = [ emacs emacsBundle git texinfo gcc bash ];
buildInputs = [ emacs emacsBundle git texinfo gcc bash ];
addEmacsNativeLoadPath = true;
addEmacsNativeLoadPath = true;
meta = {
broken = false;
platforms = emacs.meta.platforms;
homepage = "https://fg42.org/";
maintainers = [ maintainers.lxsameer ];
description = "The mighty editor for the Emacsians";
longDescription = ''
FG42 is a framework to create and editor and window manager based on GNU/Emacs.
It has a pre-defined setup as well which can be installed out of the box. But the
goal of this project is to provide the API necessary to create an integrated editor.
meta = {
broken = false;
platforms = emacs.meta.platforms;
homepage = "https://fg42.org/";
maintainers = [ maintainers.lxsameer ];
description = "The mighty editor for the Emacsians";
longDescription = ''
FG42 is a framework to create and editor and window manager based on GNU/Emacs.
It has a pre-defined setup as well which can be installed out of the box. But the
goal of this project is to provide the API necessary to create an integrated editor.
So you need to know about Emacs in advance.
'';
license = lib.licenses.gpl3Plus;
};
};
So you need to know about Emacs in advance.
'';
license = lib.licenses.gpl3Plus;
};
}

View File

@ -29,11 +29,18 @@
(defvar package-archives)
(defvar use-package-ensure-function))
(defun fg42-version ()
"Return FG42's version."
(interactive)
(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 ()
"Disable garbage collection."
(setq gc-cons-threshold fg42/-gc-cons-threshold))
@ -84,15 +91,15 @@
(run-hooks 'fg42/before-user-config-init-hook)
(require 'fg42/themes)
(when (file-exists-p user-init-file)
(load user-init-file))
(run-hooks 'fg42/after-user-config-init-hook)
(fg42/setup-theme!)
;; (fg42/setup-editor)
(add-hook 'emacs-startup-hook
(lambda ()
(run-hooks 'fg42/after-init-hook)

View File

@ -74,5 +74,41 @@ same NAME is set to t."
(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)
;;; fpkg.el ends here