-
Notifications
You must be signed in to change notification settings - Fork 1
/
flake.nix
181 lines (169 loc) · 4.85 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
{
description = "LaTeX Document Demo";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
poetry2nix.url = "github:nix-community/poetry2nix";
poetry2nix.inputs.flake-utils.follows = "flake-utils";
poetry2nix.inputs.nixpkgs.follows = "nixpkgs";
};
outputs = {
self,
nixpkgs,
flake-utils,
poetry2nix,
}:
flake-utils.lib.eachSystem ["x86_64-linux"] (system: let
pkgs = nixpkgs.legacyPackages.${system};
lib = pkgs.lib;
inherit
(poetry2nix.lib.mkPoetry2Nix {inherit pkgs;})
mkPoetryEnv
;
tex = pkgs.texlive.combine {
inherit
(pkgs.texlive)
scheme-basic
latexmk
biblatex
biblatex-ieee
enumitem
fontaxes
hyperref
opensans
titlesec
xkeyval
xcolor
fontawesome5
;
};
packagingLib = import ./lib/packaging.nix {
inherit pkgs tex;
directory = ./.;
};
documentationLib = import ./lib/documentation.nix {inherit self pkgs lib;};
examplesLib = import ./lib/examples.nix {inherit self system pkgs lib;};
moduleMarkdownDocs = documentationLib.generateMarkdownDocumentation {};
examplePdfDocs = examplesLib.generateExamplesDocumentation {};
site-env = mkPoetryEnv {
projectDir = self + /site;
python = pkgs.python311;
};
site = pkgs.stdenvNoCC.mkDerivation {
name = "nixcv-site";
src = self + "/site";
nativeBuildInputs = [site-env];
buildPhase = ''
cp -r ${moduleMarkdownDocs}/* ./docs/
cp -r ${examplePdfDocs}/* ./docs/
mkdir -p .cache/plugin/social
cp ${pkgs.roboto}/share/fonts/truetype/Roboto-* .cache/plugin/social/
mkdocs build --site-dir dist
'';
installPhase = ''
mkdir $out
cp -R dist/* $out/
'';
};
in {
devShells = {
poetry = pkgs.mkShell {
packages = [
pkgs.poetry
pkgs.python311
];
};
site = pkgs.mkShell {
buildInputs = [
pkgs.poetry
site-env
];
};
};
packages =
{
document = pkgs.stdenvNoCC.mkDerivation rec {
name = "latex-demo-document";
src = self;
propagatedBuildInputs = [pkgs.coreutils pkgs.biber tex];
phases = ["unpackPhase" "buildPhase" "installPhase"];
SCRIPT = ''
#!/bin/bash
prefix=${builtins.placeholder "out"}
export PATH="${pkgs.lib.makeBinPath propagatedBuildInputs}";
DIR=$(mktemp -d)
RES=$(pwd)/document.pdf
cd $prefix/share
mkdir -p "$DIR/.texcache/texmf-var"
env TEXMFHOME="$DIR/.cache" \
TEXMFVAR="$DIR/.cache/texmf-var" \
latexmk -interaction=nonstopmode -pdf -pdflatex \
-output-directory="$DIR" \
document.tex
mv "$DIR/document.pdf" $RES
rm -rf "$DIR"
'';
buildPhase = ''
printenv SCRIPT >latex-demo-document
'';
installPhase = ''
mkdir -p $out/{bin,share}
cp ./old/document.tex $out/share/document.tex
cp ./old/cv.tex $out/share/cv.tex
cp ./old/self.bib $out/share/self.bib
cp latex-demo-document $out/bin/latex-demo-document
chmod u+x $out/bin/latex-demo-document
'';
};
}
// packagingLib.examples
// {
inherit
moduleMarkdownDocs
examplePdfDocs
site
;
};
apps = {
copyMarkdownDocs = {
type = "app";
program = "${documentationLib.copyMarkdownDocs}/bin/copy-markdown-docs";
};
copyExampleDocs = {
type = "app";
program = "${examplesLib.copyExampleDocs}/bin/copy-example-docs";
};
};
extra = {
evaluatedModules = documentationLib.evaluatedModules {};
};
checks =
{}
// packagingLib.examples
// {
inherit
moduleMarkdownDocs
examplePdfDocs
;
};
test = lib.listToAttrs (
builtins.map
(
file:
lib.nameValuePair
(lib.removeSuffix ".nix" file)
(import ./test/${file} {inherit lib;})
)
(
builtins.attrNames (
lib.filterAttrs
(name: value: value == "regular")
(builtins.readDir ./test)
)
)
);
})
// {
nixosModules.templates.simple = ./templates/simple.nix;
};
}