diff --git a/modules/misc/news.nix b/modules/misc/news.nix index 06a0b0880..cdff6d820 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -2148,6 +2148,15 @@ in { under '$XDG_CONFIG_HOME/easyeffects/{input,output}/'. ''; } + { + time = "2025-02-12T15:56:00+00:00"; + message = '' + A new module is available: 'programs.tex-fmt'. + + tex-fmt is a LaTeX formatter written in Rust. + See https://github.com/WGUNDERWOOD/tex-fmt for more information. + ''; + } ]; }; } diff --git a/modules/modules.nix b/modules/modules.nix index 961188a26..de9447ce6 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -246,6 +246,7 @@ let ./programs/tealdeer.nix ./programs/terminator.nix ./programs/termite.nix + ./programs/tex-fmt.nix ./programs/texlive.nix ./programs/thefuck.nix ./programs/thunderbird.nix diff --git a/modules/programs/tex-fmt.nix b/modules/programs/tex-fmt.nix new file mode 100644 index 000000000..87dc8aa0e --- /dev/null +++ b/modules/programs/tex-fmt.nix @@ -0,0 +1,53 @@ +{ pkgs, config, lib, ... }: + +let + + inherit (lib) mkEnableOption mkPackageOption mkOption literalExpression; + + configDir = if pkgs.stdenv.isDarwin then + "Library/Application Support" + else + config.xdg.configHome; + + tomlFormat = pkgs.formats.toml { }; + cfg = config.programs.tex-fmt; + +in { + meta.maintainers = with lib.maintainers; [ mirkolenz wgunderwood ]; + + options.programs.tex-fmt = { + enable = mkEnableOption "tex-fmt"; + + package = mkPackageOption pkgs "tex-fmt" { }; + + settings = mkOption { + type = tomlFormat.type; + default = { }; + example = literalExpression '' + { + wrap = true; + tabsize = 2; + tabchar = "space"; + lists = []; + } + ''; + description = '' + Configuration written to + {file}`$XDG_CONFIG_HOME/tex-fmt/tex-fmt.toml` on Linux or + {file}`$HOME/Library/Application Support/tex-fmt/tex-fmt.toml` on Darwin. + See and + + for more information. + ''; + }; + }; + + config = lib.mkIf cfg.enable { + home.packages = [ cfg.package ]; + + home.file."${configDir}/tex-fmt/tex-fmt.toml" = + lib.mkIf (cfg.settings != { }) { + source = tomlFormat.generate "tex-fmt-config" cfg.settings; + }; + }; +} diff --git a/tests/default.nix b/tests/default.nix index 8d35a8aa4..fedd70a5e 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -384,6 +384,7 @@ in import nmtSrc { ./modules/programs/starship ./modules/programs/taskwarrior ./modules/programs/tealdeer + ./modules/programs/tex-fmt ./modules/programs/texlive ./modules/programs/thefuck ./modules/programs/thunderbird diff --git a/tests/modules/programs/tex-fmt/custom-settings.nix b/tests/modules/programs/tex-fmt/custom-settings.nix new file mode 100644 index 000000000..a4123b095 --- /dev/null +++ b/tests/modules/programs/tex-fmt/custom-settings.nix @@ -0,0 +1,31 @@ +{ config, pkgs, ... }: { + config = { + programs.tex-fmt = { + enable = true; + settings = { + wrap = true; + tabsize = 2; + tabchar = "space"; + lists = [ ]; + }; + }; + + nmt.script = let + expectedConfDir = if pkgs.stdenv.isDarwin then + "Library/Application Support" + else + ".config"; + expectedConfigPath = "home-files/${expectedConfDir}/tex-fmt/tex-fmt.toml"; + in '' + assertFileExists "${expectedConfigPath}" + assertFileContent "${expectedConfigPath}" ${ + pkgs.writeText "tex-fmt.config-custom.expected" '' + lists = [] + tabchar = "space" + tabsize = 2 + wrap = true + '' + } + ''; + }; +} diff --git a/tests/modules/programs/tex-fmt/default-settings.nix b/tests/modules/programs/tex-fmt/default-settings.nix new file mode 100644 index 000000000..427493946 --- /dev/null +++ b/tests/modules/programs/tex-fmt/default-settings.nix @@ -0,0 +1,15 @@ +{ config, pkgs, ... }: { + config = { + programs.tex-fmt = { enable = true; }; + + nmt.script = let + expectedConfDir = if pkgs.stdenv.isDarwin then + "Library/Application Support" + else + ".config"; + expectedConfigPath = "home-files/${expectedConfDir}/tex-fmt/tex-fmt.toml"; + in '' + assertPathNotExists "${expectedConfigPath}" + ''; + }; +} diff --git a/tests/modules/programs/tex-fmt/default.nix b/tests/modules/programs/tex-fmt/default.nix new file mode 100644 index 000000000..e75a8b354 --- /dev/null +++ b/tests/modules/programs/tex-fmt/default.nix @@ -0,0 +1,4 @@ +{ + tex-fmt-default-settings = ./default-settings.nix; + tex-fmt-custom-settings = ./custom-settings.nix; +}