FG42/nix/fg42.nix

204 lines
5.8 KiB
Nix
Raw Normal View History

# Fg42 - Emacs Editor for advance users
#
2024-02-18 16:08:02 +00:00
# Copyright (c) 2010-2024 Sameer Rahmani <lxsameer@gnu.org>
#
# 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, version 2.
#
# 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/>.
2024-03-27 23:50:44 +00:00
{ lib, stdenv, elispPkgs, srcDir, emacsPackagesFor, ourPackages, direnv
, makeDesktopItem, nix
, nil, # nix lsp server
# python deps
python311, python3Packages,
# This is a set of system tools required for FG42
# to work.
pyright, emacs, ripgrep, git, texinfo, vazir-fonts, fira-code, nerdfonts
, fira-mono, noto-fonts, gcc, ltex-ls, bash, tree-sitter,
supportWM ? true, xorg, slock,
supportPython ? true, supportVerilog ? true, svls, verilator, }:
with builtins;
2024-02-22 14:19:57 +00:00
let
2024-03-27 23:50:44 +00:00
version = "4.0.0";
2024-02-22 14:19:57 +00:00
getPkg = epkgs: pkg:
2024-03-27 23:50:44 +00:00
if hasAttr pkg epkgs then getAttr pkg epkgs else getAttr pkg ourPackages;
2024-02-22 14:19:57 +00:00
emacsBundle = (emacsPackagesFor emacs).withPackages (epkgs:
2024-03-27 23:50:44 +00:00
(map (x: getPkg epkgs x) elispPkgs)
++ [ epkgs.treesit-grammars.with-all-grammars ]);
2024-02-22 14:19:57 +00:00
maintainers = import ./maintainers.nix;
2024-02-29 17:40:45 +00:00
2024-03-27 23:50:44 +00:00
runtimeBins = [ ripgrep git ltex-ls tree-sitter direnv nix nil ]
++ (lib.optional supportPython [
python311
# Python deps
python311
pyright
python3Packages.black
python3Packages.pylint
python3Packages.flake8
]) ++ (lib.optional supportVerilog [ svls ])
++ (lib.optional (supportVerilog && stdenv.isLinux) [
# SystemC is required by verilator that at the
# moment is only available on Linux
verilator
]) ++ (lib.optional (supportWM && stdenv.isLinux) [
# Window manager supports works on Linux only
xorg.xhost
slock
]);
paths = map (x: "${x}/bin/") (lib.lists.flatten runtimeBins);
pathsStr = lib.strings.concatStrings (lib.strings.intersperse ":" paths);
2024-03-27 23:50:44 +00:00
in stdenv.mkDerivation (final: rec {
inherit version;
pname = "fg42";
2024-03-27 23:50:44 +00:00
desktop = makeDesktopItem {
name = "FG42";
desktopName = "FG42";
exec = "${placeholder "out"}/bin/fg42 %F";
comment = "Emacs Editor for advance users";
};
# [Desktop Entry]
# Encoding=UTF-8
# Name=FG42
# GenericName=FG42
# Comment=
# MimeType=text/x-makefile;text/x-c++hdr;text/x-c++src;text/x-java;application/x-shellscript;text/x-c;text/x-c++;text/x-ruby;text/x-python;text/x-clojure;text/css;text/html;text/x-javascript;
# Type=Application
# Terminal=false
# Categories=Development;TextEditor;
# StartupWMClass=FG42
# Exec=
# Icon=fg42
# Version=${version}
# '';
2024-02-22 14:19:57 +00:00
src = srcDir;
outputs = [ "out" ];
2024-03-27 23:50:44 +00:00
buildPhase = ''
2024-02-22 14:19:57 +00:00
LISPDIR=$out/share/fg42/
mkdir -p $out/bin
install -d $LISPDIR
2024-02-22 14:19:57 +00:00
cp -rv ${src}/lisp/ $LISPDIR
cp -rv ${src}/share $out/
cp -rv ${src}/snippets $LISPDIR/snippets
2024-02-22 14:19:57 +00:00
runHook preBuild
cd $LISPDIR
emacs -L . --batch -f batch-byte-compile *.el
cd -
cat >> $out/bin/fg42 << 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
2024-02-22 14:19:57 +00:00
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 \$FG42_HOME/lisp/fg42/init.el "\$@"
EOF
chmod +x $out/bin/fg42
runHook postBuild
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;
2024-03-09 22:00:49 +00:00
export PATH=${pathsStr}:\$PATH
2024-02-22 14:19:57 +00:00
# Disable access control for the current user.
2024-03-09 22:00:49 +00:00
${xorg.xhost}/bin/xhost +SI:localuser:\$USER
2024-02-22 14:19:57 +00:00
# Make Java applications aware this is a non-reparenting window manager.
export _JAVA_AWT_WM_NONREPARENTING=1
# Set default cursor.
xsetroot -cursor_name left_ptr
# Set keyboard repeat rate.
xset r rate 400 30
# 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
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 \$FG42_HOME/lisp/fg42/init.el "\$@"
EOF
chmod +x $out/bin/fg42-wm
cat >> $out/share/runtiem_deps << EOF
${vazir-fonts}
${fira-code}
2024-03-27 23:50:44 +00:00
${fira-mono}
2024-02-22 14:19:57 +00:00
${nerdfonts}
${noto-fonts}
${lib.strings.concatLines paths}
2024-03-27 23:50:44 +00:00
${desktop}/share/applications/FG42.desktop
2024-02-22 14:19:57 +00:00
EOF
runHook postBuild
'';
installPhase = ''
2024-03-27 23:50:44 +00:00
runHook preInstall
2024-03-27 23:50:44 +00:00
#LISPDIR=$out/share/fg42/lisp/
#emacs --batch -l package --eval "(package-generate-autoloads \"${pname}\" \"$LISPDIR\")"
2024-03-27 23:50:44 +00:00
runHook postInstall
'';
2024-03-27 23:50:44 +00:00
buildInputs = [ emacs emacsBundle git texinfo gcc bash ];
2024-02-22 14:19:57 +00:00
addEmacsNativeLoadPath = true;
meta = {
broken = false;
platforms = emacs.meta.platforms;
homepage = "https://fg42.org/";
maintainers = [ maintainers.lxsameer ];
description = "The mighty editor for the emacsians";
longDescription = ''
2024-03-27 23:50:44 +00:00
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.
2024-03-27 23:50:44 +00:00
So you need to know about Emacs in advance.
'';
2024-02-22 14:19:57 +00:00
license = lib.licenses.gpl3Plus;
};
2024-02-22 14:19:57 +00:00
})