-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
214 lines (203 loc) · 6.33 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
{
inputs = {
devenv = {
url = "github:cachix/devenv";
inputs.nixpkgs.follows = "nixpkgs";
};
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
treefmt = {
url = "github:numtide/treefmt-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
nixConfig = {
extra-substituters = [
"https://tendrelhq.cachix.org"
];
extra-trusted-public-keys = [
"tendrelhq.cachix.org-1:uAnm9wwXD60bKJbPuDgpVMxcAje1IqhKoroTi4iX608="
];
};
outputs = {flake-parts, ...} @ inputs:
flake-parts.lib.mkFlake {inherit inputs;} {
imports = [
inputs.devenv.flakeModule
inputs.treefmt.flakeModule
];
systems = ["x86_64-linux"];
perSystem = {
config,
lib,
pkgs,
self',
...
}: {
devShells.ci = pkgs.mkShellNoCC {
name = "tendrel-graphql/ci";
buildInputs = [pkgs.bun config.packages.treefmt];
# Environment variables:
TREEFMT = "treefmt";
};
devenv.shells.default = {
name = "tendrel-graphql";
containers = lib.mkForce {};
env = {
BIOME_BINARY = lib.getExe config.packages.biome;
# TODO: switch to dev, but I need to get a self contained test
# environment up and running first :/
PGDATABASE = "postgres";
# Janky af I know, but an easy way to silently fail successfully
TREEFMT = "treefmt";
};
packages = with pkgs;
with config.packages; [
act
awscli2
biome
bun
copilot-cli
just
nodejs # required by biome's entrypoint
perlPackages.TAPParserSourceHandlerpgTAP # pg_prove
python3.pkgs.sqlfmt
postgres
sqitchPg
squawk
treefmt
vtsls
];
pre-commit.hooks.treefmt = {
enable = true;
package = config.packages.treefmt;
};
processes = {
app.exec = "bun --inspect ./bin/app.ts";
iql.exec = "bunx ruru@beta -Pe http://localhost:4000";
};
services.postgres = {
enable = true;
extensions = exts:
with exts;
with config.packages; [
pg_cron
pgddl
pgtap
plpgsql_check
];
initialDatabases = [
{
name = "dev";
}
];
initialScript = ''
CREATE EXTENSION IF NOT EXISTS ddlx SCHEMA pg_catalog;
'';
listen_addresses = "127.0.0.1";
package = config.packages.postgres;
port = 5432;
settings = {
log_statement = "all";
logging_collector = false;
shared_preload_libraries = "pg_cron,plpgsql_check";
};
};
};
packages = {
biome = let
pkgJSON = lib.importJSON ./package.json;
in
pkgs.stdenv.mkDerivation rec {
pname = "biome";
version = let
v = pkgJSON.devDependencies."@biomejs/biome";
in "v${lib.strings.removePrefix "^" v}";
src = pkgs.fetchurl {
url = "https://github.com/biomejs/biome/releases/download/cli%2F${version}/biome-linux-x64";
hash = "sha256-ziR/tkSZnvUuURHdb9bkcQGWafycSkS1aZch45twMsM=";
};
nativeBuildInputs = [pkgs.autoPatchelfHook];
buildInputs = [pkgs.stdenv.cc.cc.libgcc];
dontUnpack = true;
installPhase = ''
install -D -m755 $src $out/bin/biome
'';
meta.mainProgram = "biome";
};
copilot-cli = pkgs.stdenv.mkDerivation rec {
pname = "copilot-cli";
version = "1.33.3";
src = pkgs.fetchurl {
url = "https://github.com/aws/copilot-cli/releases/download/v${version}/copilot-linux";
hash = "sha256-Igr6JQzy6C2F8tzAZwaCw3Gnkny+LtFogyvaZ8eKDhA=";
};
sourceRoot = ".";
nativeBuildInputs = with pkgs; [autoPatchelfHook];
dontUnpack = true;
dontBuild = true;
installPhase = ''
runHook preInstall
install -D -m755 $src $out/bin/copilot
runHook postInstall
'';
};
pgddl = pkgs.stdenv.mkDerivation rec {
name = "pgddl";
version = "0.28";
src = pkgs.fetchFromGitHub {
owner = "lacanoid";
repo = name;
rev = version;
hash = "sha256-SWAdb2hZusDGLtB240MH15XbUm2LI/Z335TZjZIjw/s=";
};
buildInputs = with pkgs; [perl config.packages.postgres];
postPatch = ''
patchShebangs .
'';
installPhase = ''
install -D -t $out/share/postgresql/extension *.sql
install -D -t $out/share/postgresql/extension *.control
'';
};
postgres = pkgs.postgresql_16;
treefmt = config.treefmt.build.wrapper;
};
treefmt.config = {
projectRootFile = "flake.nix";
programs = {
alejandra.enable = true;
biome = {
enable = true;
package = config.packages.biome;
includes = ["*.graphql" "*.json" "*.ts"];
};
prettier = {
enable = true;
includes = ["*.md" "*.yaml" "*.yml"];
};
};
settings = {
formatter = {
biome.options = lib.mkForce ["check" "--write"];
sqlfmt = {
command = lib.getExe pkgs.python3.pkgs.sqlfmt;
options = ["-"];
includes = ["*.sql"];
};
};
global.excludes = [
"*.conf"
"*.lockb"
"*.plan"
"*.snap"
"*.toml"
".*" # hidden files
"copilot/.workspace"
"Dockerfile"
"justfile"
"sql/manual-deploy.sql"
];
};
};
};
};
}