btrbk: add mainProgram
[NixPkgs.git] / pkgs / by-name / li / libselinux / package.nix
blobe77c15e7c7ecd3bba52b2883acd551cc629ff1c8
1 { lib, stdenv, fetchurl, buildPackages, pcre2, pkg-config, libsepol
2 , enablePython ? !stdenv.hostPlatform.isStatic
3 , swig ? null, python3 ? null, python3Packages
4 , fts
5 }:
7 assert enablePython -> swig != null && python3 != null;
9 stdenv.mkDerivation (rec {
10   pname = "libselinux";
11   version = "3.7";
12   inherit (libsepol) se_url;
14   outputs = [ "bin" "out" "dev" "man" ] ++ lib.optional enablePython "py";
16   src = fetchurl {
17     url = "${se_url}/${version}/libselinux-${version}.tar.gz";
18     hash = "sha256-6gP0LROk+VdXmX26jPCyYyH6xdLxZEGLTMhWqS0rF70=";
19   };
21   patches = [
22     # Make it possible to disable shared builds (for pkgsStatic).
23     #
24     # We can't use fetchpatch because it processes includes/excludes
25     # /after/ stripping the prefix, which wouldn't work here because
26     # there would be no way to distinguish between
27     # e.g. libselinux/src/Makefile and libsepol/src/Makefile.
28     #
29     # This is a static email, so we shouldn't have to worry about
30     # normalizing the patch.
31     (fetchurl {
32       url = "https://lore.kernel.org/selinux/20211113141616.361640-1-hi@alyssa.is/raw";
33       sha256 = "16a2s2ji9049892i15yyqgp4r20hi1hij4c1s4s8law9jsx65b3n";
34       postFetch = ''
35         mv "$out" $TMPDIR/patch
36         ${buildPackages.patchutils_0_3_3}/bin/filterdiff \
37             -i 'a/libselinux/*' --strip 1 <$TMPDIR/patch >"$out"
38       '';
39     })
41     (fetchurl {
42       url = "https://git.yoctoproject.org/meta-selinux/plain/recipes-security/selinux/libselinux/0003-libselinux-restore-drop-the-obsolete-LSF-transitiona.patch?id=62b9c816a5000dc01b28e78213bde26b58cbca9d";
43       sha256 = "sha256-RiEUibLVzfiRU6N/J187Cs1iPAih87gCZrlyRVI2abU=";
44     })
45   ];
47   nativeBuildInputs = [ pkg-config python3 ] ++ lib.optionals enablePython [
48     python3Packages.pip
49     python3Packages.setuptools
50     python3Packages.wheel
51     swig
52   ];
53   buildInputs = [ libsepol pcre2 fts ] ++ lib.optionals enablePython [ python3 ];
55   # drop fortify here since package uses it by default, leading to compile error:
56   # command-line>:0:0: error: "_FORTIFY_SOURCE" redefined [-Werror]
57   hardeningDisable = [ "fortify" ];
59   env.NIX_CFLAGS_COMPILE = "-Wno-error -D_FILE_OFFSET_BITS=64";
61   makeFlags = [
62     "PREFIX=$(out)"
63     "INCDIR=$(dev)/include/selinux"
64     "INCLUDEDIR=$(dev)/include"
65     "MAN3DIR=$(man)/share/man/man3"
66     "MAN5DIR=$(man)/share/man/man5"
67     "MAN8DIR=$(man)/share/man/man8"
68     "SBINDIR=$(bin)/sbin"
69     "SHLIBDIR=$(out)/lib"
71     "LIBSEPOLA=${lib.getLib libsepol}/lib/libsepol.a"
72     "ARCH=${stdenv.hostPlatform.linuxArch}"
73   ] ++ lib.optionals (fts != null) [
74     "FTS_LDLIBS=-lfts"
75   ] ++ lib.optionals stdenv.hostPlatform.isStatic [
76     "DISABLE_SHARED=y"
77   ] ++ lib.optionals enablePython [
78     "PYTHON=${python3.pythonOnBuildForHost.interpreter}"
79     "PYTHONLIBDIR=$(py)/${python3.sitePackages}"
80     "PYTHON_SETUP_ARGS=--no-build-isolation"
81   ];
83   preInstall = lib.optionalString enablePython ''
84     mkdir -p $py/${python3.sitePackages}/selinux
85   '';
87   installTargets = [ "install" ] ++ lib.optional enablePython "install-pywrap";
89   meta = removeAttrs libsepol.meta ["outputsToInstall"] // {
90     description = "SELinux core library";
91   };
92 } // lib.optionalAttrs (stdenv.cc.bintools.isLLVM && lib.versionAtLeast stdenv.cc.bintools.version "17") {
93   NIX_LDFLAGS = "--undefined-version";