diff --git a/flake.nix b/flake.nix index 35ae0d1..8132b45 100644 --- a/flake.nix +++ b/flake.nix @@ -29,6 +29,16 @@ "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, ... }: let test-x = pkgs.writeShellApplication { @@ -39,30 +49,38 @@ ${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); - default = (factory { }); + + #noether = inputs.noether.outputs.packages.${system}.default; + 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 { packages = { - default = 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; - }); + default = fg42; + }; devShells.default = pkgs.mkShell { - nativeBuildInputs = [ default.fg42 pkgs.fish test-x default.run-test-wm ]; - buildInputs = [ default.fg42 ]; + nativeBuildInputs = [ fg42 pkgs.fish test-x run-test-wm ]; + buildInputs = [ fg42 ]; }; apps.wm = { type = "app"; - program = "${default.run-test-wm}/bin/run-test-wm"; + program = "${run-test-wm}/bin/run-test-wm"; }; apps.x = { @@ -71,7 +89,7 @@ }; apps.default = { type = "app"; - program = "${default.fg42}/bin/fg42"; + program = "${fg42}/bin/fg42"; }; }; diff --git a/nix/factory.nix b/nix/fg42/default.nix similarity index 50% rename from nix/factory.nix rename to nix/fg42/default.nix index d72e13f..8f5bf10 100644 --- a/nix/factory.nix +++ b/nix/fg42/default.nix @@ -13,44 +13,31 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . -{ lib -, stdenv -, emacs29 -, callPackage -, writeShellApplication -, noether -, emacsParams ? { } -, fg42Params ? { } -}: + +# This is the home manager module that exposes FG42. It differs +# from FG42 modules that are structurally the same but used in +# different context +{ pkgs, lib ? pkgs.lib, modules ? null, extraModules ? [ ] }: +with lib; + let - lemacs = emacs29.override ({ - withTreeSitter = true; - } // emacsParams); + fg42Modules = + if modules != null + then modules + else + import ../modules { + inherit pkgs; + lib = lib; + }; - elispDepsFile = ../lisp/fg42/deps.el; - - elispPkgs = callPackage ./deps.nix { - inherit elispDepsFile; + unitModule = import ./unit.nix { inherit pkgs lib; }; + final = lib.evalModules { + modules = [ unitModule ] ++ fg42Modules ++ extraModules; }; - 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 -{ inherit fg42 run-test-wm; } +pkgs.callPackage ./derivation.nix { + inherit (final) config options; + maintainers = import ../maintainers.nix; + utils = pkgs.callPackage ./utils.nix { }; +} diff --git a/nix/fg42.nix b/nix/fg42/derivation.nix similarity index 62% rename from nix/fg42.nix rename to nix/fg42/derivation.nix index 97c126d..2a785ff 100644 --- a/nix/fg42.nix +++ b/nix/fg42/derivation.nix @@ -14,128 +14,57 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . { lib +, config , 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 , texinfo -, vazir-fonts -, fira-code -, nerdfonts -, fira-mono -, noto-fonts , gcc -, ltex-ls , bash -, tree-sitter -, fd -, aspellWithDicts -, supportWM ? true +, utils +, emacsPackagesFor +, makeFontsConf , xorg -, slock -, supportPython ? true -, supportVerilog ? true -, svls -, verilator -, +, maintainers +, ... }: with builtins; let - version = "4.0.0"; - getPkg = epkgs: pkg: - if hasAttr pkg epkgs then getAttr pkg epkgs else getAttr pkg ourPackages; + cfg = config.fg42; + emacs = cfg.emacs; + version = cfg.version; - emacsBundle = (emacsPackagesFor emacs).withPackages (epkgs: - (map (x: getPkg epkgs x) elispPkgs) - ++ [ epkgs.treesit-grammars.with-all-grammars ]); + emacsBundle = (emacsPackagesFor emacs).withPackages (_: cfg.elispPackages); - maintainers = import ./maintainers.nix; - - 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); + paths = map (x: "${x}/bin/") cfg.paths; pathsStr = lib.strings.concatStrings (lib.strings.intersperse ":" paths); - mimes = import ./mimes.nix; - fontsConf = makeFontsConf { - fontDirectories = [ - vazir-fonts - fira-code - nerdfonts - fira-mono - noto-fonts - ]; - }; + mimeTypes = builtins.concatStringsSep ";" cfg.mimeTypes; + + fontsConf = makeFontsConf { fontDirectories = cfg.fonts; }; + in -stdenv.mkDerivation (final: rec { +stdenv.mkDerivation rec { inherit version; - pname = "fg42"; - src = srcDir; - outputs = [ "out" ]; + pname = "FG42"; + + src = ../../.; buildPhase = '' LISPDIR=$out/share/fg42/ mkdir -p $out/bin mkdir -p $out/share/applications/ + install -d $LISPDIR cp -rv ${src}/lisp/ $LISPDIR + cp -rv ${src}/share $out/ cp -rv ${src}/snippets $LISPDIR/snippets cp "${fontsConf}" $LISPDIR/fonts.conf + + chmod 755 $LISPDIR -R + export FONTCONFIG_FILE="$LISPDIR/fonts.conf" cat >> $out/share/applications/FG42.desktop << EOF @@ -144,7 +73,7 @@ stdenv.mkDerivation (final: rec { Name=FG42 GenericName=FG42 Comment=The nix base Emacs bundle for advance users - MimeType=${mimes.mimeTypes} + MimeType=${mimeTypes} Type=Application Terminal=false Categories=Development;TextEditor; @@ -213,26 +142,17 @@ stdenv.mkDerivation (final: rec { EOF chmod +x $out/bin/fg42-wm - cat >> $out/share/runtiem_deps << EOF - ${vazir-fonts} - ${fira-code} - ${fira-mono} - ${nerdfonts} - ${noto-fonts} - ${lib.strings.concatLines paths} - EOF + LISPDIR=$out/share/fg42/lisp/ + emacs --batch -l package --eval "(package-generate-autoloads \"${pname}\" \"$LISPDIR\")" runHook postBuild ''; - installPhase = '' - runHook preInstall + # installPhase = '' + # runHook preInstall - #LISPDIR=$out/share/fg42/lisp/ - #emacs --batch -l package --eval "(package-generate-autoloads \"${pname}\" \"$LISPDIR\")" - - runHook postInstall - ''; + # runHook postInstall + # ''; buildInputs = [ emacs emacsBundle git texinfo gcc bash ]; @@ -243,7 +163,7 @@ stdenv.mkDerivation (final: rec { platforms = emacs.meta.platforms; homepage = "https://fg42.org/"; maintainers = [ maintainers.lxsameer ]; - description = "The mighty editor for the emacsians"; + 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 @@ -253,5 +173,4 @@ stdenv.mkDerivation (final: rec { ''; license = lib.licenses.gpl3Plus; }; - -}) +} diff --git a/nix/fg42/unit.nix b/nix/fg42/unit.nix new file mode 100644 index 0000000..c6168d0 --- /dev/null +++ b/nix/fg42/unit.nix @@ -0,0 +1,78 @@ +# Fg42 - Emacs Editor for advance users +# +# Copyright (c) 2010-2024 Sameer Rahmani +# +# 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 . + +# 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 { }; + }; +} diff --git a/nix/fg42/utils.nix b/nix/fg42/utils.nix new file mode 100644 index 0000000..55d7a27 --- /dev/null +++ b/nix/fg42/utils.nix @@ -0,0 +1,19 @@ +# Fg42 - Emacs Editor for advance users +# +# Copyright (c) 2010-2024 Sameer Rahmani +# +# 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 . +{ ... }: +{ + makeDesktopFile = { }; +} diff --git a/nix/hm/default.nix b/nix/hm/default.nix new file mode 100644 index 0000000..cf68646 --- /dev/null +++ b/nix/hm/default.nix @@ -0,0 +1,71 @@ +# Fg42 - Emacs Editor for advance users +# +# Copyright (c) 2010-2024 Sameer Rahmani +# +# 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 . + +# 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; + }; + }; + }; +} diff --git a/nix/modules/default.nix b/nix/modules/default.nix new file mode 100644 index 0000000..9fd4e4e --- /dev/null +++ b/nix/modules/default.nix @@ -0,0 +1,37 @@ +# Fg42 - Emacs Editor for advance users +# +# Copyright (c) 2010-2024 Sameer Rahmani +# +# 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 . + +# 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 ] diff --git a/nix/modules/editor.nix b/nix/modules/editor.nix new file mode 100644 index 0000000..a03a636 --- /dev/null +++ b/nix/modules/editor.nix @@ -0,0 +1,33 @@ +# Fg42 - Emacs Editor for advance users +# +# Copyright (c) 2010-2024 Sameer Rahmani +# +# 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 . + +# 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. + ''; + }; + }; +} diff --git a/nix/version.nix b/nix/version.nix new file mode 100644 index 0000000..cfdca15 --- /dev/null +++ b/nix/version.nix @@ -0,0 +1,20 @@ +# Fg42 - Emacs Editor for advance users +# +# Copyright (c) 2010-2024 Sameer Rahmani +# +# 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 . + +# 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"