2022-12-17 10:02:37 +00:00
|
|
|
{ lib, stdenv, fetchurl, buildPackages, linuxHeaders, perl, nixosTests }:
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
commonMakeFlags = [
|
|
|
|
"prefix=$(out)"
|
|
|
|
"SHLIBDIR=$(out)/lib"
|
|
|
|
];
|
|
|
|
in
|
|
|
|
|
|
|
|
stdenv.mkDerivation rec {
|
|
|
|
pname = "klibc";
|
2023-03-04 12:14:45 +00:00
|
|
|
version = "2.0.12";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
src = fetchurl {
|
|
|
|
url = "mirror://kernel/linux/libs/klibc/2.0/klibc-${version}.tar.xz";
|
2023-03-04 12:14:45 +00:00
|
|
|
hash = "sha256-cfgWoNOr46uotGMZrlyhR+eno4QBs/XiYgJfTcCMR10=";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
patches = [ ./no-reinstall-kernel-headers.patch ];
|
|
|
|
|
2021-02-05 17:12:51 +00:00
|
|
|
depsBuildBuild = [ buildPackages.stdenv.cc ];
|
2020-04-24 23:36:52 +00:00
|
|
|
nativeBuildInputs = [ perl ];
|
2021-02-05 17:12:51 +00:00
|
|
|
strictDeps = true;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
hardeningDisable = [ "format" "stackprotector" ];
|
|
|
|
|
|
|
|
makeFlags = commonMakeFlags ++ [
|
2022-09-09 14:08:57 +00:00
|
|
|
"KLIBCARCH=${if stdenv.hostPlatform.isRiscV64 then "riscv64" else stdenv.hostPlatform.linuxArch}"
|
2020-04-24 23:36:52 +00:00
|
|
|
"KLIBCKERNELSRC=${linuxHeaders}"
|
|
|
|
] # TODO(@Ericson2314): We now can get the ABI from
|
|
|
|
# `stdenv.hostPlatform.parsed.abi`, is this still a good idea?
|
2021-02-05 17:12:51 +00:00
|
|
|
++ lib.optional (stdenv.hostPlatform.linuxArch == "arm") "CONFIG_AEABI=y"
|
|
|
|
++ lib.optional (stdenv.hostPlatform != stdenv.buildPlatform) "CROSS_COMPILE=${stdenv.cc.targetPrefix}";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
# Install static binaries as well.
|
|
|
|
postInstall = ''
|
|
|
|
dir=$out/lib/klibc/bin.static
|
|
|
|
mkdir $dir
|
|
|
|
cp $(find $(find . -name static) -type f ! -name "*.g" -a ! -name ".*") $dir/
|
|
|
|
|
|
|
|
for file in ${linuxHeaders}/include/*; do
|
|
|
|
ln -sv $file $out/lib/klibc/include
|
|
|
|
done
|
|
|
|
'';
|
|
|
|
|
2022-12-17 10:02:37 +00:00
|
|
|
passthru.tests = {
|
|
|
|
# uses klibc's ipconfig
|
|
|
|
inherit (nixosTests) initrd-network-ssh;
|
|
|
|
};
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
meta = {
|
|
|
|
description = "Minimalistic libc subset for initramfs usage";
|
|
|
|
homepage = "https://kernel.org/pub/linux/libs/klibc/";
|
|
|
|
maintainers = with lib.maintainers; [ fpletz ];
|
|
|
|
license = lib.licenses.bsd3;
|
|
|
|
platforms = lib.platforms.linux;
|
|
|
|
};
|
|
|
|
}
|