Skip to content

Instantly share code, notes, and snippets.

@mstone
Created January 2, 2014 02:37
Show Gist options
  • Save mstone/8214158 to your computer and use it in GitHub Desktop.
Save mstone/8214158 to your computer and use it in GitHub Desktop.
First-draft [Nix](http://nixos.org/nix/manual/) expression for building simple [Golang](http://golang.org) programs.
# Copyright (c) 2014 Akamai Technologies, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# * Neither the name of Akamai Technologies, Inc. nor the names of its
# contributors may be used to endorse or promote products derived from this
# software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
{ stdenv, fetchgit, fetchhg, go, lib }:
let buildGoPackage = {
name,
extraSrcs ? [],
meta ? {},
vcs ? "git",
url ? "",
rev ? "",
tag ? "",
sha256,
repoPath,
importPath ? "",
install ? false,
}:
let
goPath = lib.strings.concatStringsSep ":" extraSrcs;
importPath2 = if importPath == "" then repoPath else importPath;
in
stdenv.mkDerivation rec {
inherit name meta;
src = if (vcs == "git") then
fetchgit {
inherit url rev sha256;
}
else
fetchhg {
inherit url tag sha256;
};
buildInputs = [go] ++ extraSrcs;
unpackPhase = "echo unpack;";
buildPhase = "echo build;";
installPhase = ''
mkdir -p "$out/src/$(dirname ${repoPath})";
ln -sf "$src" "$out/src/${repoPath}";
export GOPATH="$out:${goPath}";
cd $out;
go install "${importPath2}";
'';
};
in rec {
kr-fs_20140101 = buildGoPackage {
name = "kr-fs-20140101";
repoPath = "github.com/kr/fs";
url = "https://github.com/kr/fs";
rev = "2788f0dbd16903de03cb8186e5c7d97b69ad387b";
sha256 = "9e86737d232cf5bc2baad44cb214a5630f445b5053071c69d900ea4ce88d0eb0";
};
go-tools_20140101 = buildGoPackage {
name = "go.tools-20140101";
repoPath = "code.google.com/p/go.tools";
importPath = "code.google.com/p/go.tools/go/vcs";
vcs = "hg";
url = "https://code.google.com/p/go.tools/";
tag = "cb7689e25ef00326dcc6258f2293fb31acc5b791";
sha256 = "04cv3w51pkp76c27p5s237kl0df2rwili5rp5aai0d4cnpg7b1bg";
};
godep_20140101 = buildGoPackage {
name = "godep-20140101";
install = true;
repoPath = "github.com/kr/godep";
url = "https://github.com/kr/godep";
rev = "69f78935399499698084fa7829a895f97f0855cf";
sha256 = "254a8635e1324dc3a65f0bf248c17268ba0224e0ba9c03a8cca5326158d52492";
extraSrcs = [kr-fs_20140101 go-tools_20140101];
meta = with stdenv.lib; {
homepage = "https://github.com/kr/godep";
description = "A golang dependency management tool";
longDescription = ''
Command godep helps build packages reproducibly by fixing their dependencies.
'';
maintainers = [
"[email protected]"
];
platforms = platforms.linux;
};
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment