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,26 +50,28 @@
''; '';
}; };
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;
inherit nixpkgs; fg42-wm = pkgs.callPackage ./nix/fg42
modules = [ {
./nix/modules/editor inherit nixpkgs;
./nix/modules/elisp modules = [
./nix/modules/graphics ./nix/modules/editor
./nix/modules/noether ./nix/modules/elisp
./nix/modules/wm ./nix/modules/graphics
]; ./nix/modules/noether
extraPackages = { ./nix/modules/wm
noether = inputs.noether.outputs.packages.${system}.default; ];
}; extraPackages = {
}; 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,151 +64,163 @@ let
}; };
in 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}
# ============================= export PATH=${pathsStr}:$PATH
# Building FG42 itself export FONTCONFIG_FILE="$LISPDIR/fonts.conf"
# ============================= export STARTUP_FILE=$LISPDIR/lisp/fg42_init.el
LISPDIR=$out/share/fg42/ export FG42_PATH=$out
STARTUP_FILE=$LISPDIR/lisp/fg42_init.el
mkdir -p $out/bin LIBRARY_PATH="\$(${stdenv.cc}/bin/cc -print-file-name=libgccjit.so):\$LIBRARY_PATH" \
mkdir -p $out/share/applications/ FG42_WM=fales ${emacsBundle}/bin/emacs \
--name FG42 \
install -d $LISPDIR -q --no-splash --title FG42 \
-l "$STARTUP_FILE" "\$@"
mkdir -p $LISPDIR/lisp EOF
cp -rv ${src}/lisp/build.el $LISPDIR/lisp chmod +x $out/bin/fg42
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
# ============================= LISPDIR=$out/share/fg42/lisp/
# Creating fg42 command mkdir -p $LISPDIR
# ============================= #emacs --batch -l package --eval "(package-generate-autoloads \"${pname}\" \"$LISPDIR\")"
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 # Creating the fg42-wm command
#emacs --batch -l package --eval "(package-generate-autoloads \"${pname}\" \"$LISPDIR\")" # =============================
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
# ============================= # Disable access control for the current user.
# Creating the fg42-wm command ${xorg.xhost}/bin/xhost +SI:localuser:\$USER
# =============================
cat >> $out/bin/fg42-wm << EOF
#!${stdenv.shell}
export PATH=${pathsStr}:\$PATH # Make Java applications aware this is a non-reparenting window manager.
export FONTCONFIG_FILE="$LISPDIR/fonts.conf" export _JAVA_AWT_WM_NONREPARENTING=1
export STARTUP_FILE=$LISPDIR/lisp/fg42_init.el
# Disable access control for the current user. # Set default cursor.
${xorg.xhost}/bin/xhost +SI:localuser:\$USER xsetroot -cursor_name left_ptr
# Make Java applications aware this is a non-reparenting window manager. # Set keyboard repeat rate.
export _JAVA_AWT_WM_NONREPARENTING=1 xset r rate 400 30
# Set default cursor. # Uncomment the following block to use the exwm-xim module.
xsetroot -cursor_name left_ptr # export XMODIFIERS=@im=exwm-xim
# export GTK_IM_MODULE=xim
# export QT_IM_MODULE=xim
# export CLUTTER_IM_MODULE=xim
# Set keyboard repeat rate. LIBRARY_PATH="\$(${stdenv.cc}/bin/cc -print-file-name=libgccjit.so):\$LIBRARY_PATH" \
xset r rate 400 30 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. runHook postBuild
# export XMODIFIERS=@im=exwm-xim '';
# export GTK_IM_MODULE=xim
# export QT_IM_MODULE=xim
# export CLUTTER_IM_MODULE=xim
LIBRARY_PATH="\$(${stdenv.cc}/bin/cc -print-file-name=libgccjit.so):\$LIBRARY_PATH" \ postInstall = ''
FG42_WM=true ${emacsBundle}/bin/emacs \ nixDir=$out/share/fg42/;
--name FG42 \ mkdir -p $nixDir
-q --no-splash --title FG42 \ cp -rv flake.nix flake.lock nix/ $nixDir
-l $STARTUP_FILE "\$@" '';
EOF
chmod +x $out/bin/fg42-wm
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 = { So you need to know about Emacs in advance.
broken = false; '';
platforms = emacs.meta.platforms; license = lib.licenses.gpl3Plus;
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;
};
} }

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))
@ -84,15 +91,15 @@
(run-hooks 'fg42/before-user-config-init-hook) (run-hooks 'fg42/before-user-config-init-hook)
(require 'fg42/themes) (require 'fg42/themes)
(when (file-exists-p user-init-file) (when (file-exists-p user-init-file)
(load user-init-file)) (load user-init-file))
(run-hooks 'fg42/after-user-config-init-hook) (run-hooks 'fg42/after-user-config-init-hook)
(fg42/setup-theme!) (fg42/setup-theme!)
;; (fg42/setup-editor) ;; (fg42/setup-editor)
(add-hook 'emacs-startup-hook (add-hook 'emacs-startup-hook
(lambda () (lambda ()
(run-hooks 'fg42/after-init-hook) (run-hooks 'fg42/after-init-hook)

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