/
flake.nix
130 lines (111 loc) · 4.19 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
{
description = "bytes.zone website";
inputs = {
flake-utils.url = "github:numtide/flake-utils";
nixpkgs.url = "github:NixOS/nixpkgs/release-22.11";
};
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let pkgs = nixpkgs.legacyPackages.${system};
in rec {
# `nix build`
packages.bytes-zone-public = pkgs.stdenv.mkDerivation {
name = "bytes.zone-public";
src = builtins.filterSource
(path: type: builtins.match ".+(png|css|js)$" path == null) ./.;
buildInputs = [ pkgs.zola pkgs.nodePackages.html-minifier ];
buildPhase = ''
zola build
echo "compressing HTML"
html-minifier \
--collapse-whitespace \
--decode-entities \
--remove-comments \
--remove-attribute-quotes \
--remove-redundant-attributes \
--remove-optional-tags \
--remove-script-type-attributes \
--remove-style-link-type-attributes \
--file-ext html \
--input-dir public \
--output-dir public
'';
installPhase = ''
mkdir -p $out/share
mv public $out/share/bytes.zone
'';
};
packages.bytes-zone-css = pkgs.stdenv.mkDerivation {
name = "bytes.zone-css";
src = builtins.filterSource (path: type:
type == "directory" || builtins.match ".+css$" path != null)
./static;
buildInputs = [ pkgs.nodePackages.clean-css-cli ];
buildPhase = ''
for file in $(find . -type f -name '*.css'); do
cleancss -O 1 -o $file.min $file
printf '%s: %db -> %db\n' "$file" "$(wc -c $file | cut -d ' ' -f 1)" "$(wc -c $file.min | cut -d ' ' -f 1)"
mv $file.min $file
done
'';
installPhase = ''
mkdir -p $out/share/bytes.zone
for file in $(find . -type f); do
mkdir -p $out/share/bytes.zone/$(dirname $file)
mv $file $out/share/bytes.zone/$file
done
'';
};
packages.bytes-zone-js = pkgs.stdenv.mkDerivation {
name = "bytes.zone-js";
src = builtins.filterSource (path: type:
type == "directory" || builtins.match ".+js$" path != null)
./static;
buildInputs = [ pkgs.nodePackages.uglify-js ];
buildPhase = ''
for file in $(find . -type f -name '*.js'); do
uglifyjs -o $file.min $file
printf '%s: %db -> %db\n' "$file" "$(wc -c $file | cut -d ' ' -f 1)" "$(wc -c $file.min | cut -d ' ' -f 1)"
mv $file.min $file
done
'';
installPhase = ''
mkdir -p $out/share/bytes.zone
for file in $(find . -type f); do
mkdir -p $out/share/bytes.zone/$(dirname $file)
mv $file $out/share/bytes.zone/$file
done
'';
};
packages.bytes-zone-pngs = pkgs.stdenv.mkDerivation {
name = "bytes.zone-pngs";
src = builtins.filterSource (path: type:
type == "directory" || builtins.match ".+png$" path != null)
./static;
buildInputs = [ pkgs.pngcrush ];
buildPhase = ''
find . -type f -name '*.png' | xargs -n 1 pngcrush -ow -brute
'';
installPhase = ''
mkdir -p $out/share/bytes.zone
for file in $(find . -type f); do
mkdir -p $out/share/bytes.zone/$(dirname $file)
mv $file $out/share/bytes.zone/$file
done
'';
};
packages.bytes-zone = pkgs.symlinkJoin {
name = "bytes.zone";
paths = [
packages.bytes-zone-css
packages.bytes-zone-js
packages.bytes-zone-pngs
packages.bytes-zone-public
];
};
defaultPackage = packages.bytes-zone;
overlay = final: prev: { bytes-zone = packages.bytes-zone; };
# `nix develop`
devShell = pkgs.mkShell { buildInputs = with pkgs; [ zola pngcrush ]; };
});
}