1 { lib, stdenv, fetchurl, buildPackages, pcre2, pkg-config, libsepol
2 , enablePython ? !stdenv.hostPlatform.isStatic
3 , swig ? null, python3 ? null, python3Packages
7 assert enablePython -> swig != null && python3 != null;
9 stdenv.mkDerivation (rec {
12 inherit (libsepol) se_url;
14 outputs = [ "bin" "out" "dev" "man" ] ++ lib.optional enablePython "py";
17 url = "${se_url}/${version}/libselinux-${version}.tar.gz";
18 hash = "sha256-6gP0LROk+VdXmX26jPCyYyH6xdLxZEGLTMhWqS0rF70=";
22 # Make it possible to disable shared builds (for pkgsStatic).
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.
29 # This is a static email, so we shouldn't have to worry about
30 # normalizing the patch.
32 url = "https://lore.kernel.org/selinux/20211113141616.361640-1-hi@alyssa.is/raw";
33 sha256 = "16a2s2ji9049892i15yyqgp4r20hi1hij4c1s4s8law9jsx65b3n";
35 mv "$out" $TMPDIR/patch
36 ${buildPackages.patchutils_0_3_3}/bin/filterdiff \
37 -i 'a/libselinux/*' --strip 1 <$TMPDIR/patch >"$out"
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=";
47 nativeBuildInputs = [ pkg-config python3 ] ++ lib.optionals enablePython [
49 python3Packages.setuptools
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";
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"
71 "LIBSEPOLA=${lib.getLib libsepol}/lib/libsepol.a"
72 "ARCH=${stdenv.hostPlatform.linuxArch}"
73 ] ++ lib.optionals (fts != null) [
75 ] ++ lib.optionals stdenv.hostPlatform.isStatic [
77 ] ++ lib.optionals enablePython [
78 "PYTHON=${python3.pythonOnBuildForHost.interpreter}"
79 "PYTHONLIBDIR=$(py)/${python3.sitePackages}"
80 "PYTHON_SETUP_ARGS=--no-build-isolation"
83 preInstall = lib.optionalString enablePython ''
84 mkdir -p $py/${python3.sitePackages}/selinux
87 installTargets = [ "install" ] ++ lib.optional enablePython "install-pywrap";
89 meta = removeAttrs libsepol.meta ["outputsToInstall"] // {
90 description = "SELinux core library";
92 } // lib.optionalAttrs (stdenv.cc.bintools.isLLVM && lib.versionAtLeast stdenv.cc.bintools.version "17") {
93 NIX_LDFLAGS = "--undefined-version";