84 lines
2.2 kB
1
{
2
description = "site";
3
4
inputs.nixpkgs.url = "github:nixos/nixpkgs";
5
inputs.vite.url = "github:icyphox/go-vite";
6
7
outputs =
8
{ self
9
, nixpkgs
10
, vite
11
,
12
}:
13
let
14
supportedSystems = [
15
"x86_64-linux"
16
"x86_64-darwin"
17
"aarch64-linux"
18
"aarch64-darwin"
19
];
20
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
21
nixpkgsFor = forAllSystems (system: import nixpkgs { inherit system; });
22
in
23
{
24
devShells = forAllSystems (
25
system:
26
let
27
pkgs = nixpkgsFor.${system};
28
in
29
{
30
default = pkgs.mkShell {
31
buildInputs = [
32
vite.packages.${system}.vite
33
pkgs.gotools
34
pkgs.gnumake
35
pkgs.entr
36
pkgs.awscli2
37
];
38
};
39
}
40
);
41
42
apps = forAllSystems (
43
system:
44
let
45
pkgs = nixpkgsFor.${system};
46
in
47
{
48
default = {
49
type = "app";
50
program = "${pkgs.writeShellScriptBin "vite-build" ''
51
#!/usr/bin/env bash
52
${vite.packages.${system}.vite}/bin/vite build
53
''}/bin/vite-build";
54
cwd = ./.;
55
};
56
deploy = {
57
type = "app";
58
program = "${pkgs.writeShellScriptBin "s3-sync" ''
59
#!/usr/bin/env bash
60
${vite.packages.${system}.vite}/bin/vite build
61
${pkgs.awscli2}/bin/aws s3 sync build s3://site/ --size-only
62
''}/bin/s3-sync";
63
};
64
serve = {
65
type = "app";
66
program = "${pkgs.writeShellScriptBin "vite-serve" ''
67
#!/usr/bin/env bash
68
69
kill_vite() {
70
trap SIGINT
71
echo "cleaning up..."
72
pkill vite
73
exit
74
}
75
trap "kill_vite" INT
76
77
${vite.packages.${system}.vite}/bin/vite serve &
78
find pages/ static/ templates/ | ${pkgs.entr}/bin/entr ${vite.packages.${system}.vite}/bin/vite build --drafts
79
''}/bin/vite-serve";
80
};
81
}
82
);
83
};
84
}
85