Revise the derivation to break down the config into nix modules

This commit is contained in:
Sameer Rahmani 2024-04-12 22:18:03 +01:00
parent 26c1a6074d
commit 1a0f2a31d2
Signed by: lxsameer
GPG Key ID: 8741FACBF412FFA5
9 changed files with 348 additions and 166 deletions

View File

@ -29,6 +29,16 @@
"x86_64-linux" "x86_64-linux"
]; ];
flake = {
# The home-manager integration. The can use FG42 with home-manager by including
# this module.
hm-module = rec {
fg42 = import ./nix/hm;
default = fg42;
};
};
perSystem = { config, self', inputs', pkgs, system, ... }: perSystem = { config, self', inputs', pkgs, system, ... }:
let let
test-x = pkgs.writeShellApplication { test-x = pkgs.writeShellApplication {
@ -39,30 +49,38 @@
${pkgs.xorg.xorgserver.out}/bin/Xephyr -br -ac -noreset -screen 800x600 :1 ${pkgs.xorg.xorgserver.out}/bin/Xephyr -br -ac -noreset -screen 800x600 :1
''; '';
}; };
noether = inputs.noether.outputs.packages.${system}.default;
factory = params: pkgs.callPackage ./nix/factory.nix ({ inherit noether; } // params); #noether = inputs.noether.outputs.packages.${system}.default;
default = (factory { }); fg42 = pkgs.callPackage ./nix/fg42 {
#extraModules = inputs.noether.outputs.fg42Modules.default;
};
run-test-wm = pkgs.writeShellApplication {
name = "run-test-wm";
runtimeInputs = [ fg42 ];
text = ''
DISPLAY=:1 ${fg42}/bin/fg42-wm
'';
};
# factory = params: pkgs.callPackage ./nix/factory.nix ({ inherit noether; } // params);
# default = (factory { });
in in
{ {
packages = { packages = {
default = default.fg42; default = fg42;
} // (pkgs.lib.optionalAttrs (system == "x86_64-linux") { };
# Gtk causes a flickering issue on WM mode
lucid = (factory { emacsParams.toolkit = "lucid"; }).fg42;
gtk3 = (factory { emacsParams.withGTK3 = true; }).fg42;
pgtk = (factory { emacsParams.withPgtk = true; }).fg42;
gtk2 = (factory { emacsParams.withGTK2 = true; }).fg42;
none = (factory { emacsParams.toolkit = "no"; }).fg42;
});
devShells.default = pkgs.mkShell { devShells.default = pkgs.mkShell {
nativeBuildInputs = [ default.fg42 pkgs.fish test-x default.run-test-wm ]; nativeBuildInputs = [ fg42 pkgs.fish test-x run-test-wm ];
buildInputs = [ default.fg42 ]; buildInputs = [ fg42 ];
}; };
apps.wm = { apps.wm = {
type = "app"; type = "app";
program = "${default.run-test-wm}/bin/run-test-wm"; program = "${run-test-wm}/bin/run-test-wm";
}; };
apps.x = { apps.x = {
@ -71,7 +89,7 @@
}; };
apps.default = { apps.default = {
type = "app"; type = "app";
program = "${default.fg42}/bin/fg42"; program = "${fg42}/bin/fg42";
}; };
}; };

View File

