Removed builderTemplate implementation in favour of an inline approach

This commit is contained in:
isaacST08 2025-12-19 14:30:30 -07:00
parent 4d80eeb006
commit 0da99e05ae
6 changed files with 400 additions and 625 deletions

View file

@ -1,66 +0,0 @@
# This function acts as a template for creating new builders.
# It enforces providing all the parameters required for creating
# a new builder for it to be able to work in the existing code.
#
# The first layer requirements are as follows:
{
# This is the name of the builder, it will only be used internally and
# should match the <name>.nix file that the builder is implemented in.
name,
#
# Module attribute set. This is the attribute set that the module that is
# defining a builder is passed as its input.
moduleInheritancePackage,
#
# These are the standard options for the builder just like creating any
# other module. Some options are required and are described below but
# it will also accept any other options that are provided to it.
options,
#
# These are the command line arguments that will accompany the executable
# when the build command is called.
# This is a function that will take in the cfg of its own builder.
# i.e. will be called as "args cfg.build.builders.${name}"
args,
...
}: let
# Inherit the necessary variables available to any module.
inherit (moduleInheritancePackage) lib config;
#
# Inherit other useful functions.
inherit (lib.modules) mkIf;
#
# Set the cfg variable
cfg = config.vim.languages.tex;
in {
# These are the options for the builder. It will accept any options
# provided to it but some options are mandatory:
options.vim.languages.tex.build.builders.${name} = ({
# The enable option. This one is self explanatory.
enable,
#
# This is the package option for the builder.
package,
#
# This is the executable that will be used to call the builder.
# It, along with package will result in:
# "<package_path>/bin/<executable>"
executable,
#
# Any other options provided are accepted.
...
} @ opts:
opts)
options;
# Check that the language and this builder have been enabled
# before making any config.
config = mkIf (cfg.enable && cfg.build.builders.${name}.enable) {
vim.languages.tex.build.builder = {
inherit name;
package = cfg.build.builders.${name}.package;
executable = cfg.build.builders.${name}.executable;
args = args cfg.build.builders.${name};
};
};
}

View file

