summary refs log tree commit diff
path: root/pkgs/os-specific/linux/policycoreutils/default.nix
blob: 1933523d9c2d1128ea22b15df469487e63c758e4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
{ stdenv, fetchurl, pythonPackages, gettext
, setools, libsepol, libselinux, libcap_ng, libsemanage, sepolgen
}:

stdenv.mkDerivation rec {
  name = "policycoreutils-${version}";
  version = "2.4";
  inherit (libsepol) se_release se_url;

  src = fetchurl {
    url = "${se_url}/${se_release}/policycoreutils-${version}.tar.gz";
    sha256 = "0y9l9k60iy21hj0lcvfdfxs1fxydg6d3pxp9rhy7hwr4y5vgh6dq";
  };

  patches = [ ./fix-printf-type.patch ];

  postPatch = ''
    # Fix references to libsepol.a
    find . -name Makefile -exec sed -i 's,[^ ]*/libsepol.a,${libsepol}/lib/libsepol.a,g' {} \;

    # Fix install references
    substituteInPlace po/Makefile --replace /usr/bin/install install

    # Fix references to /usr/share
    grep -r '/usr/share' | awk -F: '{print $1}' | xargs sed -i "s,\(\$(DESTDIR)\)*/usr/share,$out/share,g"

    # Fix sepolicy install
    sed -i "s,\(setup.py install\).*,\1 --prefix=$out,g" sepolicy/Makefile
  '';

  nativeBuildInputs = [ pythonPackages.python gettext ];
  buildInputs = [ setools libsepol libselinux libcap_ng libsemanage ];
  pythonPath = [ libselinux sepolgen ];

  preBuild = ''
    makeFlagsArray+=("PREFIX=$out")
    makeFlagsArray+=("DESTDIR=$out")
  '';

  # Creation of the system-config-selinux directory is broken
  preInstall = ''
    mkdir -p $out/share/system-config-selinux
  '';

  # Fix the python scripts to include paths to libraries
  # NOTE: We are not using wrapPythonPrograms or makeWrapper as these scripts
  # purge the environment as a security measure
  postInstall = ''
    grep -r '#!.*python' $out/bin | awk -F: '{print $1}' | xargs sed -i "1a \
    import sys; \
    sys.path.append('$(toPythonPath "$out")'); \
    ${stdenv.lib.flip stdenv.lib.concatMapStrings pythonPath (lib: ''
      sys.path.append('$(toPythonPath "${lib}")'); \
    '')}"
  '';

  NIX_CFLAGS_COMPILE = "-fstack-protector-all";

  meta = with stdenv.lib; {
    description = "SELinux policy core utilities";
    license = licenses.gpl2;
    inherit (libsepol.meta) homepage platforms maintainers;
  };
}