Repository navigation
Expand file tree
/
Copy pathflake.nix
More file actions
168 lines (141 loc) · 5.52 KB
/
Copy pathflake.nix
File metadata and controls
168 lines (141 loc) · 5.52 KB
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
{
description = "Reproducible Go dev environment with build and test support";
# ============================================================
# INPUTS
# ============================================================
inputs = rec {
nixpkgs-stable.url = "github:NixOS/nixpkgs/nixos-26.05";
nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixos-unstable";
nixpkgs = nixpkgs-unstable;
# ast-grep 0.51.2 is newer than both channel pins; keep it on its own input
# so an ordinary `nix flake update` does not move the guard's required tool.
nixpkgs-ast-grep.url = "github:NixOS/nixpkgs/34209e4f67c988d6a21b19f4ae37672fce52c7da";
flake-utils.url = "github:numtide/flake-utils";
};
# ============================================================
# OUTPUTS
# ============================================================
outputs =
inputs@{ self
, nixpkgs
, nixpkgs-stable
, nixpkgs-unstable
, nixpkgs-ast-grep
, flake-utils
, ...
}:
let
# ==========================================================
# PROJECT CONFIGURATION — edit this section for your project
# ==========================================================
# Package metadata
pname = "village";
version = "0.1.0";
# Go package attribute (e.g., go, go_1_24)
# Set to null to use the default Go version from nixpkgs
goAttr = null;
# Vendor hash for buildGoModule (run `nix build` once with
# lib.fakeHash to get the real hash from the error message)
vendorHash = null; # null = vendored in repo; otherwise sha256 string
# Extra CLI tools available in the dev shell
devTools = pkgs: with pkgs; [
gopls # LSP
gotools # goimports, godoc, etc.
go-tools # staticcheck
delve # debugger
golangci-lint # linter suite
sqlite # CLI for inspecting analytics store
nodejs_26 # Node.js runtime for frontend tooling
pnpm # frontend package manager and build tooling
util-linux # flock serializes production-browser builds and stale recovery
typescript
typescript-language-server
# protobuf # protoc
# protoc-gen-go # protobuf Go codegen
# temporal-cli # Temporal dev server
# tlaplus18 # TLC model checker
];
# Native build dependencies (C libraries, system packages)
# gcc is required for tree-sitter CGo bindings (github.com/tree-sitter/go-tree-sitter)
nativeBuildDeps = pkgs: with pkgs; [
gcc
# pkg-config
# openssl
# sqlite
];
# Extra check commands run during `nix build` after go test
extraCheckPhase = ''
# go vet ./...
# staticcheck ./...
'';
# Files to install alongside the binary (relative to src)
extraInstallPhase = ''
# mkdir -p $out/share/policies
# cp authz/policies/*.rego $out/share/policies/
'';
# ==========================================================
# IMPLEMENTATION — you shouldn't need to edit below here
# ==========================================================
mkOutputs = nixpkgs-channel:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs-channel {
inherit system;
config.allowUnfree = true;
};
astGrepPkgs = import nixpkgs-ast-grep { inherit system; };
ast-grep = assert astGrepPkgs.ast-grep.version == "0.51.2"; astGrepPkgs.ast-grep;
goPackage =
if goAttr != null
then pkgs.${goAttr}
else pkgs.go;
# ----------------------------------------------------------
# Build
# ----------------------------------------------------------
package = pkgs.buildGoModule {
inherit pname version;
src = ./.;
inherit vendorHash;
nativeBuildInputs = nativeBuildDeps pkgs;
checkPhase = ''
runHook preCheck
go test -race ./...
${extraCheckPhase}
runHook postCheck
'';
postInstall = extraInstallPhase;
# Apache-2.0, matching the committed LICENSE. This is nixpkgs' own
# `licenses.asl20` attrset (free = true), so the package needs no
# allowUnfree to build or install. Keep in sync with LICENSE.
meta = with pkgs.lib; {
homepage = "https://github.com/peasant-labs/village";
license = licenses.asl20;
};
};
# ----------------------------------------------------------
# Development Shell
# ----------------------------------------------------------
devShell = pkgs.mkShell {
name = "${pname}-dev";
inputsFrom = [ package ];
packages = (devTools pkgs) ++ [ ast-grep ];
shellHook = ''
echo "Go $(go version | cut -d' ' -f3) dev shell"
export CGO_ENABLED=1
if [[ -f .envrc.local ]]; then
source .envrc.local
fi
'';
};
in
{
packages.default = package;
packages.${pname} = package;
devShells.default = devShell;
# Quick check: nix flake check
checks.build = package;
}
);
in
mkOutputs nixpkgs;
}