# Build environment and recipe for the Markdown course website example. # # Author: Pacien TRAN-GIRARD # Licence: EUPL-1.2 { inputs = { # Not yet merged. # quarto: 1.1.251 -> 1.2.269: https://github.com/NixOS/nixpkgs/pull/201551 nixpkgs.url = "github:NixOS/nixpkgs/a0297ff"; flake-utils.url = "github:numtide/flake-utils"; flaky-utils.url = "git+https://cgit.pacien.net/libs/flaky-utils"; }; outputs = { self, nixpkgs, flake-utils, flaky-utils }: flake-utils.lib.eachDefaultSystem (system: with nixpkgs.legacyPackages.${system}; let texliveDist = texlive.combined.scheme-full; solutionsSecret = "topsecret"; compileQuarto = options: stdenv.mkDerivation { name = "quarto-book"; src = ./.; nativeBuildInputs = [ quarto ]; buildPhase = '' export HOME=/build ${options} quarto render ''; installPhase = '' mkdir -p "$out" cp -r _book/* "$out/" ''; }; compilePandoc = src: to: options: stdenv.mkDerivation { name = "pandoc-output"; inherit src; nativeBuildInputs = [ pandoc texliveDist ]; installPhase = '' mkdir -p "$out" for f in *.md; do ${options} pandoc $f \ --lua-filter ${./filters/strip-solutions.lua} \ --output "$out"/$(basename $f .md).pdf \ --to ${to} done ''; }; in { devShell = flaky-utils.lib.mkDevShell { inherit pkgs; tools = [ quarto pandoc texlive ]; }; packages = rec { website-public = compileQuarto "STRIP_SOLUTIONS=1"; website-private = compileQuarto ""; website = runCommand "website-combined" { } '' mkdir -p "$out" cp -r "${website-public}"/* "$out/" mkdir -p "$out/${solutionsSecret}" cp -r "${website-private}"/* "$out/${solutionsSecret}" ''; pdf-slides = compilePandoc ./lectures "beamer" ""; pdf-exercises = compilePandoc ./exercises "pdf" "STRIP_SOLUTIONS=1"; pdf-solutions = compilePandoc ./exercises "pdf" ""; pdf = runCommand "pdf-combined" { } '' mkdir -p "$out" ln -s ${pdf-slides} "$out/slides" ln -s ${pdf-exercises} "$out/exercises" ln -s ${pdf-solutions} "$out/solutions" ''; }; }); }