Go
Go is a statically-typed language with syntax loosely derived from that of C, adding garbage collected memory management, type safety, some dynamic-typing capabilities, additional built-in types such as variable-length arrays and key-value maps, and a large standard library.
Compile go program with static compile flags
If go build -ldflags "-s -w -linkmode external -extldflags -static"
fails on NixOS, with the error message cannot find
-lpthreadand
cannot find -lc` - it is because the linker cannot find static glibc to link with. You need to have glibc.static in your environment (and have CFLAGS/LDFLAGS adjusted accordingly).
One way to achieve this is to have something like the following as shell.nix
and run the compilation in a nix-shell:
with import <nixpkgs> {}; {
devEnv = stdenv.mkDerivation {
name = "dev";
buildInputs = [ stdenv git go glibc.static ];
CFLAGS="-I${pkgs.glibc.dev}/include";
LDFLAGS="-L${pkgs.glibc}/lib";
};
}