summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMinijackson <minijackson@riseup.net>2021-11-04 10:45:06 +0100
committerMinijackson <minijackson@riseup.net>2021-11-04 10:45:06 +0100
commita777982b17ca555cb2a33e5828f8dc9cca302430 (patch)
tree7af0bdc41ec7eb19bed9c87b3886fd67060063d0
parent1649317cb21c7fd30a5147cffdd1b24a6cef258a (diff)
downloadpandoc-nix-templates-a777982b17ca555cb2a33e5828f8dc9cca302430.tar.gz
pandoc-nix-templates-a777982b17ca555cb2a33e5828f8dc9cca302430.zip
factorize build instructions
-rw-r--r--beamer/flake.nix116
-rw-r--r--flake.nix18
-rw-r--r--latex.nix73
-rw-r--r--overlay.nix54
4 files changed, 153 insertions, 108 deletions
diff --git a/beamer/flake.nix b/beamer/flake.nix
index d5e1614..b2c472e 100644
--- a/beamer/flake.nix
+++ b/beamer/flake.nix
@@ -2,115 +2,19 @@
2 description = "My epic presentation"; 2 description = "My epic presentation";
3 3
4 inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; 4 inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
5 inputs.beamertheme-metropolis = { 5 inputs.pandoc-nix-templates.url = "github:minijackson/pandoc-nix-templates";
6 url = "github:matze/mtheme";
7 flake = false;
8 };
9 inputs.draculaTheme = {
10 url = "github:dracula/pygments";
11 flake = false;
12 };
13 inputs.pandoc-templates = {
14 url = "github:minijackson/pandoc-templates";
15 flake = false;
16 };
17 6
18 outputs = { self, nixpkgs, beamertheme-metropolis, draculaTheme, pandoc-templates, }: 7 outputs = { self, nixpkgs, pandoc-nix-templates, }:
19 let 8 let
20 pkgs = nixpkgs.legacyPackages.x86_64-linux; 9 pkgs = import nixpkgs {
10 system = "x86_64-linux";
11 overlays = [ pandoc-nix-templates.overlay ];
12 };
21 in 13 in
22 { 14 {
23 15 defaultPackage.x86_64-linux = pkgs.mkPandocBeamerPdf {
24 packages.x86_64-linux.pygments = pkgs.python3Packages.pygments.overrideAttrs (oldAttrs: { 16 name = "slides";
25 postPatch = '' 17 src = ./.;
26 cp ${draculaTheme}/dracula.py pygments/styles/ 18 };
27 sed -i 's/bg:.\+ //' pygments/styles/inkpot.py
28 '';
29 });
30
31 defaultPackage.x86_64-linux =
32 let
33 beamertheme-metropolis' = pkgs.stdenvNoCC.mkDerivation {
34 pname = "texlive-beamertheme-metropolis";
35 version = "${builtins.substring 0 8 beamertheme-metropolis.lastModifiedDate}-${beamertheme-metropolis.shortRev or "dirty"}";
36
37 src = beamertheme-metropolis;
38
39 outputs = [ "out" "doc" ];
40
41 nativeBuildInputs = with pkgs; [
42 (texlive.combine {
43 inherit (texlive)
44 scheme-small
45 enumitem
46 fileinfo
47 latexmk;
48 })
49 ];
50
51 passthru = {
52 pname = "beamertheme-metropolis";
53 tlType = "run";
54 };
55
56 DESTDIR = placeholder "out";
57
58 dontConfigure = true;
59 };
60 in
61 pkgs.runCommand "slides"
62 {
63 src = ./.;
64 nativeBuildInputs = with pkgs; [
65 pandoc
66 self.packages.x86_64-linux.pygments
67 fira-code
68 which
69 (texlive.combine {
70 inherit (texlive)
71 scheme-medium
72 latexmk
73
74 beamercolorthemeowl
75
76 # For framed code listings
77 tcolorbox environ
78
79 # Optional pandoc dependencies
80 microtype upquote parskip xurl bookmark footnotehyper
81
82 # Some dependencies
83 fvextra pgfopts minted catchfile xstring framed;
84 beamertheme-metropolis = { pkgs = [ beamertheme-metropolis' ]; };
85 })
86 ];
87
88 FONTCONFIG_FILE = pkgs.makeFontsConf {
89 fontDirectories = with pkgs; [ lmodern freefont_ttf fira fira-code ];
90 };
91 } ''
92 unpackFile $src
93 cd */
94 chmod -R u+w .
95
96 pandoc slides.md -t beamer -so slides.tex \
97 --template=${pandoc-templates}/default.latex \
98 --lua-filter=${pkgs.pandoc-lua-filters}/share/pandoc/filters/minted.lua \
99 --pdf-engine=xelatex \
100 --pdf-engine-opt=-aux-directory=./build \
101 --pdf-engine-opt=-shell-escape
102
103 latexmk \
104 -shell-escape \
105 -xelatex \
106 -8bit \
107 -interaction=nonstopmode \
108 -verbose \
109 -file-line-error \
110 -output-directory=./build slides
111
112 cp build/slides.pdf $out
113 '';
114 # TODO: diagram-generator?
115 }; 19 };
116} 20}
diff --git a/flake.nix b/flake.nix
index ca5e3a4..f5ed111 100644
--- a/flake.nix
+++ b/flake.nix
@@ -1,7 +1,22 @@
1{ 1{
2 description = "My templates for making things with pandoc"; 2 description = "My templates for making things with pandoc";
3 3
4 outputs = { self, nixpkgs }: { 4 inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
5 inputs.beamertheme-metropolis = {
6 url = "github:matze/mtheme";
7 flake = false;
8 };
9 inputs.draculaTheme = {
10 url = "github:dracula/pygments";
11 flake = false;
12 };
13 inputs.pandoc-templates = {
14 url = "github:minijackson/pandoc-templates";
15 flake = false;
16 };
17
18 outputs = inputs @ { self, nixpkgs, beamertheme-metropolis, draculaTheme, pandoc-templates, }: {
19 overlay = import ./overlay.nix inputs;
5 20
6 templates = { 21 templates = {
7 beamer = { 22 beamer = {
@@ -11,6 +26,5 @@
11 }; 26 };
12 27
13 defaultTemplate = self.templates.beamer; 28 defaultTemplate = self.templates.beamer;
14
15 }; 29 };
16} 30}
diff --git a/latex.nix b/latex.nix
new file mode 100644
index 0000000..7c0de49
--- /dev/null
+++ b/latex.nix
@@ -0,0 +1,73 @@
1{ runCommand
2, makeFontsConf
3, fira
4, fira-code
5, freefont_ttf
6, lmodern
7, pandoc
8, pandoc-lua-filters
9, pandoc-templates
10, pygments
11, texlive
12, which
13, documentType ? "latex"
14}:
15
16{ name, src }:
17
18runCommand name
19{
20 inherit src;
21
22 nativeBuildInputs = [
23 pandoc
24 pygments
25 fira-code
26 which
27 (texlive.combine {
28 inherit (texlive)
29 scheme-medium
30 latexmk
31
32 beamertheme-metropolis
33 beamercolorthemeowl
34
35 # For framed code listings
36 tcolorbox environ
37
38 # Optional pandoc dependencies
39 microtype upquote parskip xurl bookmark footnotehyper
40
41 # Some dependencies
42 fvextra pgfopts minted catchfile xstring framed;
43 })
44 ];
45
46 FONTCONFIG_FILE = makeFontsConf {
47 fontDirectories = [ lmodern freefont_ttf fira fira-code ];
48 };
49} ''
50 unpackFile $src
51 cd */
52 chmod -R u+w .
53
54 pandoc ${name}.md -t ${documentType} -so document.tex \
55 --template=${pandoc-templates}/default.latex \
56 --lua-filter=${pandoc-lua-filters}/share/pandoc/filters/minted.lua \
57 --pdf-engine=xelatex \
58 --pdf-engine-opt=-aux-directory=./build \
59 --pdf-engine-opt=-shell-escape
60
61 latexmk \
62 -shell-escape \
63 -xelatex \
64 -8bit \
65 -interaction=nonstopmode \
66 -verbose \
67 -file-line-error \
68 -output-directory=./build document.tex
69
70 cp build/document.pdf $out
71''
72
73# TODO: diagram-generator?
diff --git a/overlay.nix b/overlay.nix
new file mode 100644
index 0000000..dc129f4
--- /dev/null
+++ b/overlay.nix
@@ -0,0 +1,54 @@
1inputs:
2
3final: prev:
4
5{
6 inherit (inputs) pandoc-templates;
7
8 pygments = prev.python3Packages.pygments.overrideAttrs (oldAttrs: {
9 postPatch = ''
10 cp ${inputs.draculaTheme}/dracula.py pygments/styles/
11 sed -i 's/bg:.\+ //' pygments/styles/inkpot.py
12 '';
13 });
14
15 texlive = (prev.texlive or { }) // {
16 beamertheme-metropolis =
17 let
18 date = builtins.substring 0 8 inputs.beamertheme-metropolis.lastModifiedDate;
19 shortRev = inputs.beamertheme-metropolis.shortRev or "dirty";
20
21 pkg = final.stdenvNoCC.mkDerivation {
22 pname = "texlive-beamertheme-metropolis";
23 version = "${date}-${shortRev}";
24
25 src = inputs.beamertheme-metropolis;
26
27 outputs = [ "out" "doc" ];
28
29 nativeBuildInputs = [
30 (final.texlive.combine {
31 inherit (final.texlive)
32 scheme-small
33 enumitem
34 fileinfo
35 latexmk;
36 })
37 ];
38
39 passthru = {
40 pname = "beamertheme-metropolis";
41 tlType = "run";
42 };
43
44 DESTDIR = placeholder "out";
45
46 dontConfigure = true;
47 };
48 in
49 { pkgs = [ pkg ]; };
50 };
51
52 mkPandocPdf = final.callPackage ./latex.nix { };
53 mkPandocBeamerPdf = final.callPackage ./latex.nix { documentType = "beamer"; };
54}