2021-07-27 14:52:47 +00:00
{ lib , stdenv , fetchFromGitHub , bc , python3 , bison , flex , fuse , libarchive
2022-09-21 06:17:26 +00:00
, buildPackages
, firewallSupport ? false
} :
2017-01-16 21:24:21 +00:00
stdenv . mkDerivation rec {
2019-07-05 03:13:08 +00:00
pname = " l k l " ;
2022-09-14 19:04:46 +00:00
version = " 2 0 2 2 - 0 5 - 1 8 " ;
2017-01-16 21:24:21 +00:00
2017-05-23 22:43:22 +00:00
outputs = [ " d e v " " l i b " " o u t " ] ;
2017-01-16 21:24:21 +00:00
src = fetchFromGitHub {
2017-01-17 18:40:58 +00:00
owner = " l k l " ;
2017-01-16 21:24:21 +00:00
repo = " l i n u x " ;
2022-09-14 19:04:46 +00:00
rev = " 1 0 c 7 b 5 d e e 8 c 4 2 4 c c 2 a b 7 5 4 e 5 1 9 e c b 7 3 3 5 0 2 8 3 f f 9 " ;
sha256 = " s h a 2 5 6 - D 3 H Q d K z h B 1 7 2 L 6 2 a + 8 8 8 4 b N h c v 7 v m / c 9 4 1 w z b Y t b f 4 I = " ;
2017-01-16 21:24:21 +00:00
} ;
2022-08-21 15:30:18 +00:00
nativeBuildInputs = [ bc bison flex python3 ] ;
buildInputs = [ fuse libarchive ] ;
postPatch = ''
# Fix a /usr/bin/env reference in here that breaks sandboxed builds
patchShebangs arch/lkl/scripts
2022-09-14 19:04:46 +00:00
patchShebangs scripts/ld-version.sh
2022-08-21 15:30:18 +00:00
# Fixup build with newer Linux headers: https://github.com/lkl/linux/pull/484
sed ' 1 i #include <linux/sockios.h>' -i tools/lkl/lib/hijack/xlate.c
2022-09-21 06:17:26 +00:00
'' + l i b . o p t i o n a l S t r i n g f i r e w a l l S u p p o r t ''
cat $ { ./lkl-defconfig-enable-nftables } > > arch/lkl/configs/defconfig
2022-08-21 15:30:18 +00:00
'' ;
2017-01-25 21:30:46 +00:00
2017-01-16 21:24:21 +00:00
installPhase = ''
2017-05-23 22:43:22 +00:00
mkdir - p $ out/bin $ lib/lib $ dev
2017-01-16 21:24:21 +00:00
cp tools/lkl/bin/lkl-hijack.sh $ out/bin
2017-05-23 22:43:22 +00:00
sed - i $ out/bin/lkl-hijack.sh \
- e " s , L D _ L I B R A R Y _ P A T H = . * , L D _ L I B R A R Y _ P A T H = $ l i b / l i b , "
2017-01-16 21:24:21 +00:00
2018-03-11 11:42:07 +00:00
cp tools/lkl / { cptofs , fs2tar , lklfuse } $ out/bin
ln - s cptofs $ out/bin/cpfromfs
2017-05-23 22:43:22 +00:00
cp - r tools/lkl/include $ dev /
2019-02-02 04:31:50 +00:00
cp tools/lkl/liblkl.a \
tools/lkl/lib/liblkl.so \
tools/lkl/lib/hijack/liblkl-hijack.so $ lib/lib
2017-01-16 21:24:21 +00:00
'' ;
# We turn off format and fortify because of these errors (fortify implies -O2, which breaks the jitter entropy code):
# fs/xfs/xfs_log_recover.c:2575:3: error: format not a string literal and no format arguments [-Werror=format-security]
# crypto/jitterentropy.c:54:3: error: #error "The CPU Jitter random number generator must not be compiled with optimizations. See documentation. Use the compiler switch -O0 for compiling jitterentropy.c."
hardeningDisable = [ " f o r m a t " " f o r t i f y " ] ;
2019-06-07 21:46:33 +00:00
makeFlags = [
" - C t o o l s / l k l "
" C C = ${ stdenv . cc } / b i n / ${ stdenv . cc . targetPrefix } c c "
" H O S T C C = ${ buildPackages . stdenv . cc } / b i n / ${ buildPackages . stdenv . cc . targetPrefix } c c "
" C R O S S _ C O M P I L E = ${ stdenv . cc . targetPrefix } "
] ;
2017-01-16 21:24:21 +00:00
2017-05-20 13:38:01 +00:00
enableParallelBuilding = true ;
2017-01-16 21:24:21 +00:00
2021-01-11 07:54:33 +00:00
meta = with lib ; {
2017-05-23 21:55:55 +00:00
description = " T h e L i n u x k e r n e l a s a l i b r a r y " ;
longDescription = ''
LKL ( Linux Kernel Library ) aims to allow reusing the Linux kernel code as
extensively as possible with minimal effort and reduced maintenance
overhead
'' ;
2020-04-01 01:11:51 +00:00
homepage = " h t t p s : / / g i t h u b . c o m / l k l / l i n u x / " ;
2022-08-21 15:30:18 +00:00
platforms = platforms . linux ; # Darwin probably works too but I haven't tested it
2017-01-16 21:24:21 +00:00
license = licenses . gpl2 ;
maintainers = with maintainers ; [ copumpkin ] ;
} ;
}