-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
124 lines (119 loc) · 3.65 KB
/
flake.nix
File metadata and controls
124 lines (119 loc) · 3.65 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
{
description = "msgtausch: Go proxy with Docker/Nix support";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05";
flake-utils.url = "github:numtide/flake-utils";
};
outputs =
{
self,
nixpkgs,
flake-utils,
}:
let
# Custom templ package with exact version
buildTemplPkg = { pkgs }: pkgs.buildGo124Module {
pname = "templ";
version = "0.3.906";
src = pkgs.fetchFromGitHub {
owner = "a-h";
repo = "templ";
rev = "v0.3.906";
hash = "sha256-Og1FPCEkBnyt1nz45imDiDNZ4CuWSJJPxGYcPzRgBE8=";
};
vendorHash = "sha256-oObzlisjvS9LeMYh3DzP+l7rgqBo9bQcbNjKCUJ8rcY=";
subPackages = [ "cmd/templ" ];
go = pkgs.go_1_24;
};
# Shared msgtausch package definition
buildMsgtauschPkg = { pkgs, version ? "dev", src ? pkgs.lib.cleanSource ./. }:
let
customTempl = buildTemplPkg { inherit pkgs; };
in
pkgs.buildGo124Module {
pname = "msgtausch";
inherit version src;
go = pkgs.go_1_24;
goVersion = "1.24";
# Let the builder vendor dependencies internally, but ignore any in-tree vendor/
vendorHash = "sha256-aoB6rkjiATKoEP+aZ+2lMBdniFjkrLwHeN0ntKsNi7Y=";
stripVendor = true;
subPackages = [ "." ];
env.CGO_ENABLED = 1;
nativeBuildInputs = [ pkgs.installShellFiles pkgs.git customTempl ];
ldflags = [
"-X main.version=${version} -s -w"
];
doCheck = false;
outputs = [ "out" ];
preBuild = ''
# Generate templates using the nixpkgs templ package
templ generate
'';
postInstall = ''
mkdir -p $out/bin
mv $GOPATH/bin/msgtausch $out/bin/
'';
};
in
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = import nixpkgs { inherit system; };
gopkgs = (import nixpkgs { inherit system; }).go_1_24;
goVersion = "1.24";
version =
let
v = builtins.getEnv "VERSION";
in
if v == "" then "dev" else v;
src = pkgs.lib.cleanSource ./.;
in
{
packages.default = buildMsgtauschPkg { inherit pkgs version src; };
packages.msgtausch = buildMsgtauschPkg { inherit pkgs version src; };
packages.templ = buildTemplPkg { inherit pkgs; };
devShells.default = pkgs.mkShell {
buildInputs = [
gopkgs
pkgs.docker
pkgs.git
pkgs.gnumake
pkgs.gotools
];
shellHook = ''
export CGO_ENABLED=1
export GOFLAGS="-mod=mod"
export VERSION=${version}
echo "msgtausch devShell: Go ${gopkgs.version} | VERSION=${version} | GOFLAGS=$GOFLAGS"
'';
};
# Run tests: nix build .#test
packages.test = pkgs.stdenv.mkDerivation {
name = "msgtausch-tests";
src = src;
buildInputs = [
gopkgs
pkgs.git
];
buildPhase = ''
export GOFLAGS="-mod=mod"
${gopkgs}/bin/go test -v ./...
'';
installPhase = ''
mkdir -p $out
touch $out/tests-done
'';
};
}
) // {
# Define the overlay at the top level
overlays.default = final: prev: {
msgtausch = buildMsgtauschPkg {
pkgs = prev;
version = let v = builtins.getEnv "VERSION"; in if v == "" then "dev" else v;
src = prev.lib.cleanSource ./.;
};
};
};
}