sketch new service start/stop API as needed for testbed
[oweals/gnunet.git] / default.nix
1 # Nix package for GNUnet development
2 #
3 ## INSTALL
4 #
5 # To build and install the package in the user environment, use:
6 #
7 # $ nix-env -f . -i
8 #
9 ## BUILD ONLY
10 #
11 # To build the package and add it to the nix store, use:
12 #
13 # $ nix-build
14 #
15 ## SHELL
16 #
17 # To launch a shell with all dependencies installed in the environment, use one of the following:
18 #    $ nix-shell
19 #
20 # After entering nix-shell, build it:
21 #
22 # $ configurePhase
23 # $ buildPhase
24 #
25 ## NIXPKGS
26 #
27 # For all of the above commands, nixpkgs to use can be set the following way:
28 #
29 # a) by default it uses nixpkgs pinned to a known working version
30 #
31 # b) use nixpkgs from the system:
32 #    --arg pkgs 0
33 #
34 # c) use nixpkgs at a given path
35 #    --arg pkgs /path/to/nixpkgs
36 #
37 ## CCACHE
38 #
39 # To enable ccache, use the following:
40 #
41 #    --argstr ccache_dir /var/cache/ccache
42
43 # or when using nix-shell:
44 #    --argstr ccache_dir ~/.ccache
45 #
46 # and make sure the given directory is writable by the nixpkgs group when using nix-build or nix-env -i,
47 # or the current user when using nix-shell
48 #
49
50 {
51  pkgs ? null,
52  ccache_dir ? "",
53 }:
54
55 let
56   syspkgs = import <nixpkgs> { };
57   pinpkgs = syspkgs.fetchFromGitHub {
58     owner = "NixOS";
59     repo = "nixpkgs";
60
61     # binary cache exists for revisions in https://nixos.org/releases/nixos/<release>/<build>/git-revision
62     rev = "c4469edac1fc1fa5e5b5aa2ceadeda8f3f92d30a"; # https://nixos.org/releases/nixos/16.09/nixos-16.09beta430.c4469ed/git-revision
63     sha256 = "1x6hmf815d5anfxrxl6iivfkk60q5qxa6waa9xnwhwkbc14rhvn9";
64   };
65   usepkgs = if null == pkgs then
66              import pinpkgs {}
67             else
68               if 0 == pkgs then
69                 import <nixpkgs> { }
70               else
71                 import pkgs {};
72   stdenv = usepkgs.stdenvAdapters.keepDebugInfo usepkgs.stdenv;
73
74 in with usepkgs; stdenv.mkDerivation rec {
75   src = ./.;
76   name = "gnunet-dev";
77
78   buildInputs = [
79     makeWrapper pkgconfig autoconf automake ccache
80     adns curl gettext gmp gnutls gss ncurses openldap zlib sqlite mariadb postgresql
81     libextractor libgcrypt libgnurl libidn libmicrohttpd
82     libpsl libtool libunistring libxml2
83   ];
84
85   patchPhase = ''
86     test -e Makefile && make distclean
87   '';
88
89   NIX_CFLAGS_COMPILE = "-ggdb -O0";
90
91   configureFlags = [
92     "--enable-gcc-hardening"
93     "--enable-linker-hardening"
94
95     "--enable-experimental"
96     "--enable-logging=verbose"
97     "--enable-poisoning"
98   ];
99
100   preConfigure = ''
101     ./bootstrap
102     configureFlags="$configureFlags --with-nssdir=$out/lib"
103
104     if [ -n "${ccache_dir}" ]; then
105       export CC='ccache gcc'
106       export CCACHE_COMPRESS=1
107       export CCACHE_DIR="${ccache_dir}"
108       export CCACHE_UMASK=007
109     fi
110   '';
111
112   doCheck = false;
113
114   postInstall = ''
115     # Tests can be run this way
116     #export GNUNET_PREFIX="$out"
117     #export PATH="$out/bin:$PATH"
118     #make -k check
119   '';
120
121   meta = with stdenv.lib; {
122     description = "GNU's decentralized anonymous and censorship-resistant P2P framework";
123
124     longDescription = ''
125       GNUnet is a framework for secure peer-to-peer networking that
126       does not use any centralized or otherwise trusted services.  A
127       first service implemented on top of the networking layer
128       allows anonymous censorship-resistant file-sharing.  Anonymity
129       is provided by making messages originating from a peer
130       indistinguishable from messages that the peer is routing.  All
131       peers act as routers and use link-encrypted connections with
132       stable bandwidth utilization to communicate with each other.
133       GNUnet uses a simple, excess-based economic model to allocate
134       resources.  Peers in GNUnet monitor each others behavior with
135       respect to resource usage; peers that contribute to the
136       network are rewarded with better service.
137     '';
138
139     homepage = http://gnunet.org/;
140
141     license = licenses.gpl3Plus;
142     platforms = platforms.gnu;
143     maintainers = with maintainers; [ ];
144   };
145 }