-
Notifications
You must be signed in to change notification settings - Fork 1
/
default.nix
63 lines (48 loc) · 1.29 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
{ pkgs ? import <nixpkgs> { }
}:
with pkgs;
stdenv.mkDerivation rec {
pname = "thesis-template";
version = "0.0.0";
src = ./.;
buildInputs = [
python3
asciidoctor-web-pdf
asciidoctor-js
sass
gnumake
nixpkgs-fmt
nil
jq
];
buildPhase = ''
mkdir -p styles
mkdir -p images
make index.html
'';
installPhase = ''
mkdir -p $out
cp -r *.html *.css images $out
# cp thesis.pdf $out
mkdir -p $out/bin
cat <<EOF > $out/bin/${pname}.py
#!/usr/bin/env python3
import http.server
DIRECTORY = "$out"
class MyHTTPRequestHandler(http.server.SimpleHTTPRequestHandler):
def __init__(self, *args, **kwargs):
super().__init__(*args, directory=DIRECTORY, **kwargs)
def end_headers(self):
self.send_my_headers()
http.server.SimpleHTTPRequestHandler.end_headers(self)
def send_my_headers(self):
self.send_header("Cache-Control", "no-cache, no-store, must-revalidate")
self.send_header("Pragma", "no-cache")
self.send_header("Expires", "0")
if __name__ == '__main__':
http.server.test(HandlerClass=MyHTTPRequestHandler)
EOF
chmod a+x $out/bin/${pname}.py
'';
meta.mainProgram = "${pname}.py";
}