FG42/nix/modules/build_config/default.nix

123 lines
3.4 KiB
Nix

# 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, config, pkgs, ... }:
with lib;
let
generateBuildConfig = configs:
let
defineConfig = cs: name:
let
config = builtins.getAttr name cs;
form = if config.const then "defconst" else "defvar";
in
''(${form} ${name} ${config.value} "${config.docs}")'';
configsList = builtins.map (defineConfig configs) (builtins.attrNames configs);
in
pkgs.writeTextFile {
name = "build-config";
text = ''
${builtins.concatStringsSep "\n" configsList}
(provide 'fg42/build-config)
'';
executable = false;
};
buildConfig = generateBuildConfig (config.fg42.buildConfig);
drv = pkgs.emacsPackages.trivialBuild rec {
pname = "fg42-build-config";
version = config.fg42.version;
src = ./.;
buildPhase = ''
runHook preBuild
LISPDIR=$out/share/emacs/site-lisp/fg42
install -d $LISPDIR
cp -v ${buildConfig} $LISPDIR/build-config.el
emacs -L . --batch -f batch-byte-compile *.el
runHook postBuild
'';
installPhase = ''
runHook preInstall
LISPDIR=$out/share/emacs/site-lisp/fg42/
emacs --batch -l package --eval "(package-generate-autoloads \"${pname}\" \"$LISPDIR\")"
runHook postInstall
'';
};
in
{
options = {
fg42.buildConfig = mkOption {
type = types.attrsOf
(types.submodule {
options = {
value = mkOption {
type = types.str;
default = "nil";
description = ''
The value should be quoted. For example the string "nil"
means the actual nil in elisp and the string "\"foo\""
means elisp string "foo".
'';
};
docs = mkOption {
type = types.str;
description = "The docstring for the variable or constant (mandatory)";
};
const = mkOption {
type = types.bool;
default = false;
description = "defvar vs defconst";
};
};
});
default = { };
example = ''
fg42.config = {
"fg42/some-var" = {
value = "foo";
docs = "The docstring";
const = false;
};
};
'';
description = ''
An attrset of configuration variables and their values
that should end up in `fg42/config` elisp module.
'';
};
};
config = {
fg42.elispPackages = [ drv ];
};
}