@ -13,44 +13,31 @@
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
{ lib
, stdenv # This is the home manager module that exposes FG42. It differs
, emacs29 # from FG42 modules that are structurally the same but used in
, callPackage # different context
, writeShellApplication { pkgs, lib ? pkgs.lib, modules ? null, extraModules ? [ ] }:
, noether with lib;
, emacsParams ? { }
, fg42Params ? { }
}:
let let
lemacs = emacs29.override ({ fg42Modules =
withTreeSitter = true; if modules != null
} // emacsParams); then modules
else
import ../modules {
inherit pkgs;
lib = lib;
};
elispDepsFile = ../lisp/fg42/deps.el; unitModule = import ./unit.nix { inherit pkgs lib; };
final = lib.evalModules {
elispPkgs = callPackage ./deps.nix { modules = [ unitModule ] ++ fg42Modules ++ extraModules;
inherit elispDepsFile;
}; };
ourPackages = {
noether-mode = noether;
};
fg42 = callPackage ./fg42.nix ({
inherit elispPkgs ourPackages;
srcDir = ../.;
emacs = lemacs;
} // fg42Params);
run-test-wm = writeShellApplication {
name = "run-test-wm";
runtimeInputs = [ fg42 ];
text = ''
DISPLAY=:1 ${fg42}/bin/fg42-wm
'';
};
in in
{ inherit fg42 run-test-wm; } pkgs.callPackage ./derivation.nix {
inherit (final) config options;
maintainers = import ../maintainers.nix;
utils = pkgs.callPackage ./utils.nix { };
}

View File

@ -14,128 +14,57 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
{ lib { lib
, config
, stdenv , stdenv
, elispPkgs
, srcDir
, emacsPackagesFor
, ourPackages
, direnv
, makeFontsConf
, nix
, nixpkgs-fmt
, nil
, # nix lsp server
# python deps
python311
, python3Packages
, # This is a set of system tools required for FG42
# to work.
pyright
, emacs
, ripgrep
, git , git
, texinfo , texinfo
, vazir-fonts
, fira-code
, nerdfonts
, fira-mono
, noto-fonts
, gcc , gcc
, ltex-ls
, bash , bash
, tree-sitter , utils
, fd , emacsPackagesFor
, aspellWithDicts , makeFontsConf
, supportWM ? true
, xorg , xorg
, slock , maintainers
, supportPython ? true , ...
, supportVerilog ? true
, svls
, verilator
,
}: }:
with builtins; with builtins;
let let
version = "4.0.0"; cfg = config.fg42;
getPkg = epkgs: pkg: emacs = cfg.emacs;
if hasAttr pkg epkgs then getAttr pkg epkgs else getAttr pkg ourPackages; version = cfg.version;
emacsBundle = (emacsPackagesFor emacs).withPackages (epkgs: emacsBundle = (emacsPackagesFor emacs).withPackages (_: cfg.elispPackages);
(map (x: getPkg epkgs x) elispPkgs)
++ [ epkgs.treesit-grammars.with-all-grammars ]);
maintainers = import ./maintainers.nix; paths = map (x: "${x}/bin/") cfg.paths;
dicts = aspellWithDicts (dicts: with dicts; [ en en-computers en-science ]);
runtimeBins = [
ripgrep
git
tree-sitter
direnv
nix
nil
dicts
fd
nixpkgs-fmt
]
++ (lib.optional (!stdenv.buildPlatform.isRiscV) [
# Not supported on Risc-V
ltex-ls
])
++ (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); pathsStr = lib.strings.concatStrings (lib.strings.intersperse ":" paths);
mimes = import ./mimes.nix; mimeTypes = builtins.concatStringsSep ";" cfg.mimeTypes;
fontsConf = makeFontsConf {
fontDirectories = [ fontsConf = makeFontsConf { fontDirectories = cfg.fonts; };
vazir-fonts
fira-code
nerdfonts
fira-mono
noto-fonts
];
};
in in
stdenv.mkDerivation (final: rec { stdenv.mkDerivation rec {
inherit version; inherit version;
pname = "fg42"; pname = "FG42";
src = srcDir;
outputs = [ "out" ]; src = ../../.;
buildPhase = '' buildPhase = ''
LISPDIR=$out/share/fg42/ LISPDIR=$out/share/fg42/
mkdir -p $out/bin mkdir -p $out/bin
mkdir -p $out/share/applications/ mkdir -p $out/share/applications/
install -d $LISPDIR install -d $LISPDIR
cp -rv ${src}/lisp/ $LISPDIR cp -rv ${src}/lisp/ $LISPDIR
cp -rv ${src}/share $out/ cp -rv ${src}/share $out/
cp -rv ${src}/snippets $LISPDIR/snippets cp -rv ${src}/snippets $LISPDIR/snippets
cp "${fontsConf}" $LISPDIR/fonts.conf cp "${fontsConf}" $LISPDIR/fonts.conf
chmod 755 $LISPDIR -R
export FONTCONFIG_FILE="$LISPDIR/fonts.conf" export FONTCONFIG_FILE="$LISPDIR/fonts.conf"
cat >> $out/share/applications/FG42.desktop << EOF cat >> $out/share/applications/FG42.desktop << EOF
@ -144,7 +73,7 @@ stdenv.mkDerivation (final: rec {
Name=FG42 Name=FG42
GenericName=FG42 GenericName=FG42
Comment=The nix base Emacs bundle for advance users Comment=The nix base Emacs bundle for advance users
MimeType=${mimes.mimeTypes} MimeType=${mimeTypes}
Type=Application Type=Application
Terminal=false Terminal=false
Categories=Development;TextEditor; Categories=Development;TextEditor;
@ -213,26 +142,17 @@ stdenv.mkDerivation (final: rec {
EOF EOF
chmod +x $out/bin/fg42-wm chmod +x $out/bin/fg42-wm
cat >> $out/share/runtiem_deps << EOF LISPDIR=$out/share/fg42/lisp/
${vazir-fonts} emacs --batch -l package --eval "(package-generate-autoloads \"${pname}\" \"$LISPDIR\")"
${fira-code}
${fira-mono}
${nerdfonts}
${noto-fonts}
${lib.strings.concatLines paths}
EOF
runHook postBuild runHook postBuild
''; '';
installPhase = '' # installPhase = ''
runHook preInstall # runHook preInstall
#LISPDIR=$out/share/fg42/lisp/ # runHook postInstall
#emacs --batch -l package --eval "(package-generate-autoloads \"${pname}\" \"$LISPDIR\")" # '';
runHook postInstall
'';
buildInputs = [ emacs emacsBundle git texinfo gcc bash ]; buildInputs = [ emacs emacsBundle git texinfo gcc bash ];
@ -243,7 +163,7 @@ stdenv.mkDerivation (final: rec {
platforms = emacs.meta.platforms; platforms = emacs.meta.platforms;
homepage = "https://fg42.org/"; homepage = "https://fg42.org/";
maintainers = [ maintainers.lxsameer ]; maintainers = [ maintainers.lxsameer ];
description = "The mighty editor for the emacsians"; description = "The mighty editor for the Emacsians";
longDescription = '' longDescription = ''
FG42 is a framework to create and editor and window manager based on GNU/Emacs. 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 It has a pre-defined setup as well which can be installed out of the box. But the
@ -253,5 +173,4 @@ stdenv.mkDerivation (final: rec {
''; '';
license = lib.licenses.gpl3Plus; license = lib.licenses.gpl3Plus;
}; };
}
})

78
nix/fg42/unit.nix Normal file
View File

@ -0,0 +1,78 @@
# Fg42 - Emacs Editor for advance users
#
# 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/>.
# This is the home manager module that exposes FG42. It differs
# from FG42 modules that are structurally the same but used in
# different context
{ lib, pkgs, ... }:
with lib;
{
options = {
fg42.version = mkOption {
type = types.str;
visible = true;
readOnly = true;
description = "FG42's version.";
};
fg42.emacs = mkOption {
type = types.package;
default = pkgs.emacs29.override ({
withTreeSitter = true;
});
description = "What Emacs package to use.";
};
fg42.elispPackages = mkOption {
type = types.listOf types.package;
default = [ ];
description = ''
A list of Emacs packages that should be included in FG42
'';
};
fg42.paths = mkOption {
type = types.listOf types.package;
default = [ ];
description = ''
A list of packages that should be added to FG42's PATH
'';
};
fg42.mimeTypes = mkOption {
type = types.listOf types.str;
default = [ ];
description = ''
A list of mineType strings that FG42 should handle via
desktop file.
'';
};
fg42.fonts = mkOption {
type = types.listOf types.package;
default = [ ];
description = ''
A list of font packages that should be included in FG42
'';
};
};
config = {
fg42.version = import ../version.nix { };
};
}

19
nix/fg42/utils.nix Normal file
View File

@ -0,0 +1,19 @@
# Fg42 - Emacs Editor for advance users
#
# 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/>.
{ ... }:
{
makeDesktopFile = { };
}

71
nix/hm/default.nix Normal file
View File

@ -0,0 +1,71 @@
# Fg42 - Emacs Editor for advance users
#
# 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/>.
# This is the home manager module that exposes FG42. It differs
# from FG42 modules that are structurally the same but used in
# different context
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.programs.fg42;
defaultModules = pkgs.callPackage ../modules { };
in
{
meta.maintainers = [ (import ../maintainers.nix { }).lxsameer ];
options = {
enable = mkEnableOption "FG42";
extraModules = mkOption {
type = types.listOf types.submodule;
default = cfg.defaultModules ++ cfg.extraModules;
defaultText = literalExpression "[]";
example = literalExpression ''
extraModules = [
./any-fg42-module-youwant.nix
];
'';
};
modules = mkOption {
type = types.listOf types.deferredModule;
default = cfg.defaultModules ++ cfg.extraModules;
defaultText = literalExpression "[]";
example = literalExpression ''
modules = [
./any-fg42-module-youwant.nix
];
'';
};
finalPackage = mkOption {
type = types.package;
visible = false;
readOnly = true;
description = ''
The Emacs package including any overrides and extra packages.
'';
};
config = mkIf cfg.enable {
home.packages = [ cfg.finalPackage ];
programs.fg42.finalPackage = pkgs.callPackage ../fg42 {
modules = cfg.modules ++ cfg.extraModules;
};
};
};
}

37
nix/modules/default.nix Normal file
View File

@ -0,0 +1,37 @@
# Fg42 - Emacs Editor for advance users
#
# 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/>.
# This is the home manager module that exposes FG42. It differs
# from FG42 modules that are structurally the same but used in
# different context
# A list of default FG42 modules to build FG42 with.
{ pkgs, lib }:
let
modules = [
./editor.nix
];
pkgsModule = { config, ... }: {
config = {
_module.args.baseModules = modules;
_module.args.pkgs = lib.mkDefault pkgs;
_module.check = true;
#inherit lib;
};
};
in
modules ++ [ pkgsModule ]

33
nix/modules/editor.nix Normal file
View File

@ -0,0 +1,33 @@
# Fg42 - Emacs Editor for advance users
#
# 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/>.
# This is the home manager module that exposes FG42. It differs
# from FG42 modules that are structurally the same but used in
# different context
# A list of default FG42 modules to build FG42 with.
{ lib, ... }:
{
options = {
fg42.editor = lib.mkOption {
type = lib.types.str;
default = "blah";
description = ''
FG42's version1.
'';
};
};
}

20
nix/version.nix Normal file
View File

@ -0,0 +1,20 @@
# Fg42 - Emacs Editor for advance users
#
# 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/>.
# This is the home manager module that exposes FG42. It differs
# from FG42 modules that are structurally the same but used in
# different context
_: "4.0.0"