fork/home-manager
git clone https://git.julia.blue/fork/home-manager
c47c350f
master
1{ config , lib , pkgs , ...} : 2 3let 4 5cfg = config . programs . pandoc ; 6 7inherit ( lib ) literalExpression mkEnableOption mkIf mkOption types ; 8 9jsonFormat = pkgs . formats . json { }; 10 11makeTemplateFile = name :file : 12lib . nameValuePair "pandoc/templates/ ${ name } " { source = file ; }; 13 14getFileName = file : 15# This is actually safe here, since it is just a file name 16builtins . unsafeDiscardStringContext ( baseNameOf file ); 17 18makeCslFile = file : 19lib . nameValuePair "pandoc/csl/ ${ getFileName file } " { source = file ; }; 20 21in { 22meta . maintainers = [ lib . maintainers . kirelagin ]; 23 24options . programs . pandoc = { 25enable = mkEnableOption "pandoc" ; 26 27package = mkOption { 28type = types . package ; 29default = pkgs . pandoc ; 30defaultText = literalExpression "pkgs.pandoc" ; 31description = "The pandoc package to use." ; 32}; 33 34# We wrap the executable to pass some arguments 35finalPackage = mkOption { 36type = types . package ; 37readOnly = true ; 38description = "Resulting package." ; 39}; 40 41defaults = mkOption { 42type = jsonFormat . type ; 43default = { }; 44example = literalExpression '' 45{ 46metadata = { 47author = "John Doe"; 48}; 49pdf-engine = "xelatex"; 50citeproc = true; 51} 52'' ; 53description = '' 54Options to set by default. 55These will be converted to JSON and written to a defaults 56file (see Default files in pandoc documentation). 57'' ; 58}; 59 60defaultsFile = mkOption { 61type = types . path ; 62readOnly = true ; 63description = "Resulting defaults file." ; 64}; 65 66templates = mkOption { 67type = types . attrsOf types . path ; 68default = { }; 69example = literalExpression '' 70{ 71"default.latex" = path/to/your/template; 72} 73'' ; 74description = "Custom templates." ; 75}; 76 77citationStyles = mkOption { 78type = types . listOf types . path ; 79default = [ ]; 80example = literalExpression "[ path/to/file.csl ]" ; 81description = "List of .csl files to install." ; 82}; 83}; 84 85config = mkIf cfg . enable { 86programs . pandoc = { 87defaultsFile = jsonFormat . generate "hm.json" cfg . defaults ; 88 89finalPackage = pkgs . symlinkJoin { 90name = "pandoc-with-defaults" ; 91paths = [ cfg . package ]; 92nativeBuildInputs = [ pkgs . makeWrapper ]; 93postBuild = '' 94wrapProgram " $ out /bin/pandoc" \ 95--add-flags '--defaults " ${ cfg . defaultsFile } "' 96'' ; 97}; 98}; 99 100home . packages = [ cfg . finalPackage ]; 101xdg . dataFile = lib . mapAttrs' makeTemplateFile cfg . templates 102// lib . listToAttrs ( map makeCslFile cfg . citationStyles ); 103}; 104}