mirror of
https://github.com/nix-community/home-manager
synced 2024-12-23 10:19:48 +01:00
pandoc: add new module
Add a module for pandoc that provides the following: 1. Setting default configuration options. 2. Installing templates. 3. Installing citation styles.
This commit is contained in:
parent
e622c5d836
commit
c47c350f65
14 changed files with 227 additions and 0 deletions
3
.github/CODEOWNERS
vendored
3
.github/CODEOWNERS
vendored
|
@ -176,6 +176,9 @@
|
|||
|
||||
/modules/programs/openssh.nix @rycee
|
||||
|
||||
/modules/programs/pandoc.nix @kirelagin
|
||||
/tests/modules/programs/pandoc @kirelagin
|
||||
|
||||
/modules/programs/password-store.nix @pacien
|
||||
|
||||
/modules/programs/pazi.nix @marsam
|
||||
|
|
|
@ -2380,6 +2380,13 @@ in
|
|||
A new module is available: 'programs.tint2'.
|
||||
'';
|
||||
}
|
||||
|
||||
{
|
||||
time = "2022-01-22T17:39:20+00:00";
|
||||
message = ''
|
||||
A new module is available: 'programs.pandoc'.
|
||||
'';
|
||||
}
|
||||
];
|
||||
};
|
||||
}
|
||||
|
|
|
@ -117,6 +117,7 @@ let
|
|||
./programs/octant.nix
|
||||
./programs/offlineimap.nix
|
||||
./programs/opam.nix
|
||||
./programs/pandoc.nix
|
||||
./programs/password-store.nix
|
||||
./programs/pazi.nix
|
||||
./programs/pet.nix
|
||||
|
|
104
modules/programs/pandoc.nix
Normal file
104
modules/programs/pandoc.nix
Normal file
|
@ -0,0 +1,104 @@
|
|||
{ 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 "pandoc";
|
||||
|
||||
package = mkOption {
|
||||
type = types.package;
|
||||
default = pkgs.pandoc;
|
||||
defaultText = literalExpression "pkgs.pandoc";
|
||||
description = "The pandoc package to use.";
|
||||
};
|
||||
|
||||
# We wrap the executable to pass some arguments
|
||||
finalPackage = mkOption {
|
||||
type = types.package;
|
||||
readOnly = true;
|
||||
description = "Resulting package.";
|
||||
};
|
||||
|
||||
defaults = mkOption {
|
||||
type = jsonFormat.type;
|
||||
default = { };
|
||||
example = literalExpression ''
|
||||
{
|
||||
metadata = {
|
||||
author = "John Doe";
|
||||
};
|
||||
pdf-engine = "xelatex";
|
||||
citeproc = true;
|
||||
}
|
||||
'';
|
||||
description = ''
|
||||
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 = "Resulting defaults file.";
|
||||
};
|
||||
|
||||
templates = mkOption {
|
||||
type = types.attrsOf types.path;
|
||||
default = { };
|
||||
example = literalExpression ''
|
||||
{
|
||||
"default.latex" = path/to/your/template;
|
||||
}
|
||||
'';
|
||||
description = "Custom templates.";
|
||||
};
|
||||
|
||||
citationStyles = mkOption {
|
||||
type = types.listOf types.path;
|
||||
default = [ ];
|
||||
example = literalExpression "[ path/to/file.csl ]";
|
||||
description = "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);
|
||||
};
|
||||
}
|
|
@ -86,6 +86,7 @@ import nmt {
|
|||
./modules/programs/nix-index
|
||||
./modules/programs/nnn
|
||||
./modules/programs/nushell
|
||||
./modules/programs/pandoc
|
||||
./modules/programs/pet
|
||||
./modules/programs/powerline-go
|
||||
./modules/programs/qutebrowser
|
||||
|
|
18
tests/modules/programs/pandoc/csl.nix
Normal file
18
tests/modules/programs/pandoc/csl.nix
Normal file
|
@ -0,0 +1,18 @@
|
|||
{ config, ... }:
|
||||
|
||||
{
|
||||
programs.pandoc = {
|
||||
enable = true;
|
||||
|
||||
citationStyles = [ ./example.csl ];
|
||||
};
|
||||
|
||||
test.stubs.pandoc = import ./stub.nix;
|
||||
|
||||
nmt.script = ''
|
||||
assertFileExists home-files/.local/share/pandoc/csl/example.csl
|
||||
assertFileContent home-files/.local/share/pandoc/csl/example.csl \
|
||||
${./example.csl}
|
||||
'';
|
||||
}
|
||||
|
5
tests/modules/programs/pandoc/default.nix
Normal file
5
tests/modules/programs/pandoc/default.nix
Normal file
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
pandoc-citation-styles = ./csl.nix;
|
||||
pandoc-defaults = ./defaults.nix;
|
||||
pandoc-templates = ./templates.nix;
|
||||
}
|
7
tests/modules/programs/pandoc/defaults-expected.json
Normal file
7
tests/modules/programs/pandoc/defaults-expected.json
Normal file
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"citeproc": true,
|
||||
"metadata": {
|
||||
"author": "John Doe"
|
||||
},
|
||||
"pdf-engine": "xelatex"
|
||||
}
|
30
tests/modules/programs/pandoc/defaults.nix
Normal file
30
tests/modules/programs/pandoc/defaults.nix
Normal file
|
@ -0,0 +1,30 @@
|
|||
{ config, lib, ... }:
|
||||
|
||||
let cfg = config.programs.pandoc;
|
||||
|
||||
in {
|
||||
config = lib.mkIf config.test.enableBig {
|
||||
programs.pandoc = {
|
||||
enable = true;
|
||||
|
||||
defaults = {
|
||||
metadata = { author = "John Doe"; };
|
||||
pdf-engine = "xelatex";
|
||||
citeproc = true;
|
||||
};
|
||||
};
|
||||
|
||||
nmt.script = ''
|
||||
assertFileContent ${cfg.defaultsFile} ${./defaults-expected.json}
|
||||
|
||||
# Test that defaults are set by looking at the metadata for an empty file
|
||||
# (it should contain the author that we set in defaults).
|
||||
output=$(mktemp)
|
||||
${cfg.finalPackage}/bin/pandoc --standalone \
|
||||
-f markdown /dev/null \
|
||||
-t native -o "$output"
|
||||
assertFileContent "$output" ${./output-expected}
|
||||
'';
|
||||
};
|
||||
}
|
||||
|
12
tests/modules/programs/pandoc/example.csl
Normal file
12
tests/modules/programs/pandoc/example.csl
Normal file
|
@ -0,0 +1,12 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<style xmlns="http://purl.org/net/xbiblio/csl" version="1.0" default-locale="en-US">
|
||||
<info>
|
||||
<title>A trivial CSL style for tests</title>
|
||||
<id>https://github.com/nix-community/home-manager/tree/master/tests/modules/tools/pandoc/example.csl</id>
|
||||
<link href="https://github.com/nix-community/home-manager/tree/master/tests/modules/tools/pandoc/example.csl" rel="self"/>
|
||||
<link href=""https://www.zotero.org/styles/association-for-computing-machinery rel="independent-parent"/>
|
||||
<link href="http://aem.asm.org/" rel="documentation"/>
|
||||
<category citation-format="numeric"/>
|
||||
<category field="engineering"/>
|
||||
</info>
|
||||
</style>
|
2
tests/modules/programs/pandoc/output-expected
Normal file
2
tests/modules/programs/pandoc/output-expected
Normal file
|
@ -0,0 +1,2 @@
|
|||
Pandoc (Meta {unMeta = fromList [("author",MetaString "John Doe")]})
|
||||
[]
|
10
tests/modules/programs/pandoc/stub.nix
Normal file
10
tests/modules/programs/pandoc/stub.nix
Normal file
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
name = "pandoc-stub";
|
||||
outPath = null;
|
||||
buildScript = ''
|
||||
mkdir -p "$out"/bin
|
||||
pandoc="$out"/bin/pandoc
|
||||
echo 'Stub to make the wrapper happy' > "$pandoc"
|
||||
chmod a+x "$pandoc"
|
||||
'';
|
||||
}
|
9
tests/modules/programs/pandoc/template.latex
Normal file
9
tests/modules/programs/pandoc/template.latex
Normal file
|
@ -0,0 +1,9 @@
|
|||
\documentclass[a4paper]{scrartcl}
|
||||
|
||||
$if(title)$\title{$title$}$endif$
|
||||
$if(author)$\author{$for(author)$$author$$sep$ \and $endfor$}$endif$
|
||||
|
||||
\begin{document}
|
||||
\maketitle
|
||||
$body$
|
||||
\end{document}
|
18
tests/modules/programs/pandoc/templates.nix
Normal file
18
tests/modules/programs/pandoc/templates.nix
Normal file
|
@ -0,0 +1,18 @@
|
|||
{ config, ... }:
|
||||
|
||||
{
|
||||
programs.pandoc = {
|
||||
enable = true;
|
||||
|
||||
templates = { "default.latex" = ./template.latex; };
|
||||
};
|
||||
|
||||
test.stubs.pandoc = import ./stub.nix;
|
||||
|
||||
nmt.script = ''
|
||||
assertFileExists home-files/.local/share/pandoc/templates/default.latex
|
||||
assertFileContent home-files/.local/share/pandoc/templates/default.latex \
|
||||
${./template.latex}
|
||||
'';
|
||||
}
|
||||
|
Loading…
Reference in a new issue