Go on NixOS & FreeBSD

Beyond Linux: NixOS & FreeBSD

Go is famous for its cross-compilation support.

Cross Compilation

You can build a binary for ANY OS from your Mac.

# Build for Linux (AMD64)
GOOS=linux GOARCH=amd64 go build -o app-linux

# Build for FreeBSD (ARM64) - e.g., Raspberry Pi on FreeBSD
GOOS=freebsd GOARCH=arm64 go build -o app-bsd

# Build for Windows
GOOS=windows GOARCH=amd64 go build -o app.exe

Go on NixOS

NixOS is purely functional. You can’t just go build and expect it to run if you link against C libraries, because standard paths (/lib) don’t exist.

Pure Go

If you use CGO_ENABLED=0, your binary works perfectly on NixOS without modification. This is why Go devs love NixOS.

Development Environment (Flakes)

Use a flake.nix to define your dev shell. This guarantees that every developer on your team uses the exact same version of Go, gopls, and golangci-lint.

{
  inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
  outputs = { self, nixpkgs }:
    let pkgs = nixpkgs.legacyPackages.x86_64-linux;
    in {
      devShells.x86_64-linux.default = pkgs.mkShell {
        buildInputs = [ pkgs.go_1_26 pkgs.gopls ];
      };
    };
}

Go on FreeBSD

FreeBSD is a fantastic server OS (ZFS, Jails). Go treats it as a first-class citizen. * Performance: Go’s scheduler maps efficiently to FreeBSD kqueues. * Wait: fsnotify uses kqueue on BSD instead of inotify, which is efficient.

Note: If you use low-level networking code, verify if libraries support BSD. But the stdlib (net/http) works flawlessly.