Skip to content

Commit 5d6545c

Browse files
committed
chore(nix): add flake.nix to provide reproducible Go development environment
1 parent 31eaef6 commit 5d6545c

5 files changed

Lines changed: 221 additions & 0 deletions

File tree

.envrc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env bash
2+
# Automatically load the Nix development environment when entering this directory
3+
# Requires: direnv (https://direnv.net/)
4+
5+
if ! has nix_direnv_version || ! nix_direnv_version 3.0.4; then
6+
source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/3.0.4/direnvrc" "sha256-DzlYZ33mWF/Gs8DDeyjr8mnVmQGx7ASYqA5WlxwvBG4="
7+
fi
8+
9+
use flake

.gitattributes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Nix files
2+
*.nix linguist-language=Nix
3+
flake.lock linguist-generated=true

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,8 @@ bin
3333
# .idea/
3434
# .vscode/
3535
ai.md
36+
37+
# Nix
38+
result
39+
result-*
40+
.direnv/

flake.lock

Lines changed: 61 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
{
2+
description = "SQLens - High-performance multi-dialect SQL query analysis tool";
3+
4+
inputs = {
5+
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
6+
flake-utils.url = "github:numtide/flake-utils";
7+
};
8+
9+
outputs = { self, nixpkgs, flake-utils }:
10+
flake-utils.lib.eachDefaultSystem (system:
11+
let
12+
pkgs = nixpkgs.legacyPackages.${system};
13+
14+
# Package version
15+
version = "0.1.0";
16+
17+
in
18+
{
19+
# Development shell with all tools
20+
devShells.default = pkgs.mkShell {
21+
name = "sql-parser-go-dev";
22+
23+
buildInputs = with pkgs; [
24+
# Go toolchain (latest stable)
25+
go
26+
27+
# Go development tools
28+
gopls # Language server
29+
gotools # goimports, godoc, etc.
30+
go-tools # staticcheck, etc.
31+
golangci-lint # Linter
32+
delve # Debugger
33+
34+
# Build tools
35+
gnumake
36+
37+
# Optional: useful for benchmarking
38+
hyperfine
39+
];
40+
41+
shellHook = ''
42+
echo "🚀 SQL Parser Go - Development Environment"
43+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
44+
echo "Go version: $(go version)"
45+
echo ""
46+
echo "Available commands:"
47+
echo " make build - Build the project"
48+
echo " make test - Run tests"
49+
echo " make bench - Run benchmarks"
50+
echo " make lint - Run linter"
51+
echo " make fmt - Format code"
52+
echo ""
53+
echo "Run 'make help' for more commands"
54+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
55+
'';
56+
57+
# Environment variables
58+
CGO_ENABLED = "0";
59+
};
60+
61+
# Main package - sqlparser binary
62+
packages.default = pkgs.buildGoModule {
63+
pname = "sqlparser";
64+
inherit version;
65+
66+
src = ./.;
67+
68+
# This hash needs to be computed
69+
# Run: nix flake lock --update-input nixpkgs
70+
# Then: nix build
71+
# Copy the hash from the error message
72+
vendorHash = "sha256-u8ail0ExBVg1jdu1DW0J1HCFrtyh1C/rbN06qp1qyqY=";
73+
74+
# Build flags
75+
ldflags = [
76+
"-s"
77+
"-w"
78+
"-X main.version=${version}"
79+
];
80+
81+
# Run tests
82+
doCheck = true;
83+
checkPhase = ''
84+
runHook preCheck
85+
go test -v ./...
86+
runHook postCheck
87+
'';
88+
89+
meta = with pkgs.lib; {
90+
description = "High-performance SQL parser with multi-dialect support";
91+
homepage = "https://github.com/Chahine-tech/sql-parser-go";
92+
license = licenses.mit;
93+
maintainers = [ ];
94+
mainProgram = "sqlparser";
95+
};
96+
};
97+
98+
# Alias for the package
99+
packages.sqlparser = self.packages.${system}.default;
100+
101+
# Apps - make it easy to run
102+
apps.default = {
103+
type = "app";
104+
program = "${self.packages.${system}.default}/bin/sqlparser";
105+
};
106+
107+
# Checks - run tests with nix flake check
108+
checks = {
109+
# Run all tests
110+
tests = pkgs.runCommand "sql-parser-tests" {
111+
buildInputs = [ pkgs.go ];
112+
} ''
113+
cp -r ${./.}/* .
114+
chmod -R +w .
115+
export HOME=$TMPDIR
116+
go test -v ./tests
117+
touch $out
118+
'';
119+
120+
# Check formatting
121+
fmt-check = pkgs.runCommand "sql-parser-fmt-check" {
122+
buildInputs = [ pkgs.go ];
123+
} ''
124+
cp -r ${./.}/* .
125+
chmod -R +w .
126+
127+
# Check if code is formatted
128+
unformatted=$(gofmt -l .)
129+
if [ -n "$unformatted" ]; then
130+
echo "The following files are not formatted:"
131+
echo "$unformatted"
132+
exit 1
133+
fi
134+
135+
touch $out
136+
'';
137+
};
138+
139+
# Formatter for `nix fmt`
140+
formatter = pkgs.nixpkgs-fmt;
141+
}
142+
);
143+
}

0 commit comments

Comments
 (0)