blob: fb6388079922a0a0691ee5d8307e0f08be241797 (
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
|
# Build environment and recipe for the Markdown course website example.
#
# Author: Pacien TRAN-GIRARD
# Licence: CC BY-NC 4.0
{
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-small;
solutionsSecret = "topsecret";
compileQuarto = options: stdenv.mkDerivation {
name = "quarto-book";
src = ./.;
nativeBuildInputs = [ quarto ];
buildPhase = ''
export HOME=$PWD
${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 {
pdf-slides = compilePandoc ./lectures "beamer" "";
pdf-exercises = compilePandoc ./exercises "pdf" "STRIP_SOLUTIONS=1";
pdf-solutions = compilePandoc ./exercises "pdf" "";
website-public = compileQuarto "STRIP_SOLUTIONS=1";
website-private = compileQuarto "";
# Everything combined
default = runCommand "combined" { } ''
cp -Lr --no-preserve=mode ${website-public} "$out"
cp -Lr --no-preserve=mode ${website-private} "$out/${solutionsSecret}"
cp -Lr ${pdf-slides}/* "$out/lectures"
cp -Lr ${pdf-exercises}/* "$out/exercises"
cp -Lr ${pdf-slides}/* "$out/${solutionsSecret}/lectures"
cp -Lr ${pdf-solutions}/* "$out/${solutionsSecret}/exercises"
'';
};
});
}
|