Last active
July 31, 2017 11:12
-
-
Save LnL7/d4fe689716f36bd84714afb1b2cd4bb4 to your computer and use it in GitHub Desktop.
nix golang project exmaple
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ 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"; | |
''; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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