Skip to content

Instantly share code, notes, and snippets.

@lobre
Last active June 23, 2020 19:11
Show Gist options
  • Save lobre/7d9a0613a728668083d89e790e094d1f to your computer and use it in GitHub Desktop.
Save lobre/7d9a0613a728668083d89e790e094d1f to your computer and use it in GitHub Desktop.
How to nix-shell for Go projects
# Example with go modules fetched by
# nix and linked to the vendor directory
# when entering the shell.
with import <nixpkgs> {};
buildGoModule {
pname = "example";
version = "0.0.1";
src = ./.;
vendorSha256 = lib.fakeSha256; # to change at first build
shellHook = ''
eval "$configurePhase"
'';
}
# Simple example with only go as dependency.
# To avoid writing in $HOME/go, we define
# the $GOPATH in a temporary location.
with import <nixpkgs> {};
mkShell {
buildInputs = [ go ];
shellHook = ''
export GOCACHE=$TMPDIR/go-cache
export GOPATH="$TMPDIR/go"
'';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment