1{ stdenv, fetchurl, attr, perl, pam ? null }:
2assert pam != null -> stdenv.isLinux;
3
4stdenv.mkDerivation rec {
5 name = "libcap-${version}";
6 version = "2.25";
7
8 src = fetchurl {
9 url = "mirror://kernel/linux/libs/security/linux-privs/libcap2/${name}.tar.xz";
10 sha256 = "0qjiqc5pknaal57453nxcbz3mn1r4hkyywam41wfcglq3v2qlg39";
11 };
12
13 outputs = [ "out" "dev" "lib" "man" "doc" ]
14 ++ stdenv.lib.optional (pam != null) "pam";
15
16 nativeBuildInputs = [ perl ];
17
18 buildInputs = [ pam ];
19
20 propagatedBuildInputs = [ attr ];
21
22 makeFlags = [
23 "lib=lib"
24 (stdenv.lib.optional (pam != null) "PAM_CAP=yes")
25 ];
26
27 prePatch = ''
28 # use relative bash path
29 substituteInPlace progs/capsh.c --replace "/bin/bash" "bash"
30
31 # ensure capsh can find bash in $PATH
32 substituteInPlace progs/capsh.c --replace execve execvpe
33 '';
34
35 preInstall = ''
36 substituteInPlace Make.Rules \
37 --replace 'prefix=/usr' "prefix=$lib" \
38 --replace 'exec_prefix=' "exec_prefix=$out" \
39 --replace 'lib_prefix=$(exec_prefix)' "lib_prefix=$lib" \
40 --replace 'inc_prefix=$(prefix)' "inc_prefix=$dev" \
41 --replace 'man_prefix=$(prefix)' "man_prefix=$doc"
42 '';
43
44 installFlags = "RAISE_SETFCAP=no";
45
46 postInstall = ''
47 rm "$lib"/lib/*.a
48 mkdir -p "$doc/share/doc/${name}"
49 cp License "$doc/share/doc/${name}/"
50 '' + stdenv.lib.optionalString (pam != null) ''
51 mkdir -p "$pam/lib/security"
52 mv "$lib"/lib/security "$pam/lib"
53 '';
54
55 meta = {
56 description = "Library for working with POSIX capabilities";
57 platforms = stdenv.lib.platforms.linux;
58 };
59}