forked from hmemcpy/milewski-ctfp-pdf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
149 lines (128 loc) · 3.94 KB
/
flake.nix
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
{
description = "Category Theory for Programmers";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-21.11";
inputs.utils.url = "github:numtide/flake-utils";
outputs = { self, nixpkgs, utils }: utils.lib.eachDefaultSystem (system: let
inherit (nixpkgs) lib;
pkgs = nixpkgs.legacyPackages.${system};
###########################################################################
# LaTeX Environment
texliveEnv = pkgs.texlive.combine {
inherit (pkgs.texlive)
bookcover
textpos
fgruler
tcolorbox
fvextra
framed
newtx
nowidow
emptypage
wrapfig
subfigure
adjustbox
collectbox
tikz-cd
imakeidx
idxlayout
titlesec
subfiles
lettrine
upquote
libertine
mweights
fontaxes
mdframed
needspace
xifthen
ifnextok
currfile
noindentafter
ifmtarg
scheme-medium
listings
minted
microtype
babel
todonotes
chngcntr
ifplatform
xstring
minifp
titlecaps
enumitem
environ
trimspaces
l3packages
zref
catchfile
import
;
};
###########################################################################
# Python Environment
# Pin the Python version and its associated package set in a single place.
python = pkgs.python38;
pythonPkgs = pkgs.python38Packages;
pygments-style-github = pythonPkgs.buildPythonPackage rec {
pname = "pygments-style-github";
version = "0.4";
doCheck = false; # Hopefully someone else has run the tests.
src = pythonPkgs.fetchPypi {
inherit pname version;
sha256 = "19zl8l5fyb8z3j8pdlm0zbgag669af66f8gn81ichm3x2hivvjhg";
};
# Anything depending on this derivation is probably also gonna want
# pygments to be available.
propagatedBuildInputs = with pythonPkgs; [ pygments ];
};
pythonEnv = python.withPackages (p: [ p.pygments pygments-style-github ]);
commonAttrs = {
nativeBuildInputs = [ texliveEnv pythonEnv pkgs.which ];
FONTCONFIG_FILE = pkgs.makeFontsConf {
fontDirectories = with pkgs; [ inconsolata-lgc libertine libertinus ];
};
};
mkLatex = variant: edition: let
maybeVariant = lib.optionalString (variant != null) "-${variant}";
maybeEdition = lib.optionalString (edition != null) "-${edition}";
variantStr = if variant == null then "reader" else variant;
suffix = maybeVariant + maybeEdition;
basename = "ctfp-${variantStr}${maybeEdition}";
version = self.shortRev or self.lastModifiedDate;
in pkgs.stdenv.mkDerivation (commonAttrs // {
inherit basename version;
name = "ctfp${suffix}-${version}";
fullname = "ctfp${suffix}";
src = "${self}/src";
configurePhase = ''
echo -n "\\newcommand{\\OPTversion}{$version}" > version.tex
'';
buildPhase = ''
latexmk -shell-escape -interaction=nonstopmode -halt-on-error \
-norc -jobname=ctfp -pdflatex="xelatex %O %S" -pdf "$basename.tex"
'';
installPhase = "install -m 0644 -vD ctfp.pdf \"$out/$fullname.pdf\"";
passthru.packageName = "ctfp${suffix}";
});
editions = [ null "scala" "ocaml" "reason" ];
variants = [ null "print" ];
in {
# nix build .#ctfp
# nix build .#ctfp-print
# nix build .#ctfp-print-ocaml
# etc etc
packages = lib.listToAttrs (lib.concatMap (variant: map (edition: rec {
name = value.packageName;
value = mkLatex variant edition;
}) editions) variants);
# nix build .
defaultPackage = self.packages.${system}.ctfp;
# nix develop .
devShell = pkgs.mkShell (commonAttrs // {
nativeBuildInputs = commonAttrs.nativeBuildInputs ++ [
pkgs.git pkgs.gnumake
];
});
});
}