1{ stdenv, fetchurl, pythonPackages, gettext
2, setools, libsepol, libselinux, libcap_ng, libsemanage, sepolgen
3}:
4
5stdenv.mkDerivation rec {
6 name = "policycoreutils-${version}";
7 version = "2.4";
8 inherit (libsepol) se_release se_url;
9
10 src = fetchurl {
11 url = "${se_url}/${se_release}/policycoreutils-${version}.tar.gz";
12 sha256 = "0y9l9k60iy21hj0lcvfdfxs1fxydg6d3pxp9rhy7hwr4y5vgh6dq";
13 };
14
15 patches = [ ./fix-printf-type.patch ];
16
17 postPatch = ''
18 # Fix references to libsepol.a
19 find . -name Makefile -exec sed -i 's,[^ ]*/libsepol.a,${libsepol}/lib/libsepol.a,g' {} \;
20
21 # Fix install references
22 substituteInPlace po/Makefile --replace /usr/bin/install install
23
24 # Fix references to /usr/share
25 grep -r '/usr/share' | awk -F: '{print $1}' | xargs sed -i "s,\(\$(DESTDIR)\)*/usr/share,$out/share,g"
26
27 # Fix sepolicy install
28 sed -i "s,\(setup.py install\).*,\1 --prefix=$out,g" sepolicy/Makefile
29 '';
30
31 nativeBuildInputs = [ pythonPackages.python gettext ];
32 buildInputs = [ setools libsepol libselinux libcap_ng libsemanage ];
33 pythonPath = [ libselinux sepolgen ];
34
35 preBuild = ''
36 makeFlagsArray+=("PREFIX=$out")
37 makeFlagsArray+=("DESTDIR=$out")
38 '';
39
40 # Creation of the system-config-selinux directory is broken
41 preInstall = ''
42 mkdir -p $out/share/system-config-selinux
43 '';
44
45 # Fix the python scripts to include paths to libraries
46 # NOTE: We are not using wrapPythonPrograms or makeWrapper as these scripts
47 # purge the environment as a security measure
48 postInstall = ''
49 grep -r '#!.*python' $out/bin | awk -F: '{print $1}' | xargs sed -i "1a \
50 import sys; \
51 sys.path.append('$(toPythonPath "$out")'); \
52 ${stdenv.lib.flip stdenv.lib.concatMapStrings pythonPath (lib: ''
53 sys.path.append('$(toPythonPath "${lib}")'); \
54 '')}"
55 '';
56
57 NIX_CFLAGS_COMPILE = "-fstack-protector-all";
58
59 meta = with stdenv.lib; {
60 description = "SELinux policy core utilities";
61 license = licenses.gpl2;
62 inherit (libsepol.meta) homepage platforms maintainers;
63 };
64}
65