1{ stdenv, lib, buildPackages, fetchurl, attr, perl, runtimeShell
2, usePam ? !isStatic, pam ? null
3, isStatic ? stdenv.hostPlatform.isStatic
4}:
5
6assert usePam -> pam != null;
7
8stdenv.mkDerivation rec {
9 pname = "libcap";
10 version = "2.49";
11
12 src = fetchurl {
13 url = "mirror://kernel/linux/libs/security/linux-privs/libcap2/${pname}-${version}.tar.xz";
14 sha256 = "sha256-6YvE2TZFCC7Hh3MLD9GnErOIgkZcUFd33hfDOIMe4YE=";
15 };
16
17 outputs = [ "out" "dev" "lib" "man" "doc" ]
18 ++ lib.optional usePam "pam";
19
20 depsBuildBuild = [ buildPackages.stdenv.cc ];
21 nativeBuildInputs = [ perl ];
22
23 buildInputs = lib.optional usePam pam;
24
25 propagatedBuildInputs = [ attr ];
26
27 makeFlags = [
28 "lib=lib"
29 "PAM_CAP=${if usePam then "yes" else "no"}"
30 "BUILD_CC=$(CC_FOR_BUILD)"
31 "CC:=$(CC)"
32 ] ++ lib.optional isStatic "SHARED=no";
33
34 prePatch = ''
35 # use full path to bash
36 substituteInPlace progs/capsh.c --replace "/bin/bash" "${runtimeShell}"
37
38 # set prefixes
39 substituteInPlace Make.Rules \
40 --replace 'prefix=/usr' "prefix=$lib" \
41 --replace 'exec_prefix=' "exec_prefix=$out" \
42 --replace 'lib_prefix=$(exec_prefix)' "lib_prefix=$lib" \
43 --replace 'inc_prefix=$(prefix)' "inc_prefix=$dev" \
44 --replace 'man_prefix=$(prefix)' "man_prefix=$doc"
45 '';
46
47 installFlags = [ "RAISE_SETFCAP=no" ];
48
49 postInstall = ''
50 ${lib.optionalString (!isStatic) ''rm "$lib"/lib/*.a''}
51 mkdir -p "$doc/share/doc/${pname}-${version}"
52 cp License "$doc/share/doc/${pname}-${version}/"
53 '' + lib.optionalString usePam ''
54 mkdir -p "$pam/lib/security"
55 mv "$lib"/lib/security "$pam/lib"
56 '';
57
58 meta = {
59 description = "Library for working with POSIX capabilities";
60 homepage = "https://sites.google.com/site/fullycapable";
61 platforms = lib.platforms.linux;
62 license = lib.licenses.bsd3;
63 };
64}