1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-10-01 02:37:27 +02:00
home-manager/modules/programs/pandoc.nix
Emily 36a53d9f26 treewide: convert all option docs to Markdown
This process was automated by [my fork of `nix-doc-munge`]. All
conversions were automatically checked to produce the same DocBook
result when converted back, modulo minor typographical/formatting
differences on the acceptable-to-desirable spectrum.

To reproduce this commit, run:

  $ NIX_PATH=nixpkgs=flake:nixpkgs/e7e69199f0372364a6106a1e735f68604f4c5a25 \
    nix shell nixpkgs#coreutils \
    -c find . -name '*.nix' \
    -exec nix run -- github:emilazy/nix-doc-munge/98dadf1f77351c2ba5dcb709a2a171d655f15099 \
    {} +
  $ ./format

[my fork of `nix-doc-munge`]: https://github.com/emilazy/nix-doc-munge/tree/home-manager
2023-07-17 18:40:56 +01:00

104 lines
2.7 KiB
Nix

{ 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 = {
enable = mkEnableOption (lib.mdDoc "pandoc");
package = mkOption {
type = types.package;
default = pkgs.pandoc;
defaultText = literalExpression "pkgs.pandoc";
description = lib.mdDoc "The pandoc package to use.";
};
# We wrap the executable to pass some arguments
finalPackage = mkOption {
type = types.package;
readOnly = true;
description = lib.mdDoc "Resulting package.";
};
defaults = mkOption {
type = jsonFormat.type;
default = { };
example = literalExpression ''
{
metadata = {
author = "John Doe";
};
pdf-engine = "xelatex";
citeproc = true;
}
'';
description = lib.mdDoc ''
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;
description = lib.mdDoc "Resulting defaults file.";
};
templates = mkOption {
type = types.attrsOf types.path;
default = { };
example = literalExpression ''
{
"default.latex" = path/to/your/template;
}
'';
description = lib.mdDoc "Custom templates.";
};
citationStyles = mkOption {
type = types.listOf types.path;
default = [ ];
example = literalExpression "[ path/to/file.csl ]";
description = lib.mdDoc "List of .csl files to install.";
};
};
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);
};
}