chore: use nix-shell for CGO-dependent Makefile targets

Wrap test, lint, and build targets with nix-shell to provide
pkg-config, vips, libheif, and golangci-lint automatically.
This commit is contained in:
Jeffrey Paul 2026-02-25 20:08:04 +07:00
parent ce6db7627d
commit 429926fb71

View File

@ -3,6 +3,9 @@
VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
LDFLAGS := -X main.Version=$(VERSION)
# nix-shell wrapper for targets that need CGO dependencies (libvips, pkg-config)
NIX_SHELL := nix-shell -p pkg-config vips libheif golangci-lint git --run
# Default target: run all checks
check: fmt-check lint test
@ -19,19 +22,17 @@ fmt:
# Run linter
lint:
@echo "Running linter..."
golangci-lint run
$(NIX_SHELL) "golangci-lint run"
# Run tests (30-second timeout)
test:
@echo "Running tests..."
go test -timeout 30s -v ./...
$(NIX_SHELL) "CGO_ENABLED=1 go test -timeout 30s -v ./..."
# Build the binary
build: ./bin/pixad
./bin/pixad: ./internal/*/*.go ./cmd/pixad/*.go ./internal/static/* ./internal/templates/*
build:
@echo "Building pixad..."
go build -ldflags "$(LDFLAGS)" -o $@ ./cmd/pixad
$(NIX_SHELL) "CGO_ENABLED=1 go build -ldflags '$(LDFLAGS)' -o ./bin/pixad ./cmd/pixad"
# Clean build artifacts
clean:
@ -62,6 +63,5 @@ devserver-stop:
# Install pre-commit hook
hooks:
@printf '#!/bin/sh\nset -e\n' > .git/hooks/pre-commit
@printf 'go mod tidy\ngo fmt ./...\ngit diff --exit-code -- go.mod go.sum || { echo "go mod tidy changed files; please stage and retry"; exit 1; }\n' >> .git/hooks/pre-commit
@printf 'make check\n' >> .git/hooks/pre-commit
@chmod +x .git/hooks/pre-commit