Skip to content

Instantly share code, notes, and snippets.

@LnL7
Last active July 31, 2017 11:12
Show Gist options
  • Save LnL7/d4fe689716f36bd84714afb1b2cd4bb4 to your computer and use it in GitHub Desktop.
Save LnL7/d4fe689716f36bd84714afb1b2cd4bb4 to your computer and use it in GitHub Desktop.
nix golang project exmaple
{ pkgs ? import <nixpkgs> {} }:
let
inherit (pkgs) stdenv buildEnv;
goPackages = buildEnv {
name = "go-packages";
paths =
[ # Dependencies...
];
};
in
stdenv.mkDerivation rec {
name = "foo-${version}";
version = "0.0.1";
src = ./.;
nativeBuildInputs = [ pkgs.go ];
buildPhase = ''
mkdir -p build/go/src/github.com/lnl7
ln -sfn ../../../../.. build/go/src/github.com/lnl7/foo
export GOPATH="${goPackages}:$PWD/build/go"
go build github.com/lnl7/foo
'';
installPhase = ''
mkdir -p $out/bin
cp foo $out/bin/foo
'';
shellHook = ''
cd ${builtins.toString ./.}
mkdir -p build/go/src/github.com/lnl7
ln -sfn ../../../../.. build/go/src/github.com/lnl7/foo
export GOPATH="${goPackages}:$PWD/build/go";
'';
}
package main
import "fmt"
func main() {
fmt.Printf("Hello World!\n")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment