2021-08-05 21:33:18 +00:00
{ lib , stdenv , fetchFromGitHub , bc , python3 , bison , flex , fuse , libarchive
2022-10-06 18:32:54 +00:00
, buildPackages
, firewallSupport ? false
} :
2020-04-24 23:36:52 +00:00
stdenv . mkDerivation rec {
pname = " l k l " ;
2023-03-04 12:14:45 +00:00
# NOTE: pinned to the last known version that doesn't have a hang in cptofs.
# Please verify `nix build -f nixos/release-combined.nix nixos.ova` works
# before attempting to update again.
# ref: https://github.com/NixOS/nixpkgs/pull/219434
version = " 2 0 2 2 - 0 8 - 0 8 " ;
2020-04-24 23:36:52 +00:00
outputs = [ " d e v " " l i b " " o u t " ] ;
src = fetchFromGitHub {
owner = " l k l " ;
repo = " l i n u x " ;
2023-03-04 12:14:45 +00:00
rev = " f f b b 4 a a 6 7 b 3 e 0 a 6 4 f 6 9 6 3 f 5 9 3 8 5 a 2 0 0 d 0 8 c b 2 d 8 b " ;
sha256 = " s h a 2 5 6 - 2 4 s N R E d n h k F + P + 3 P 0 q E h 2 t F 1 j H K F 7 K c b F S n / r P K 2 z W s = " ;
2020-04-24 23:36:52 +00:00
} ;
2022-09-09 14:08:57 +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-22 12:36:57 +00:00
patchShebangs scripts/ld-version.sh
2022-09-09 14:08:57 +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-10-06 18:32:54 +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-09-09 14:08:57 +00:00
'' ;
2020-04-24 23:36:52 +00:00
installPhase = ''
mkdir - p $ out/bin $ lib/lib $ dev
cp tools/lkl/bin/lkl-hijack.sh $ out/bin
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 , "
cp tools/lkl / { cptofs , fs2tar , lklfuse } $ out/bin
ln - s cptofs $ out/bin/cpfromfs
cp - r tools/lkl/include $ dev /
cp tools/lkl/liblkl.a \
tools/lkl/lib/liblkl.so \
tools/lkl/lib/hijack/liblkl-hijack.so $ lib/lib
'' ;
# 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 " ] ;
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 } "
] ;
enableParallelBuilding = true ;
2021-01-15 22:18:51 +00:00
meta = with lib ; {
2020-04-24 23:36:52 +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
'' ;
homepage = " h t t p s : / / g i t h u b . c o m / l k l / l i n u x / " ;
2022-09-09 14:08:57 +00:00
platforms = platforms . linux ; # Darwin probably works too but I haven't tested it
2020-04-24 23:36:52 +00:00
license = licenses . gpl2 ;
2023-03-04 12:14:45 +00:00
maintainers = with maintainers ; [ copumpkin raitobezarius ] ;
2020-04-24 23:36:52 +00:00
} ;
}