1{
2 description = "site";
3
4 inputs = {
5 nixpkgs.url = "github:nixos/nixpkgs";
6 vite.url = "github:icyphox/go-vite";
7 inter-fonts-src = {
8 url = "https://github.com/rsms/inter/releases/download/v4.1/Inter-4.1.zip";
9 flake = false;
10 };
11 ibm-plex-mono-src = {
12 url = "https://github.com/IBM/plex/releases/download/%40ibm%2Fplex-mono%401.1.0/ibm-plex-mono.zip";
13 flake = false;
14 };
15 };
16
17 outputs =
18 { self
19 , nixpkgs
20 , vite
21 , inter-fonts-src
22 , ibm-plex-mono-src
23 }:
24 let
25 supportedSystems = [
26 "x86_64-linux"
27 "x86_64-darwin"
28 "aarch64-linux"
29 "aarch64-darwin"
30 ];
31 forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
32 nixpkgsFor = forAllSystems (system: import nixpkgs { inherit system; });
33 in
34 {
35 devShells = forAllSystems (
36 system:
37 let
38 pkgs = nixpkgsFor.${system};
39 in
40 {
41 default = pkgs.mkShell {
42 buildInputs = [
43 vite.packages.${system}.vite
44 pkgs.gotools
45 pkgs.gnumake
46 pkgs.entr
47 pkgs.tailwindcss
48 ];
49 shellHook = ''
50 cp -f ${inter-fonts-src}/web/InterVariable*.woff2 static/fonts/
51 cp -f ${inter-fonts-src}/web/InterDisplay*.woff2 static/fonts/
52 cp -f ${ibm-plex-mono-src}/fonts/complete/woff2/IBMPlexMono-Regular.woff2 static/fonts/
53 '';
54 };
55 }
56 );
57
58 apps = forAllSystems (
59 system:
60 let
61 pkgs = nixpkgsFor.${system};
62 in
63 {
64 default = {
65 type = "app";
66 program = "${pkgs.writeShellScriptBin "vite-build" ''
67 #!/usr/bin/env bash
68 ${vite.packages.${system}.vite}/bin/vite build
69 ''}/bin/vite-build";
70 cwd = ./.;
71 };
72 serve = {
73 type = "app";
74 program = "${pkgs.writeShellScriptBin "vite-serve" ''
75 #!/usr/bin/env bash
76
77 kill_vite() {
78 trap SIGINT
79 echo "cleaning up..."
80 pkill vite
81 exit
82 }
83 trap "kill_vite" INT
84
85 ${vite.packages.${system}.vite}/bin/vite serve &
86 find pages/ static/ templates/ | ${pkgs.entr}/bin/entr ${vite.packages.${system}.vite}/bin/vite build --drafts
87 ''}/bin/vite-serve";
88 };
89 deploy = {
90 type = "app";
91 program = "${pkgs.writeShellScriptBin "deploy" ''
92 #!/usr/bin/env bash
93 ${vite.packages.${system}.vite}/bin/vite build
94 ${pkgs.wrangler}/bin/wrangler pages deploy --project-name tangled-blog ./build
95 ''}/bin/deploy";
96 };
97 }
98 );
99 };
100}