From a777982b17ca555cb2a33e5828f8dc9cca302430 Mon Sep 17 00:00:00 2001 From: Minijackson Date: Thu, 4 Nov 2021 10:45:06 +0100 Subject: factorize build instructions --- beamer/flake.nix | 116 +++++-------------------------------------------------- flake.nix | 18 ++++++++- latex.nix | 73 ++++++++++++++++++++++++++++++++++ overlay.nix | 54 ++++++++++++++++++++++++++ 4 files changed, 153 insertions(+), 108 deletions(-) create mode 100644 latex.nix create mode 100644 overlay.nix 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 @@ description = "My epic presentation"; inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; - inputs.beamertheme-metropolis = { - url = "github:matze/mtheme"; - flake = false; - }; - inputs.draculaTheme = { - url = "github:dracula/pygments"; - flake = false; - }; - inputs.pandoc-templates = { - url = "github:minijackson/pandoc-templates"; - flake = false; - }; + inputs.pandoc-nix-templates.url = "github:minijackson/pandoc-nix-templates"; - outputs = { self, nixpkgs, beamertheme-metropolis, draculaTheme, pandoc-templates, }: + outputs = { self, nixpkgs, pandoc-nix-templates, }: let - pkgs = nixpkgs.legacyPackages.x86_64-linux; + pkgs = import nixpkgs { + system = "x86_64-linux"; + overlays = [ pandoc-nix-templates.overlay ]; + }; in { - - packages.x86_64-linux.pygments = pkgs.python3Packages.pygments.overrideAttrs (oldAttrs: { - postPatch = '' - cp ${draculaTheme}/dracula.py pygments/styles/ - sed -i 's/bg:.\+ //' pygments/styles/inkpot.py - ''; - }); - - defaultPackage.x86_64-linux = - let - beamertheme-metropolis' = pkgs.stdenvNoCC.mkDerivation { - pname = "texlive-beamertheme-metropolis"; - version = "${builtins.substring 0 8 beamertheme-metropolis.lastModifiedDate}-${beamertheme-metropolis.shortRev or "dirty"}"; - - src = beamertheme-metropolis; - - outputs = [ "out" "doc" ]; - - nativeBuildInputs = with pkgs; [ - (texlive.combine { - inherit (texlive) - scheme-small - enumitem - fileinfo - latexmk; - }) - ]; - - passthru = { - pname = "beamertheme-metropolis"; - tlType = "run"; - }; - - DESTDIR = placeholder "out"; - - dontConfigure = true; - }; - in - pkgs.runCommand "slides" - { - src = ./.; - nativeBuildInputs = with pkgs; [ - pandoc - self.packages.x86_64-linux.pygments - fira-code - which - (texlive.combine { - inherit (texlive) - scheme-medium - latexmk - - beamercolorthemeowl - - # For framed code listings - tcolorbox environ - - # Optional pandoc dependencies - microtype upquote parskip xurl bookmark footnotehyper - - # Some dependencies - fvextra pgfopts minted catchfile xstring framed; - beamertheme-metropolis = { pkgs = [ beamertheme-metropolis' ]; }; - }) - ]; - - FONTCONFIG_FILE = pkgs.makeFontsConf { - fontDirectories = with pkgs; [ lmodern freefont_ttf fira fira-code ]; - }; - } '' - unpackFile $src - cd */ - chmod -R u+w . - - pandoc slides.md -t beamer -so slides.tex \ - --template=${pandoc-templates}/default.latex \ - --lua-filter=${pkgs.pandoc-lua-filters}/share/pandoc/filters/minted.lua \ - --pdf-engine=xelatex \ - --pdf-engine-opt=-aux-directory=./build \ - --pdf-engine-opt=-shell-escape - - latexmk \ - -shell-escape \ - -xelatex \ - -8bit \ - -interaction=nonstopmode \ - -verbose \ - -file-line-error \ - -output-directory=./build slides - - cp build/slides.pdf $out - ''; - # TODO: diagram-generator? + defaultPackage.x86_64-linux = pkgs.mkPandocBeamerPdf { + name = "slides"; + src = ./.; + }; }; } diff --git a/flake.nix b/flake.nix index ca5e3a4..f5ed111 100644 --- a/flake.nix +++ b/flake.nix @@ -1,7 +1,22 @@ { description = "My templates for making things with pandoc"; - outputs = { self, nixpkgs }: { + inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + inputs.beamertheme-metropolis = { + url = "github:matze/mtheme"; + flake = false; + }; + inputs.draculaTheme = { + url = "github:dracula/pygments"; + flake = false; + }; + inputs.pandoc-templates = { + url = "github:minijackson/pandoc-templates"; + flake = false; + }; + + outputs = inputs @ { self, nixpkgs, beamertheme-metropolis, draculaTheme, pandoc-templates, }: { + overlay = import ./overlay.nix inputs; templates = { beamer = { @@ -11,6 +26,5 @@ }; defaultTemplate = self.templates.beamer; - }; } diff --git a/latex.nix b/latex.nix new file mode 100644 index 0000000..7c0de49 --- /dev/null +++ b/latex.nix @@ -0,0 +1,73 @@ +{ runCommand +, makeFontsConf +, fira +, fira-code +, freefont_ttf +, lmodern +, pandoc +, pandoc-lua-filters +, pandoc-templates +, pygments +, texlive +, which +, documentType ? "latex" +}: + +{ name, src }: + +runCommand name +{ + inherit src; + + nativeBuildInputs = [ + pandoc + pygments + fira-code + which + (texlive.combine { + inherit (texlive) + scheme-medium + latexmk + + beamertheme-metropolis + beamercolorthemeowl + + # For framed code listings + tcolorbox environ + + # Optional pandoc dependencies + microtype upquote parskip xurl bookmark footnotehyper + + # Some dependencies + fvextra pgfopts minted catchfile xstring framed; + }) + ]; + + FONTCONFIG_FILE = makeFontsConf { + fontDirectories = [ lmodern freefont_ttf fira fira-code ]; + }; +} '' + unpackFile $src + cd */ + chmod -R u+w . + + pandoc ${name}.md -t ${documentType} -so document.tex \ + --template=${pandoc-templates}/default.latex \ + --lua-filter=${pandoc-lua-filters}/share/pandoc/filters/minted.lua \ + --pdf-engine=xelatex \ + --pdf-engine-opt=-aux-directory=./build \ + --pdf-engine-opt=-shell-escape + + latexmk \ + -shell-escape \ + -xelatex \ + -8bit \ + -interaction=nonstopmode \ + -verbose \ + -file-line-error \ + -output-directory=./build document.tex + + cp build/document.pdf $out +'' + +# 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 @@ +inputs: + +final: prev: + +{ + inherit (inputs) pandoc-templates; + + pygments = prev.python3Packages.pygments.overrideAttrs (oldAttrs: { + postPatch = '' + cp ${inputs.draculaTheme}/dracula.py pygments/styles/ + sed -i 's/bg:.\+ //' pygments/styles/inkpot.py + ''; + }); + + texlive = (prev.texlive or { }) // { + beamertheme-metropolis = + let + date = builtins.substring 0 8 inputs.beamertheme-metropolis.lastModifiedDate; + shortRev = inputs.beamertheme-metropolis.shortRev or "dirty"; + + pkg = final.stdenvNoCC.mkDerivation { + pname = "texlive-beamertheme-metropolis"; + version = "${date}-${shortRev}"; + + src = inputs.beamertheme-metropolis; + + outputs = [ "out" "doc" ]; + + nativeBuildInputs = [ + (final.texlive.combine { + inherit (final.texlive) + scheme-small + enumitem + fileinfo + latexmk; + }) + ]; + + passthru = { + pname = "beamertheme-metropolis"; + tlType = "run"; + }; + + DESTDIR = placeholder "out"; + + dontConfigure = true; + }; + in + { pkgs = [ pkg ]; }; + }; + + mkPandocPdf = final.callPackage ./latex.nix { }; + mkPandocBeamerPdf = final.callPackage ./latex.nix { documentType = "beamer"; }; +} -- cgit v1.2.3