-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
101 lines (88 loc) · 3.13 KB
/
flake.nix
File metadata and controls
101 lines (88 loc) · 3.13 KB
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
{
description = "An empty flake template that you can adapt to your own environment";
# Flake inputs
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.11";
# Flake outputs
outputs =
{ self, ... }@inputs:
let
# The systems supported for this flake's outputs
supportedSystems = [
"x86_64-linux"
];
# Helper for providing system-specific attributes
forEachSupportedSystem =
f:
inputs.nixpkgs.lib.genAttrs supportedSystems (
system:
f {
inherit system;
# Provides a system-specific, configured Nixpkgs
pkgs = import inputs.nixpkgs {
inherit system;
# Enable using unfree packages
config.allowUnfree = true;
};
}
);
in
{
devShells = forEachSupportedSystem (
{ pkgs, system }:
{
default = pkgs.mkShellNoCC {
# The Nix packages provided in the environment
packages = with pkgs; [
self.formatter.${system}
nil
nixpkgs-fmt
caddy
];
env = { };
shellHook = "";
};
}
);
packages = forEachSupportedSystem (
{ pkgs, system }: rec {
default = www;
www = pkgs.stdenv.mkDerivation {
version = "0.0.1";
name = "www";
src = ./.;
buildInputs = [];
nativeBuildInputs = with pkgs; [ gzip brotli esbuild minhtml imagemagick ];
buildPhase = ''
mkdir -p $out/assets/images
mkdir -p $out/assets/css
# Images
cp -r assets/images $out/assets
mogrify -quality 8 -strip -resize 25x25 $out/assets/images/ceo.webp
# HTML
find . -name '*.html' -execdir minhtml --keep-closing-tags --minify-js --minify-css {} --output {} \;
find . -name '*.html' -execdir brotli --best {} -f \;
find . -name '*.html' -execdir gzip --best --keep {} -f \;
cp *.html* $out
cp -R about $out/
# CSS
esbuild ./assets/css/*.css --minify --outdir=$out/assets/css
find $out/assets/css -name '*.css' -execdir brotli --best {} -f \;
find $out/assets/css -name '*.css' -execdir gzip --best --keep {} -f \;
# # JS
# cp -r ./assets/scripts $out/assets
# find $out/assets/scripts -name '*.js' -execdir brotli --best {} -f \;
# find $out/assets/scripts -name '*.js' -execdir gzip --best --keep {} -f \;
'';
};
}
);
# Nix formatter
# This applies the formatter that follows RFC 166, which defines a standard format:
# https://github.com/NixOS/rfcs/pull/166
# To format all Nix files:
# git ls-files -z '*.nix' | xargs -0 -r nix fmt
# To check formatting:
# git ls-files -z '*.nix' | xargs -0 -r nix develop --command nixfmt --check
formatter = forEachSupportedSystem ({ pkgs, ... }: pkgs.nixfmt-rfc-style);
};
}