blob: aa5c0738d871db132871c192f38c36833cec0d91 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# 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"
'';
};
});
}
|