forked from NixOS/nixos-summer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
186 lines (181 loc) · 6.82 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
182
183
184
185
186
{
description = "A very basic flake";
inputs.nixpkgs = { url = "nixpkgs/nixos-unstable"; };
inputs.nixos-common-styles = { url = "github:NixOS/nixos-common-styles"; };
outputs =
{ self
, nixpkgs
, nixos-common-styles
}:
let
system = "x86_64-linux";
pkgs = import nixpkgs { inherit system; };
pages =
[
{
path = "index.html";
}
];
mkPage =
{ path
, title ? null
, body ? null
}:
let
titleFinal =
if title == null
then "Nix Camp"
else "Nix Camp - ${title}";
bodyFinal =
if body == null
then builtins.readFile (self + "/" + path)
else body;
mkHeaderLink =
{ href
, title
, class ? ""
}:
''
<li class="${class}">
<a href="${href}">${title}</a>
</li>
'';
in
pkgs.writeText "${builtins.baseNameOf path}"
''
<!doctype html>
<html lang="en" class="without-js">
<head>
<title>${titleFinal}</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0" />
<link rel="stylesheet" href="/styles/index.css" type="text/css" />
<link rel="shortcut icon" type="image/png" href="/favicon.png" />
<script>
var html = document.documentElement;
html.className = html.className.replace("without-js", "with-js");
</script>
</head>
<body>
<main>
${bodyFinal}
</main>
<footer>
<div>
<div class="lower">
<section class="footer-copyright">
<h4>NixOS</h4>
<div>
<span>
Copyright © 2024 Nix Camp Organizers
</span>
<a href="https://github.com/nix-how/nix.camp/blob/main/LICENSE.txt">
<abbr title="Creative Commons Attribution Share Alike 4.0 International">
CC-BY-SA-4.0
</abbr>
</a>
</div>
</section>
<section class="footer-social">
<h4>Connect with us</h4>
<ul>
<li class="social-icon -twitter"><a href="https://twitter.com/nix_camp">Twitter</a></li>
<li class="social-icon -github"><a href="https://github.com/nix-how">GitHub</a></li>
</ul>
</section>
</div>
</div>
</footer>
<script type="text/javascript" src="/js/jquery.min.js"></script>
<script type="text/javascript" src="/js/index.js"></script>
</body>
</html>
'';
buildPage = page:
''
echo " -> /${page.path}"
mkdir -p ${builtins.dirOf page.path}
ln -s ${mkPage page} ${page.path}
'';
mkWebsite = { shell ? false }:
pkgs.stdenv.mkDerivation {
name = "nixos-summer-${self.lastModifiedDate}";
src = self;
preferLocalBuild = true;
enableParallelBuilding = true;
buildInputs = with pkgs; [
imagemagick
nodePackages.less
];
buildPhase = ''
mkdir -p ./output
pushd ./output
echo "Generating pages:"
${builtins.concatStringsSep "\n" (builtins.map buildPage pages)}
popd
cp -R images ./output/images
mkdir -p ./output/styles
rm -f styles/common-styles
ln -s ${nixos-common-styles.packages."${system}".commonStyles} styles/common-styles
echo "Generating styles:"
echo " -> /styles/index.css"
lessc --verbose \
--source-map=styles/index.css.map \
styles/index.less \
./output/styles/index.css
mkdir -p ./output/styles/fonts
for font in styles/common-styles/fonts/*.ttf; do
echo " -> /styles/fonts/`basename $font`"
cp $font ./output/styles/fonts/
done
mkdir -p ./output/js
for jsscript in js/*.js; do
echo " -> /js/`basename $jsscript`"
cp $jsscript ./output/js/
done
echo " -> /favicon.png"
convert \
-resize 16x16 \
-background none \
-gravity center \
-extent 16x16 \
images/logo.png \
./output/favicon.png
echo " -> /favicon.ico"
convert \
-resize x16 \
-gravity center \
-crop 16x16+0+0 \
-flatten \
-colors 256 \
-background transparent \
./output/favicon.png \
./output/favicon.ico
'';
installPhase = ''
mkdir -p $out
cp -R ./output/* $out/
'';
shellHook = ''
rm -f styles/common-styles
ln -s ${nixos-common-styles.packages."${system}".commonStyles} styles/common-styles
'';
};
mkPyScript = dependencies: name:
let
pythonEnv = pkgs.python3.buildEnv.override {
extraLibs = dependencies;
};
in
pkgs.writeShellScriptBin name ''exec "${pythonEnv}/bin/python" "${toString ./.}/scripts/${name}.py" "$@"'';
in
{
packages."${system}" = {
nixos-summer = mkWebsite {};
nixos-summer-serve = mkPyScript (with pkgs.python3Packages; [ click livereload ]) "serve";
};
defaultPackage."${system}" = self.packages."${system}".nixos-summer;
devPackage."${system}" = mkWebsite { shell = true; };
};
}