Skip to content

Instantly share code, notes, and snippets.

@zimbatm
Created June 29, 2014 19:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zimbatm/8a3fd32b6aec0cac57f3 to your computer and use it in GitHub Desktop.
Save zimbatm/8a3fd32b6aec0cac57f3 to your computer and use it in GitHub Desktop.
{ pkgs ? (import <nixpkgs> {})
, stdenv ? pkgs.stdenv
, go ? pkgs.go
, git ? pkgs.git
}:
rec {
readChop = with builtins; path:
let
str = readFile path;
len = stringLength str;
in substring 0 (sub len 1) str;
gitref = with builtins; dir:
let
head = readChop (toPath "${dir}/.git/HEAD");
in
if (pkgs.lib.hasPrefix "ref: " head) then
readChop (substring 3 (sub (stringLength head) 4) head)
else
head;
crank = stdenv.mkDerivation rec {
git_version = gitref ./.;
version = "1.0.0-${git_version}";
name = "direnv-${version}";
src = ./.;
buildInputs = [ go ];
buildPhase = "make";
installPhase = ''make install "DESTDIR=$out"'';
dontStrip = 1;
meta = {
homepage = "http://direnv.net";
description = "path-dependent environments";
maintainers = [
stdenv.lib.maintainers.zimbatm
];
license = stdenv.lib.licenses.mit;
platforms = go.meta.platforms;
};
};
}
@zimbatm
Copy link
Author

zimbatm commented Jun 29, 2014

Produces:

error: string `/nix/store/38xyldzh0nzcy6r2yfkqqwnhg1vyl5fc-direnv/.git/HEAD' cannot refer to other paths, at /Users/zimbatm/code/github.com/zimbatm/direnv/default.nix:10:13

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment