-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdefault.nix
282 lines (244 loc) · 8.72 KB
/
default.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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
rec {
pkgs = import (pkgsSrc) {};
pkgsOriginal = import <nixpkgs> {};
pkgsSrc = pkgsOriginal.fetchzip {
url = "https://github.com/NixOS/nixpkgs/archive/refs/tags/22.05.zip";
sha256 = "sha256-M6bJShji9AIDZ7Kh7CPwPBPb/T7RiVev2PAcOi4fxDQ=";
};
nodejs = pkgs.nodejs;
sphinx = pkgs.python3Packages.sphinx;
specBuilder = pkgs.python3Packages.buildPythonPackage rec {
name = "xml2rfc-2.5.1";
propagatedBuildInputs = with pkgs.python3Packages; [ lxml requests ];
src = pkgs.fetchurl {
url = "https://pypi.python.org/packages/source/x/xml2rfc/xml2rfc-2.5.1.tar.gz";
sha256 = "67d44fce6548c44e6065b95d0ef5b3a6e08928e6d659d4396928d8937c2be32d";
};
};
nodeModules = pkgs.stdenv.mkDerivation {
inherit nodejs;
name = "node-modules";
propagatedBuildInputs = [nodejs];
builder = builtins.toFile "builder.sh" "
source $stdenv/setup
HOME=.
npm install [email protected]
npm install [email protected]
npm install [email protected]
npm install [email protected]
npm install [email protected]
npm install [email protected]
npm install [email protected]
npm install [email protected]
mkdir $out
cp -R node_modules $out/node_modules
ln -sv $out/node_modules/.bin $out/bin
";
};
zip2dir = zipFile: pkgs.stdenv.mkDerivation {
name = "unzip";
buildInputs = [pkgs.unzip];
builder = builtins.toFile "builder.sh" "
source $stdenv/setup
mkdir $out
unzip $zipFile -d $out
";
inherit zipFile;
};
nodeBuilder = pkgs.stdenv.mkDerivation {
name = "node-builder";
propagatedBuildInputs = [nodeModules nodejs];
builder = builtins.toFile "builder.sh" "
source $stdenv/setup
mkdir $out
cp -R $siteDir/* $out
cp -R $nodeModules/* $out
";
siteDir = ./_site;
inherit nodeModules;
};
rfc2html = rfc : pkgs.stdenv.mkDerivation {
inherit rfc nodejs nodeBuilder;
name = "rfc2html";
builder = builtins.toFile "builder.sh" "
source $stdenv/setup
$nodejs/bin/node $nodeBuilder/spec.js < $rfc > $out
";
};
inject = {htmlTree, opts} : pkgs.stdenv.mkDerivation {
inherit nodejs nodeBuilder htmlTree opts;
name = "inject";
buildInputs = [nodejs];
builder = builtins.toFile "builder.sh" "
source $stdenv/setup
cp -R --no-preserve=mode $htmlTree $out
find $out -iname \\*.html | xargs node $nodeBuilder/inject.js $opts
";
};
xml2rfc = xmlFile : pkgs.stdenv.mkDerivation {
inherit xmlFile specBuilder;
name = "spec";
specs = ./_spec;
python = pkgs.python3;
builder = builtins.toFile "builder.sh" "
source $stdenv/setup
PATH=$python/bin:$PATH
mkdir cache
$specBuilder/bin/xml2rfc --no-network --cache=./cache $xmlFile --text --out=$out
chmod 644 $out
";
};
pythonDocs = pythonRoot : pkgs.stdenv.mkDerivation {
inherit pythonRoot;
name = "sphinx-docs";
buildInputs = [pkgs.python3 sphinx];
builder = builtins.toFile "builder.sh" "
source $stdenv/setup
cp -R $pythonRoot/* .
SOURCE_DATE_EPOCH=1451606400 # sphinx overrides copyright year based on this environment variable
sphinx-build -v -W -b html docs $out
";
};
pythonDocs02 = inject {
htmlTree = pythonDocs ./python/0.2;
opts = "--navbar python/0.2 --bs";
};
pythonDocs03 = inject {
htmlTree = pythonDocs ./python/0.3;
opts = "--navbar python/0.3 --bs";
};
pythonDocs04 = inject {
htmlTree = pythonDocs ./python/0.4;
opts = "--navbar python/0.4 --bs";
};
bootstrapDist = pkgs.fetchzip {
url = "https://github.com/twbs/bootstrap/releases/download/v3.3.0/bootstrap-3.3.0-dist.zip";
sha256 = "0i014fyw07vzhbjns05zjxv23q0k47m8ks7nfiv8psqaca45l1sy";
};
googleFonts = pkgs.stdenv.mkDerivation {
name = "google-fonts";
fonts = pkgs.google-fonts;
builder = builtins.toFile "builder.sh" "
source $stdenv/setup
mkdir $out
cp $fonts/share/fonts/truetype/Lato-Italic.ttf $out
cp $fonts/share/fonts/truetype/Lato-Bold.ttf $out
cp $fonts/share/fonts/truetype/Lato-Regular.ttf $out
cp $fonts/share/fonts/truetype/Inconsolata-Regular.ttf $out
cp $fonts/share/fonts/truetype/Inconsolata-Bold.ttf $out
";
};
jqueryMin = pkgs.fetchurl {
url = "https://code.jquery.com/jquery-2.2.3.min.js";
sha256 = "16hh52338jahcjk1pppmagqr7gxvsgmlgnry78cd2xkqvgaf0vbb";
};
bootswatch = pkgs.fetchzip {
url = "https://github.com/thomaspark/bootswatch/archive/v3.3.6+1.zip";
sha256 = "1d2pdxk5zavs6v9am4gv3im19x9mra19cc6xipb7qnwab1wqmb1d";
};
highlightjs = pkgs.fetchzip {
url = "https://github.com/isagalaev/highlight.js/archive/9.3.0.zip";
sha256 = "1m53mrfx59hiz6kbl6d3vczhxxqca8l2jx5qx2ndi4l8wwkf75nd";
};
fontAwesome = pkgs.fetchzip {
url = "https://github.com/FortAwesome/Font-Awesome/archive/v4.6.1.zip";
sha256 = "0iw5xzsmj04yzhf8kwav7wy7izvjnnqxzlmn38vp4nhnwr2av4cg";
};
bootstrap = pkgs.stdenv.mkDerivation {
inherit bootswatch bootstrapDist highlightjs nodeModules fontAwesome googleFonts nodejs;
name = "bootstrap";
staticCss = _site/static/static.css;
fontsCss = _site/static/fonts.css;
buildInputs = [nodeModules nodejs];
builder = builtins.toFile "builder.sh" "
source $stdenv/setup
mkdir $out
cp -R $bootstrapDist/js $out/js
mkdir $out/css
mkdir $out/fonts
cp -R $googleFonts/* $out/fonts
cp $fontAwesome/fonts/fontawesome-webfont.ttf $out/fonts
touch everything.css
cat $bootswatch/flatly/bootstrap.css | sed '/googleapis/d' > everything.css
cat $highlightjs/src/styles/default.css >> everything.css
cat $staticCss >> everything.css
# Make the css safe to mix with other css
namespace-css everything.css -s .bs >> everything-safe.css
sed -i.bak 's/\\.bs\\ body/\\.bs,\\ \\.bs\\ body/g' everything-safe.css
# @font-face shouldn't be namespaced
cat $fontsCss >> everything-safe.css
cat $fontAwesome/css/font-awesome.css >> everything-safe.css
cp everything-safe.css $out/css/bootstrap.css
cleancss $out/css/bootstrap.css > $out/css/bootstrap.min.css
";
};
specLegacy = zip2dir ./_site/archive/spec-old.zip;
site = pkgs.stdenv.mkDerivation {
name = "site";
staticDir = ./_site/static;
buildInputs = [pkgs.unzip nodejs];
specLegacy = zip2dir ./_site/archive/spec-old.zip;
spec00 = rfc2html (xml2rfc ./_spec/draft-00.xml);
spec01 = rfc2html (xml2rfc ./_spec/draft-01.xml);
spec02 = rfc2html (xml2rfc ./_spec/draft-02.xml);
spec03 = rfc2html (xml2rfc ./_spec/draft-03.xml);
spec04 = rfc2html (xml2rfc ./_spec/draft-04.xml);
builder = builtins.toFile "builder.sh" ''
source $stdenv/setup
PATH=$nodeBuilder/bin:$PATH
echo $(pwd)
mkdir -p static
cp -R $staticDir/* static
cp $jqueryMin static/jquery.min.js
cp -R $bootstrap static/bootstrap
node $nodeBuilder/index.js > index.html
node $nodeBuilder/inject.js index.html --navbar '/' --bs --highlight
mkdir spec
cp -R --no-preserve=mode $specLegacy/spec-old spec/1.0
node $nodeBuilder/inject.js spec/1.0/index.html --navbar 'spec/1.0' --bs
mkdir -p spec/draft-00
cat $spec00 > spec/draft-00/index.html
node $nodeBuilder/inject.js spec/draft-00/index.html --navbar 'spec/draft-00' --bs
mkdir -p spec/draft-01
cat $spec01 > spec/draft-01/index.html
node $nodeBuilder/inject.js spec/draft-01/index.html --navbar 'spec/draft-01' --bs
mkdir -p spec/draft-02
cat $spec02 > spec/draft-02/index.html
node $nodeBuilder/inject.js spec/draft-02/index.html --navbar 'spec/draft-02' --bs
mkdir -p spec/draft-03
cat $spec03 > spec/draft-03/index.html
node $nodeBuilder/inject.js spec/draft-03/index.html --navbar 'spec/draft-03' --bs
mkdir -p spec/draft-04
cat $spec04 > spec/draft-04/index.html
node $nodeBuilder/inject.js spec/draft-04/index.html --navbar 'spec/draft-04' --bs
mkdir python
cp -R --no-preserve=mode $pythonDocs02 python/0.2
cp -R --no-preserve=mode $pythonDocs03 python/0.3
cp -R --no-preserve=mode $pythonDocs04 python/0.4
mkdir -p $out
cp -R . $out
'';
inherit nodejs;
inherit bootstrap;
inherit jqueryMin;
inherit nodeBuilder;
inherit pythonDocs02;
inherit pythonDocs03;
inherit pythonDocs04;
};
siteGA = inject {
htmlTree = site;
opts = "--analytics";
};
deploySite = pkgs.stdenv.mkDerivation {
name = "deploy";
buildInputs = [site nodeModules nodejs];
# nix-build -A site
# aws s3 sync result s3://www.teleport-json.org
builder = builtins.toFile "builder.sh" ''
source $stdenv/setup
touch $out
'';
inherit site;
};
}