@@ -0,0 +1,57 @@
1+{ stdenv, lib, fetchurl, fetchFromGitHub, writeText }:
2+
3+let
4+ version = "0.75";
5+ sha256 = "1iajg55n47hqxcpdzmyq4g4aprx7bzxcp885i850h355k5vmf68r";
6+ # Please don’t forget to update the docs:
7+ # clone https://github.com/Profpatsch/cdb-docs
8+ # and create a pull request with the result of running
9+ # ./update <version>
10+ # from the repository’s root folder.
11+ docRepo = fetchFromGitHub {
12+ owner = "Profpatsch";
13+ repo = "cdb-docs";
14+ rev = "359b6c55c9e170ebfc88f3f38face8ae2315eacb";
15+ sha256 = "1y0ivviy58i0pmavhvrpznc4yjigjknff298gnw9rkg5wxm0gbbq";
16+ };
17+
18+in stdenv.mkDerivation {
19+ name = "cdb-${version}";
20+
21+ src = fetchurl {
22+ url = "https://cr.yp.to/cdb/cdb-${version}.tar.gz";
23+ inherit sha256;
24+ };
25+
26+ outputs = [ "bin" "doc" "out" ];
27+
28+ postPatch = ''
29+ # A little patch, borrowed from Archlinux AUR, borrowed from Gentoo Portage
30+ sed -e 's/^extern int errno;$/#include <errno.h>/' -i error.h
31+ '';
32+
33+ postInstall = ''
34+ # don't use make setup, but move the binaries ourselves
35+ mkdir -p $bin/bin
36+ install -m 755 -t $bin/bin/ cdbdump cdbget cdbmake cdbmake-12 cdbmake-sv cdbstats cdbtest
37+
38+ # patch paths in scripts
39+ function cdbmake-subst {
40+ substituteInPlace $bin/bin/$1 \
41+ --replace /usr/local/bin/cdbmake $bin/bin/cdbmake
42+ }
43+ cdbmake-subst cdbmake-12
44+ cdbmake-subst cdbmake-sv
45+
46+ # docs
47+ mkdir -p $doc/share/cdb
48+ cp -r "${docRepo}/docs" $doc/share/cdb/html
49+ '';
50+
51+ meta = {
52+ homepage = "https://cr.yp.to/cdb";
53+ license = lib.licenses.publicDomain;
54+ maintainers = [ lib.maintainers.Profpatsch ];
55+ platforms = [ lib.platforms.unix ];
56+ };
57+}