/
flake.nix
69 lines (60 loc) · 2.04 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
{
description = "bytes.zone website";
inputs = {
flake-utils.url = "github:numtide/flake-utils";
nixpkgs.url = "github:NixOS/nixpkgs/release-22.05";
};
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let pkgs = nixpkgs.legacyPackages.${system};
in rec {
# `nix build`
packages.bytes-zone = pkgs.stdenv.mkDerivation {
name = "bytes.zone";
src = ./.;
buildInputs = [
pkgs.zola
pkgs.nodePackages.html-minifier
pkgs.nodePackages.clean-css-cli
pkgs.nodePackages.uglify-js
pkgs.pngcrush
];
buildPhase = ''
zola build
echo "compressing CSS"
find public \
-type f -name '*.css' \
-exec cleancss -O 1 -o {}.min {} \; \
-exec mv {}.min {} \;
echo "compressing JS"
find public \
-type f -name '*.js' \
-exec uglifyjs -o {}.min {} \; \
-exec mv {}.min {} \;
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
echo "compressing images"
find public -type f -name '*.png' | xargs -n 1 pngcrush -ow -brute
'';
installPhase = ''
mkdir -p $out/share
mv public $out/share/bytes.zone
'';
};
defaultPackage = packages.bytes-zone;
overlay = final: prev: { bytes-zone = packages.bytes-zone; };
# `nix develop`
devShell = pkgs.mkShell { buildInputs = with pkgs; [ zola pngcrush ]; };
});
}