1{ stdenv, lib, fetchurl, fetchFromGitHub }:
2
3let
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
18in stdenv.mkDerivation {
19 pname = "cdb";
20 inherit version;
21
22 src = fetchurl {
23 url = "https://cr.yp.to/cdb/cdb-${version}.tar.gz";
24 inherit sha256;
25 };
26
27 outputs = [ "bin" "doc" "out" ];
28
29 postPatch = ''
30 # A little patch, borrowed from Archlinux AUR, borrowed from Gentoo Portage
31 sed -e 's/^extern int errno;$/#include <errno.h>/' -i error.h
32 '';
33
34 postInstall = ''
35 # don't use make setup, but move the binaries ourselves
36 mkdir -p $bin/bin
37 install -m 755 -t $bin/bin/ cdbdump cdbget cdbmake cdbmake-12 cdbmake-sv cdbstats cdbtest
38
39 # patch paths in scripts
40 function cdbmake-subst {
41 substituteInPlace $bin/bin/$1 \
42 --replace /usr/local/bin/cdbmake $bin/bin/cdbmake
43 }
44 cdbmake-subst cdbmake-12
45 cdbmake-subst cdbmake-sv
46
47 # docs
48 mkdir -p $doc/share/cdb
49 cp -r "${docRepo}/docs" $doc/share/cdb/html
50 '';
51
52 meta = {
53 homepage = "https://cr.yp.to/cdb.html";
54 license = lib.licenses.publicDomain;
55 maintainers = [ lib.maintainers.Profpatsch ];
56 platforms = lib.platforms.unix;
57 };
58}