1{ stdenv, buildPackages, 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 depsBuildBuild = [ buildPackages.stdenv.cc ];
17 nativeBuildInputs = [ perl ];
18
19 buildInputs = [ pam ];
20
21 propagatedBuildInputs = [ attr ];
22
23 makeFlags = [
24 "lib=lib"
25 (stdenv.lib.optional (pam != null) "PAM_CAP=yes")
26 "BUILD_CC=$(CC_FOR_BUILD)"
27 "CC:=$(CC)"
28 ];
29
30 prePatch = ''
31 # use relative bash path
32 substituteInPlace progs/capsh.c --replace "/bin/bash" "bash"
33
34 # ensure capsh can find bash in $PATH
35 substituteInPlace progs/capsh.c --replace execve execvpe
36
37 # set prefixes
38 substituteInPlace Make.Rules \
39 --replace 'prefix=/usr' "prefix=$lib" \
40 --replace 'exec_prefix=' "exec_prefix=$out" \
41 --replace 'lib_prefix=$(exec_prefix)' "lib_prefix=$lib" \
42 --replace 'inc_prefix=$(prefix)' "inc_prefix=$dev" \
43 --replace 'man_prefix=$(prefix)' "man_prefix=$doc"
44 '';
45
46 installFlags = "RAISE_SETFCAP=no";
47
48 postInstall = ''
49 rm "$lib"/lib/*.a
50 mkdir -p "$doc/share/doc/${name}"
51 cp License "$doc/share/doc/${name}/"
52 '' + stdenv.lib.optionalString (pam != null) ''
53 mkdir -p "$pam/lib/security"
54 mv "$lib"/lib/security "$pam/lib"
55 '';
56
57 meta = {
58 description = "Library for working with POSIX capabilities";
59 platforms = stdenv.lib.platforms.linux;
60 };
61}