!QCCCSJHEsTIfozrZxz:nixos.org

Nix + Go

226 Members
Go packaging for and with Nixpkgs. | Be excellent to each other.50 Servers

Load older messages


SenderMessageTime
3 Jul 2025
@katexochen:matrix.orgPaul Meyer (katexochen)There is also a section in the manual on versioned builders: https://nixos.org/manual/nixpkgs/unstable/#ssec-go-toolchain-versions14:18:38
5 Jul 2025
@jsnf:matrix.orgjsnfAhhh got it, thank you so much!15:39:19
10 Jul 2025
@aerunakai:matrix.org@aerunakai:matrix.org joined the room.05:46:05
@nazarewk:matrix.orgkdnis there a way to build system-independent Go binaries on NixOS? I'm trying to build an Alpine container that requires passing the binary externally and getting those pesky file not founds19:08:33
@curid:matrix.orgCurid why not use a scratch base instead of alpine? 19:10:47
@nazarewk:matrix.orgkdn could probably design it around scratch some time in the future, but right now I need to create an entrypoint bash script for the app and that's it 19:12:08
@curid:matrix.orgCurid should be distro independent if you set CGO_ENABLE=0 19:14:08
@jrick:zettaport.comjricknot necessarily. enabling pie will still use the dynamic loader19:16:24
@jrick:zettaport.comjrickbut you can override the path to the dynamic loader, and force it to use the standard path to the musl one which will work on alpine19:17:07
@curid:matrix.orgCurid patchelf --set-interpreter "/lib64/ld-linux-x86-64.so.2" file 19:17:21
@jrick:zettaport.comjrickthere's that hack, but also there's a variable you can set in the go tooling19:17:38
@jrick:zettaport.comjrickdon't remember it exactly off top of my head, just that it exists19:17:52
@jrick:zettaport.comjrick go tool link -extld <path> 19:19:02
@jrick:zettaport.comjrickso, set that with ldflags19:19:11
@diamondburned:matrix.orgDiamond (it/she)CGO_ENABLED=0 definitely will work20:47:58
@diamondburned:matrix.orgDiamond (it/she)if your binary still has PIE then you have to fix your environment20:48:03
@diamondburned:matrix.orgDiamond (it/she) oh this is Nix, perfect! CGO_ENABLED=0 will work 20:48:39
@diamondburned:matrix.orgDiamond (it/she)i've done it before20:48:41
@jrick:zettaport.comjrickpie without cgo doesn't really work. static pie is a thing, but go doesn't produce those20:50:31
@jrick:zettaport.comjrickwell it can, but i haven't tried to cross compile them20:50:58
@jrick:zettaport.comjrickerr, i have tried, and failed lol20:51:54
@nazarewk:matrix.orgkdn yeah, CGO_ENABLED=0 go build works fine on NixOS 20:52:15
@diamondburned:matrix.orgDiamond (it/she)yeah for the explicit purpose of cross-building i wouldn't bother with PIE20:55:57
@diamondburned:matrix.orgDiamond (it/she)or i guess just build a Nix OCI container instead20:56:14
@jrick:zettaport.comjrickthe issue with building static pie executables is that you need the target platform's ld.so and essentially embed it into the final binary20:57:05
@jrick:zettaport.comjrickit works if you have the file and can set the appropriate go flags to link with it20:57:45
@jrick:zettaport.comjrickbut makes cross compiling a nightmare20:57:49
@nazarewk:matrix.orgkdnI'd love to, but the team uses goreleaser to build for few-teen targets including different architectures, containers & operating systems20:58:28
@diamondburned:matrix.orgDiamond (it/she)hm ic21:00:36
@nazarewk:matrix.orgkdnI just wanted to adjust my local build to whatever they're running so I can make a proper entrypoint21:01:08

Show newer messages


Back to Room ListRoom Version: 9