mirror of
https://github.com/nix-community/home-manager.git
synced 2025-11-22 02:09:39 +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
|
|
@ -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);
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue