Skip to content

Commit e5540bf

Browse files
authored
Nix flake build static with sqlite support (#35149) (#35225)
Backport #35149 with `nix develop -c $SHELL` you can enter the dev environment. now with `make clean-all generate build -j1` you will get a static linked binary that has sqlite support outside of an nix dev shell if you set `STATIC=true` you also will get a static binary
1 parent d22d6ca commit e5540bf

File tree

2 files changed

+51
-25
lines changed

2 files changed

+51
-25
lines changed

Makefile

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,17 @@ ifeq ($(HAS_GO), yes)
4747
CGO_CFLAGS ?= $(shell $(GO) env CGO_CFLAGS) $(CGO_EXTRA_CFLAGS)
4848
endif
4949

50+
CGO_ENABLED ?= 0
51+
ifneq (,$(findstring sqlite,$(TAGS))$(findstring pam,$(TAGS)))
52+
CGO_ENABLED = 1
53+
endif
54+
55+
STATIC ?=
56+
EXTLDFLAGS ?=
57+
ifneq ($(STATIC),)
58+
EXTLDFLAGS = -extldflags "-static"
59+
endif
60+
5061
ifeq ($(GOOS),windows)
5162
IS_WINDOWS := yes
5263
else ifeq ($(patsubst Windows%,Windows,$(OS)),Windows)
@@ -740,7 +751,10 @@ security-check:
740751
go run $(GOVULNCHECK_PACKAGE) -show color ./...
741752

742753
$(EXECUTABLE): $(GO_SOURCES) $(TAGS_PREREQ)
743-
CGO_CFLAGS="$(CGO_CFLAGS)" $(GO) build $(GOFLAGS) $(EXTRA_GOFLAGS) -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)' -o $@
754+
ifneq ($(and $(STATIC),$(findstring pam,$(TAGS))),)
755+
$(error pam support set via TAGS doesn't support static builds)
756+
endif
757+
CGO_ENABLED="$(CGO_ENABLED)" CGO_CFLAGS="$(CGO_CFLAGS)" $(GO) build $(GOFLAGS) $(EXTRA_GOFLAGS) -tags '$(TAGS)' -ldflags '-s -w $(EXTLDFLAGS) $(LDFLAGS)' -o $@
744758

745759
.PHONY: release
746760
release: frontend generate release-windows release-linux release-darwin release-freebsd release-copy release-compress vendor release-sources release-check

flake.nix

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,33 +11,45 @@
1111
pkgs = nixpkgs.legacyPackages.${system};
1212
in
1313
{
14-
devShells.default = pkgs.mkShell {
15-
buildInputs = with pkgs; [
16-
# generic
17-
git
18-
git-lfs
19-
gnumake
20-
gnused
21-
gnutar
22-
gzip
14+
devShells.default =
15+
with pkgs;
16+
let
17+
# only bump toolchain versions here
18+
go = go_1_24;
19+
nodejs = nodejs_24;
20+
python3 = python312;
21+
in
22+
pkgs.mkShell {
23+
buildInputs = [
24+
# generic
25+
git
26+
git-lfs
27+
gnumake
28+
gnused
29+
gnutar
30+
gzip
2331

24-
# frontend
25-
nodejs_22
32+
# frontend
33+
nodejs
2634

27-
# linting
28-
python312
29-
poetry
35+
# linting
36+
python3
37+
poetry
3038

31-
# backend
32-
go_1_24
33-
gofumpt
34-
sqlite
35-
];
36-
shellHook = ''
37-
export GO="${pkgs.go_1_24}/bin/go"
38-
export GOROOT="${pkgs.go_1_24}/share/go"
39-
'';
40-
};
39+
# backend
40+
go
41+
glibc.static
42+
gofumpt
43+
sqlite
44+
];
45+
CFLAGS = "-I${glibc.static.dev}/include";
46+
LDFLAGS = "-L ${glibc.static}/lib";
47+
GO = "${go}/bin/go";
48+
GOROOT = "${go}/share/go";
49+
50+
TAGS = "sqlite sqlite_unlock_notify";
51+
STATIC = "true";
52+
};
4153
}
4254
);
4355
}

0 commit comments

Comments
 (0)