Added usage of lib.optionals and created an assersion to check the number of enabled builders

This commit is contained in:
isaacST08 2025-02-11 19:37:14 -07:00
commit d638292e77
3 changed files with 29 additions and 71 deletions

View file

@ -10,6 +10,7 @@
# The builder template # The builder template
template = import ./builderTemplate.nix; template = import ./builderTemplate.nix;
inherit (lib) optionals;
inherit (lib.options) mkOption mkEnableOption; inherit (lib.options) mkOption mkEnableOption;
inherit (lib.types) bool package str; inherit (lib.types) bool package str;
in ( in (
@ -42,11 +43,7 @@ in (
args = builderCfg: ( args = builderCfg: (
# Flags # Flags
( (optionals builderCfg.pdfOutput ["-pdf"])
if builderCfg.pdfOutput
then ["-pdf"]
else []
)
# Base args # Base args
++ [ ++ [
"-quiet" "-quiet"

View file

@ -10,6 +10,7 @@
# The builder template # The builder template
template = import ./builderTemplate.nix; template = import ./builderTemplate.nix;
inherit (lib) optionals;
inherit (lib.options) mkOption mkEnableOption; inherit (lib.options) mkOption mkEnableOption;
inherit (lib.types) enum ints listOf package str; inherit (lib.types) enum ints listOf package str;
inherit (lib.nvim.config) mkBool; inherit (lib.nvim.config) mkBool;
@ -133,71 +134,23 @@ in (
"%f" "%f"
] ]
# Flags # Flags
++ ( ++ (optionals builderCfg.keepIntermediates ["--keep-intermediates"])
if builderCfg.keepIntermediates ++ (optionals builderCfg.keepLogs ["--keep-logs"])
then ["--keep-intermediates"] ++ (optionals builderCfg.onlyCached ["--only-cached"])
else [] ++ (optionals builderCfg.synctex ["--synctex"])
) ++ (optionals builderCfg.untrustedInput ["--untrusted"])
++ (
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 []
)
# Options # Options
++ ( ++ (optionals (builderCfg.reruns > 0) ["--reruns" "${toString builderCfg.reruns}"])
if builderCfg.reruns > 0 ++ (optionals (builderCfg.bundle != "") ["--bundle" "${toString builderCfg.bundle}"])
then ["--reruns" "${toString builderCfg.reruns}"] ++ (optionals (builderCfg.webBundle != "") ["--web-bundle" "${toString builderCfg.webBundle}"])
else [] ++ (optionals (builderCfg.outfmt != "") ["--outfmt" "${toString builderCfg.outfmt}"])
)
++ (
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)) ++ (concatLists (map (x: ["--hide" x]) builderCfg.hidePaths))
++ ( ++ (optionals (builderCfg.format != "") ["--format" "${toString builderCfg.format}"])
if builderCfg.format != "" ++ (optionals (builderCfg.color != "") ["--color" "${toString builderCfg.color}"])
then ["--format" "${toString builderCfg.format}"]
else []
)
++ (
if builderCfg.color != ""
then ["--color" "${toString builderCfg.color}"]
else []
)
# Still options but these are not defined by builder specific options but # Still options but these are not defined by builder specific options but
# instead synchronize options between the global build options and builder # instead synchronize options between the global build options and builder
# specific options # specific options
++ ( ++ (optionals (!(elem cfg.build.pdfDirectory ["." ""])) ["--outdir" "${cfg.build.pdfDirectory}"])
if !(elem cfg.build.pdfDirectory ["." ""])
then ["--outdir" "${cfg.build.pdfDirectory}"]
else []
)
); );
} }
) )

View file

@ -4,6 +4,7 @@
... ...
}: let }: let
inherit (lib.options) mkOption; inherit (lib.options) mkOption;
inherit (lib.modules) mkIf;
inherit (lib.types) str nullOr; inherit (lib.types) str nullOr;
inherit (builtins) filter isAttrs hasAttr attrNames length elemAt; inherit (builtins) filter isAttrs hasAttr attrNames length elemAt;
inherit (lib.nvim.config) mkBool; inherit (lib.nvim.config) mkBool;
@ -48,11 +49,7 @@ in {
options.vim.languages.tex.build = { options.vim.languages.tex.build = {
enable = enable =
mkBool ( mkBool (enabledBuildersCount == 1) ''
if enabledBuildersCount > 1
then throw "nvf-tex-language does not support having more than 1 builders enabled!"
else (enabledBuildersCount == 1)
) ''
Whether to enable configuring the builder. Whether to enable configuring the builder.
By enabling any of the builders, this option will be automatically set. By enabling any of the builders, this option will be automatically set.
@ -106,8 +103,19 @@ in {
type = nullOr str; type = nullOr str;
default = null; default = null;
description = '' description = ''
Allows overriding the default file name of the build artifact. This setting is used to find the correct PDF file to open during forward search. Allows overriding the default file name of the build artifact.
This setting is used to find the correct PDF file to open during forward search.
''; '';
}; };
}; };
config = mkIf (enabledBuildersCount > 0) {
assertions = [
{
assertion = (enabledBuildersCount < 2);
message = "The nvf-tex-language implementation does not support having more than 1 builders enabled.";
}
];
};
} }