2022-01-01 14:51:06 -05:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.programs.pandoc;
|
|
|
|
|
|
|
|
inherit (lib) literalExpression mkEnableOption mkIf mkOption types;
|
|
|
|
|
|
|
|
jsonFormat = pkgs.formats.json { };
|
|
|
|
|
|
|
|
makeTemplateFile = name: file:
|
|
|
|
lib.nameValuePair "pandoc/templates/${name}" { source = file; };
|
|
|
|
|
|
|
|
getFileName = file:
|
|
|
|
# This is actually safe here, since it is just a file name
|
|
|
|
builtins.unsafeDiscardStringContext (baseNameOf file);
|
|
|
|
|
|
|
|
makeCslFile = file:
|
|
|
|
lib.nameValuePair "pandoc/csl/${getFileName file}" { source = file; };
|
|
|
|
|
|
|
|
in {
|
|
|
|
meta.maintainers = [ lib.maintainers.kirelagin ];
|
|
|
|
|
|
|
|
options.programs.pandoc = {
|
2023-07-01 00:30:13 +01:00
|
|
|
enable = mkEnableOption (lib.mdDoc "pandoc");
|
2022-01-01 14:51:06 -05:00
|
|
|
|
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.pandoc;
|
|
|
|
defaultText = literalExpression "pkgs.pandoc";
|
2023-07-01 00:30:13 +01:00
|
|
|
description = lib.mdDoc "The pandoc package to use.";
|
2022-01-01 14:51:06 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
# We wrap the executable to pass some arguments
|
|
|
|
finalPackage = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
readOnly = true;
|
2023-07-01 00:30:13 +01:00
|
|
|
description = lib.mdDoc "Resulting package.";
|
2022-01-01 14:51:06 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
defaults = mkOption {
|
|
|
|
type = jsonFormat.type;
|
|
|
|
default = { };
|
|
|
|
example = literalExpression ''
|
|
|
|
{
|
|
|
|
metadata = {
|
|
|
|
author = "John Doe";
|
|
|
|
};
|
|
|
|
pdf-engine = "xelatex";
|
|
|
|
citeproc = true;
|
|
|
|
}
|
|
|
|
'';
|
2023-07-01 00:30:13 +01:00
|
|
|
description = lib.mdDoc ''
|
2022-01-01 14:51:06 -05:00
|
|
|
Options to set by default.
|
|
|
|
These will be converted to JSON and written to a defaults
|
|
|
|
file (see Default files in pandoc documentation).
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
defaultsFile = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
readOnly = true;
|
2023-07-01 00:30:13 +01:00
|
|
|
description = lib.mdDoc "Resulting defaults file.";
|
2022-01-01 14:51:06 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
templates = mkOption {
|
|
|
|
type = types.attrsOf types.path;
|
|
|
|
default = { };
|
|
|
|
example = literalExpression ''
|
|
|
|
{
|
|
|
|
"default.latex" = path/to/your/template;
|
|
|
|
}
|
|
|
|
'';
|
2023-07-01 00:30:13 +01:00
|
|
|
description = lib.mdDoc "Custom templates.";
|
2022-01-01 14:51:06 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
citationStyles = mkOption {
|
|
|
|
type = types.listOf types.path;
|
|
|
|
default = [ ];
|
|
|
|
example = literalExpression "[ path/to/file.csl ]";
|
2023-07-01 00:30:13 +01:00
|
|
|
description = lib.mdDoc "List of .csl files to install.";
|
2022-01-01 14:51:06 -05:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
programs.pandoc = {
|
|
|
|
defaultsFile = jsonFormat.generate "hm.json" cfg.defaults;
|
|
|
|
|
|
|
|
finalPackage = pkgs.symlinkJoin {
|
|
|
|
name = "pandoc-with-defaults";
|
|
|
|
paths = [ cfg.package ];
|
|
|
|
nativeBuildInputs = [ pkgs.makeWrapper ];
|
|
|
|
postBuild = ''
|
|
|
|
wrapProgram "$out/bin/pandoc" \
|
|
|
|
--add-flags '--defaults "${cfg.defaultsFile}"'
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
home.packages = [ cfg.finalPackage ];
|
|
|
|
xdg.dataFile = lib.mapAttrs' makeTemplateFile cfg.templates
|
|
|
|
// lib.listToAttrs (map makeCslFile cfg.citationStyles);
|
|
|
|
};
|
|
|
|
}
|