summaryrefslogtreecommitdiff
path: root/modules/latex.nix
diff options
context:
space:
mode:
authorQuentin Aristote <quentin@aristote.fr>2021-12-03 11:48:19 +0100
committerQuentin Aristote <quentin@aristote.fr>2021-12-03 11:48:19 +0100
commit6bb027dbeb3dedb6c65cb27274465105bccdfb18 (patch)
tree7613a6397d866617c5c71cb3c906d86f03baba75 /modules/latex.nix
initial commit
Diffstat (limited to 'modules/latex.nix')
-rw-r--r--modules/latex.nix95
1 files changed, 95 insertions, 0 deletions
diff --git a/modules/latex.nix b/modules/latex.nix
new file mode 100644
index 0000000..0c06ec7
--- /dev/null
+++ b/modules/latex.nix
@@ -0,0 +1,95 @@
+{ config, lib, pkgs, ... }:
+
+with lib;
+let
+ cfg = config.latex;
+ latexmkFlags = concatStringsSep " " ([
+ (if cfg.latexmk.output.dvi.enable then "-dvi" else "-dvi-")
+ (if cfg.latexmk.output.ps.enable then "-ps" else "-ps-")
+ (if cfg.latexmk.output.pdf.enable then
+ ("-pdf" + cfg.latexmk.output.pdf.method)
+ else
+ "-pdf-")
+ (optionalString cfg.minted.enable "-shell-escape")
+ ] ++ (map (filename: ''-r "${filename}"'') cfg.latexmk.rc)
+ ++ cfg.latexmk.extraFlags);
+ latexBuildInput = cfg.texlive.combine ((cfg.packages cfg.texlive)
+ // (optionalAttrs cfg.latexmk.enable { inherit (cfg.texlive) latexmk; })
+ // (optionalAttrs cfg.minted.enable { inherit (cfg.texlive) minted; }));
+in {
+ options.latex = {
+ enable = mkEnableOption { name = "LaTex"; };
+
+ texlive = mkOption {
+ type = types.attrs;
+ default = pkgs.texlive;
+ defaultText = literalExample "pkgs.texlive";
+ description = ''
+ The package providing LaTex.
+ Use this option to set the version of LaTex.
+ '';
+ };
+
+ packages = mkOption {
+ type = with types; functionTo attrs;
+ default = tl: { inherit (tl) scheme-full; };
+ defaultText = literalExample "tl: { inherit (tl) scheme-full; }";
+ description = ''
+ Collection of packages that will be made available to the environment.
+ '';
+ example = literalExample ''
+ tl: {
+ inherit (tl) scheme-full calligra;
+ my-package = { pkgs = [ (pkgs.callPackage ./my-package.nix {}) ]; };
+ }
+ '';
+ };
+
+ latexmk = {
+ enable = mkEnableOption "latexmk";
+ output = {
+ dvi.enable = mkEnableOption "dvi output";
+ pdf = {
+ enable = mkEnableOption "pdf output";
+ method = mkOption {
+ type = types.enum [ "" "dvi" "lua" "ps" "xe" ];
+ default = "lua";
+ description = ''
+ Method by which to generate the pdf.
+ '';
+ };
+ };
+ ps.enable = mkEnableOption "ps output";
+ };
+ rc = mkOption {
+ type = types.listOf types.path;
+ default = [ ];
+ description = ''
+ List of LaTeXmk rc files to load.
+ '';
+ example = literalExample "[ ~/.config/latexmkrc ]";
+ };
+ extraFlags = mkOption {
+ # TODO vulnerable to shell injection
+ type = types.listOf types.str;
+ default = [ ];
+ description = ''
+ Flags to pass to latexmk.
+ '';
+ example = [ "-shell-escape" "-M" ];
+ };
+ };
+
+ minted.enable = mkEnableOption "minted";
+ };
+
+ config = mkIf cfg.enable {
+ buildInputs = [ latexBuildInput ] ++ (optional cfg.latexmk.enable pkgs.ps);
+ aliases.latexmk = mkIf cfg.latexmk.enable
+ "${latexBuildInput}/bin/latexmk ${latexmkFlags} \\$@";
+ python = mkIf cfg.minted.enable {
+ enable = true;
+ packages = ps: with ps; [ pygments ];
+ };
+ };
+}