@ -1,22 +1,22 @@
# TODO: I need testing.
{
pkgs,
config,
lib,
pkgs,
...
} @ moduleInheritancePackage: let
}: let
# The name of the builder
name = "latexmk";
# The builder template
template = import ./builderTemplate.nix;
inherit (lib.modules) mkIf;
inherit (lib.nvim.config) mkBool;
inherit (lib.options) mkOption mkEnableOption;
inherit (lib.types) bool package str;
in (
template {
inherit name moduleInheritancePackage;
inherit (lib.types) package str;
options = {
texCfg = config.vim.languages.tex;
cfg = texCfg.build.builders.${name};
in {
options.vim.languages.tex.build.builders.${name} = {
enable = mkEnableOption "Whether to enable Tex Compilation Via latexmk";
package = mkOption {
@ -32,26 +32,22 @@ in (
};
# Flag options
pdfOutput = mkOption {
type = bool;
default = true;
example = false;
description = "Insure the output file is a pdf.";
};
pdfOutput = mkBool true "Insure the output file is a pdf.";
};
args = builderCfg: (
config = mkIf (texCfg.enable && cfg.enable) {
vim.languages.tex.build.builder = {
inherit name;
inherit (cfg) package executable;
args = (
# Flags
(
if builderCfg.pdfOutput
then ["-pdf"]
else []
)
(lib.lists.optional cfg.pdfOutput "-pdf")
# Base args
++ [
"-quiet"
"%f"
]
);
};
};
}
)

View file

@ -1,26 +1,23 @@
{
config,
pkgs,
lib,
pkgs,
...
} @ moduleInheritancePackage: let
}: let
# The name of the builder
name = "tectonic";
# The builder template
template = import ./builderTemplate.nix;
inherit (lib.options) mkOption mkEnableOption;
inherit (lib.types) enum ints listOf package str;
inherit (builtins) concatLists elem map toString match;
inherit (lib.modules) mkIf;
inherit (lib.nvim.config) mkBool;
inherit (builtins) concatLists elem map toString;
inherit (lib.options) mkOption mkEnableOption;
inherit (lib.strings) toLower optionalString stringAsChars;
inherit (lib.types) enum ints listOf package str;
cfg = config.vim.languages.tex;
in (
template {
inherit name moduleInheritancePackage;
options = {
texCfg = config.vim.languages.tex;
cfg = texCfg.build.builders.${name};
in {
options.vim.languages.tex.build.builders.${name} = {
enable = mkEnableOption "Whether to enable Tex Compilation Via Tectonic";
package = mkOption {
@ -125,7 +122,15 @@ in (
};
};
args = builderCfg: (
config = mkIf (texCfg.enable && cfg.enable) {
vim.languages.tex.build.builder = {
inherit name;
inherit (cfg) package executable;
args = let
inherit (lib.lists) optional optionals;
snakeCaseToKebabCase = str: stringAsChars (x: "${optionalString ((match "[A-Z]" x) != null) "-"}${toLower x}") str;
generateOptionFlag = option: (optionals (cfg.${option} != "") ["--${snakeCaseToKebabCase option}" "${toString cfg.${option}}"]);
in (
# Base args
[
"-X"
@ -133,71 +138,24 @@ in (
"%f"
]
# Flags
++ (
if builderCfg.keepIntermediates
then ["--keep-intermediates"]
else []
)
++ (
if builderCfg.keepLogs
then ["--keep-logs"]
else []
)
++ (
if builderCfg.onlyCached
then ["--only-cached"]
else []
)
++ (
if builderCfg.synctex
then ["--synctex"]
else []
)
++ (
if builderCfg.untrustedInput
then ["--untrusted"]
else []
)
++ (optional cfg.keepIntermediates "--keep-intermediates")
++ (optional cfg.keepLogs "--keep-logs")
++ (optional cfg.onlyCached "--only-cached")
++ (optional cfg.synctex "--synctex")
++ (optional cfg.untrustedInput "--untrusted")
# Options
++ (
if builderCfg.reruns > 0
then ["--reruns" "${toString builderCfg.reruns}"]
else []
)
++ (
if builderCfg.bundle != ""
then ["--bundle" "${toString builderCfg.bundle}"]
else []
)
++ (
if builderCfg.webBundle != ""
then ["--web-bundle" "${toString builderCfg.webBundle}"]
else []
)
++ (
if builderCfg.outfmt != ""
then ["--outfmt" "${toString builderCfg.outfmt}"]
else []
)
++ (concatLists (map (x: ["--hide" x]) builderCfg.hidePaths))
++ (
if builderCfg.format != ""
then ["--format" "${toString builderCfg.format}"]
else []
)
++ (
if builderCfg.color != ""
then ["--color" "${toString builderCfg.color}"]
else []
)
++ (optionals (cfg.reruns > 0) ["--reruns" "${toString cfg.reruns}"])
++ (generateOptionFlag "bundle")
++ (generateOptionFlag "webBundle")
++ (generateOptionFlag "outfmt")
++ (concatLists (map (x: ["--hide" x]) cfg.hidePaths))
++ (generateOptionFlag "format")
++ (generateOptionFlag "color")
# Still options but these are not defined by builder specific options but
# instead synchronize options between the global build options and builder
# specific options
++ (
if !(elem cfg.build.pdfDirectory ["." ""])
then ["--outdir" "${cfg.build.pdfDirectory}"]
else []
)
# specific options.
++ (optionals (!(elem texCfg.build.pdfDirectory ["." ""])) ["--outdir" "${texCfg.build.pdfDirectory}"])
);
};
};
}
)

View file

@ -1,66 +0,0 @@
# This function acts as a template for creating new builders.
# It enforces providing all the parameters required for creating
# a new builder for it to be able to work in the existing code.
#
# The first layer requirements are as follows:
{
# This is the name of the builder, it will only be used internally and
# should match the <name>.nix file that the builder is implemented in.
name,
#
# Module attribute set. This is the attribute set that the module that is
# defining a builder is passed as its input.
moduleInheritancePackage,
#
# These are the standard options for the builder just like creating any
# other module. Some options are required and are described below but
# it will also accept any other options that are provided to it.
options,
#
# These are the command line arguments that will accompany the executable
# when the build command is called.
# This is a function that will take in the cfg of its own builder.
# i.e. will be called as "args cfg.build.builders.${name}"
args,
...
}: let
# Inherit the necessary variables available to any module.
inherit (moduleInheritancePackage) lib config;
#
# Inherit other useful functions.
inherit (lib.modules) mkIf;
#
# Set the cfg variable
cfg = config.vim.languages.tex;
in {
# These are the options for the builder. It will accept any options
# provided to it but some options are mandatory:
options.vim.languages.tex.build.builders.${name} = ({
# The enable option. This one is self explanatory.
enable,
#
# This is the package option for the builder.
package,
#
# This is the executable that will be used to call the builder.
# It, along with package will result in:
# "<package_path>/bin/<executable>"
executable,
#
# Any other options provided are accepted.
...
} @ opts:
opts)
options;
# Check that the language and this builder have been enabled
# before making any config.
config = mkIf (cfg.enable && cfg.build.builders.${name}.enable) {
vim.languages.tex.build.builder = {
inherit name;
package = cfg.build.builders.${name}.package;
executable = cfg.build.builders.${name}.executable;
args = args cfg.build.builders.${name};
};
};
}

View file

@ -1,23 +1,22 @@
# TODO: I need testing.
{
pkgs,
config,
lib,
pkgs,
...
} @ moduleInheritancePackage: let
}: let
# The name of the builder
name = "latexmk";
# The builder template
template = import ./builderTemplate.nix;
inherit (lib) optionals;
inherit (lib.modules) mkIf;
inherit (lib.nvim.config) mkBool;
inherit (lib.options) mkOption mkEnableOption;
inherit (lib.types) bool package str;
in (
template {
inherit name moduleInheritancePackage;
inherit (lib.types) package str;
options = {
texCfg = config.vim.languages.tex;
cfg = texCfg.build.builders.${name};
in {
options.vim.languages.tex.build.builders.${name} = {
enable = mkEnableOption "Tex Compilation Via latexmk";
package = mkOption {
@ -36,24 +35,23 @@ in (
};
# Flag options
pdfOutput = mkOption {
type = bool;
default = true;
example = false;
description = "Insure the output file is a pdf.";
};
pdfOutput = mkBool true "Insure the output file is a pdf.";
};
# Optional flags must come before the base args because of how the latexmk
# command works
args = builderCfg: (
config = mkIf (texCfg.enable && cfg.enable) {
vim.languages.tex.build.builder = {
inherit name;
inherit (cfg) package executable;
args = (
# Flags
(optionals builderCfg.pdfOutput ["-pdf"])
(lib.lists.optional cfg.pdfOutput "-pdf")
# Base args
++ [
"-quiet"
"%f"
]
);
};
};
}
)

View file

@ -1,34 +1,23 @@
{
config,
pkgs,
lib,
pkgs,
...
} @ moduleInheritancePackage: let
}: let
# The name of the builder
name = "tectonic";
# The builder template
template = import ./builderTemplate.nix;
inherit (lib) optionals;
inherit (lib.options) mkOption mkEnableOption mkPackageOption;
inherit (lib.types) enum ints listOf str nullOr;
inherit (builtins) concatLists elem map toString match;
inherit (lib.modules) mkIf;
inherit (lib.nvim.config) mkBool;
inherit (builtins) concatLists elem map toString attrNames filter isList;
inherit (lib.options) mkOption mkEnableOption mkPackageOption;
inherit (lib.strings) toLower optionalString stringAsChars;
inherit (lib.types) enum ints listOf str nullOr;
notNull = x: x != null;
forceCheck = x: true;
toList = x:
if isList x
then x
else [x];
cfg = config.vim.languages.tex;
in (
template {
inherit name moduleInheritancePackage;
options = {
texCfg = config.vim.languages.tex;
cfg = texCfg.build.builders.${name};
in {
options.vim.languages.tex.build.builders.${name} = {
enable = mkEnableOption "Tex Compilation Via Tectonic";
package = mkPackageOption pkgs "tectonic" {};
@ -155,75 +144,41 @@ in (
};
};
# args = builderCfg: (
# # Base args
# [
# "-X"
# "compile"
# "%f"
# ]
# # Flags
# ++ (optionals builderCfg.keepIntermediates ["--keep-intermediates"])
# ++ (optionals builderCfg.keepLogs ["--keep-logs"])
# ++ (optionals builderCfg.onlyCached ["--only-cached"])
# ++ (optionals builderCfg.synctex ["--synctex"])
# ++ (optionals builderCfg.untrustedInput ["--untrusted"])
# # Options
# ++ (optionals (builderCfg.reruns > 0) ["--reruns" "${toString builderCfg.reruns}"])
# ++ (optionals (builderCfg.bundle != null) ["--bundle" "${toString builderCfg.bundle}"])
# ++ (optionals (builderCfg.webBundle != null) ["--web-bundle" "${toString builderCfg.webBundle}"])
# ++ (optionals (builderCfg.outfmt != null) ["--outfmt" "${toString builderCfg.outfmt}"])
# ++ (concatLists (map (x: ["--hide" x]) builderCfg.hidePaths))
# ++ (optionals (builderCfg.format != null) ["--format" "${toString builderCfg.format}"])
# ++ (optionals (builderCfg.color != null) ["--color" "${toString builderCfg.color}"])
# # Still options but these are not defined by builder specific options but
# # instead synchronize options between the global build options and builder
# # specific options
# ++ (optionals (!(elem cfg.build.pdfDirectory ["." ""])) ["--outdir" "${cfg.build.pdfDirectory}"])
# );
config = mkIf (texCfg.enable && cfg.enable) {
vim.languages.tex.build.builder = {
inherit name;
inherit (cfg) package executable;
args = builderCfg: let
option = setCheck: flag: {inherit setCheck flag;};
args = {
baseArgs = ["-X" "compile" "%f"];
flags = {
keepIntermediates = "--keep-intermediates";
keepLogs = "--keep-logs";
onlyCached = "--only-cached";
synctex = "--synctex";
untrustedInput = "--untrusted";
};
options = {
reruns = option (x: x > 0) "--reruns";
bundle = option notNull "--bundle";
webBundle = option notNull "--web-bundle";
outfmt = option notNull "--outfmt";
format = option notNull "--format";
color = option notNull "--color";
hidePaths = option forceCheck "--hide";
};
externalOptions = concatLists [
(optionals (!(elem cfg.build.pdfDirectory ["." ""])) ["--outdir" "${cfg.build.pdfDirectory}"])
];
};
flags = map (flag: args.flags.${flag}) (filter (flag: builderCfg.${flag}) (attrNames args.flags));
options = let
getOptionFlagsList = opt:
concatLists (
map
(y: [args.options."${opt}".flag "${toString y}"])
(toList builderCfg."${opt}")
args = let
inherit (lib.lists) optional optionals;
snakeCaseToKebabCase = str: stringAsChars (x: "${optionalString ((match "[A-Z]" x) != null) "-"}${toLower x}") str;
generateOptionFlag = option: (optionals (cfg.${option} != "" && cfg.${option} != null) ["--${snakeCaseToKebabCase option}" "${toString cfg.${option}}"]);
in (
# Base args
[
"-X"
"compile"
"%f"
]
# Flags
++ (optional cfg.keepIntermediates "--keep-intermediates")
++ (optional cfg.keepLogs "--keep-logs")
++ (optional cfg.onlyCached "--only-cached")
++ (optional cfg.synctex "--synctex")
++ (optional cfg.untrustedInput "--untrusted")
# Options
++ (optionals (cfg.reruns > 0) ["--reruns" "${toString cfg.reruns}"])
++ (generateOptionFlag "bundle")
++ (generateOptionFlag "webBundle")
++ (generateOptionFlag "outfmt")
++ (concatLists (map (x: ["--hide" x]) cfg.hidePaths))
++ (generateOptionFlag "format")
++ (generateOptionFlag "color")
# Still options but these are not defined by builder specific options but
# instead synchronize options between the global build options and builder
# specific options.
++ (optionals (!(elem texCfg.build.pdfDirectory ["." ""])) ["--outdir" "${texCfg.build.pdfDirectory}"])
);
processOption = opt:
optionals
(args.options."${opt}".setCheck builderCfg."${opt}")
(getOptionFlagsList opt);
in (concatLists (map processOption (attrNames args.options)));
in
concatLists (with args; [baseArgs flags options externalOptions]);
};
};
}
)