compile custom lqx kernel with clang and lto
This commit is contained in:
parent
3ed8cb071a
commit
55f98da282
@ -166,7 +166,8 @@
|
||||
"netbird-24.11.patch"
|
||||
"onlyoffice.patch"
|
||||
"vaultwarden.patch"
|
||||
"zen-kernels.patch"
|
||||
# "zen-kernels.patch"
|
||||
"fix-args-override.patch"
|
||||
];
|
||||
stable-patches = shared-patches ++ patchesPath [ "netbird-24.05.patch" "vaultwarden-24.05.patch" ];
|
||||
in {
|
||||
|
@ -2,6 +2,7 @@
|
||||
imports = with inputs.self; [
|
||||
./boot.nix
|
||||
./hardware-configuration.nix
|
||||
./kernel
|
||||
customRoles.workstation
|
||||
|
||||
customProfiles.a2ln-server
|
||||
|
86
machines/AMD-Workstation/kernel/default.nix
Normal file
86
machines/AMD-Workstation/kernel/default.nix
Normal file
@ -0,0 +1,86 @@
|
||||
{ config, pkgs, lib, ... }: {
|
||||
# boot.kernelPackages = lib.mkForce (pkgs.linuxPackagesFor pkgs.linuxLqxZfs);
|
||||
boot.kernelPackages = lib.mkForce pkgs.linuxPackages_lqx_clang;
|
||||
|
||||
nixpkgs.overlays = let
|
||||
inherit (pkgs) overrideCC ccacheWrapper addAttrsToDerivation;
|
||||
|
||||
llvmPackages = "llvmPackages_17";
|
||||
noBintools = { bootBintools = null; bootBintoolsNoLibc = null; };
|
||||
mkLLVMPlatform = platform: platform // { useLLVM = true; };
|
||||
|
||||
# Get llvmPackages for host and build platforms, disabling bootBintools
|
||||
hostLLVM = pkgs.pkgsBuildHost.${llvmPackages}.override noBintools;
|
||||
# buildLLVM = pkgs.pkgsBuildBuild.${llvmPackages}.override noBintools; # unused
|
||||
|
||||
# Get LLVM stdenv with clang
|
||||
stdenvClangUseLLVM = overrideCC hostLLVM.stdenv hostLLVM.clangUseLLVM;
|
||||
|
||||
# set useLLVM to true for host and build platforms
|
||||
stdenvPlatformLLVM = stdenvClangUseLLVM.override (old: {
|
||||
hostPlatform = mkLLVMPlatform old.hostPlatform;
|
||||
buildPlatform = mkLLVMPlatform old.buildPlatform;
|
||||
});
|
||||
|
||||
# Wrap clang with ccache
|
||||
stdenvCcacheLLVM = overrideCC stdenvPlatformLLVM (
|
||||
ccacheWrapper.override { cc = stdenvPlatformLLVM.cc; }
|
||||
);
|
||||
|
||||
# Disable fortify hardening as LLVM does not support it, and disable response file
|
||||
stdenvLLVM = addAttrsToDerivation {
|
||||
env.NIX_CC_USE_RESPONSE_FILE = "0";
|
||||
hardeningDisable = [ "fortify" ];
|
||||
} stdenvCcacheLLVM;
|
||||
in [
|
||||
(final: prev: {
|
||||
linuxPackages_lqx_clang = prev.linuxPackages_lqx.extend (lpfinal: lpprev: {
|
||||
kernel = (lpprev.kernel.override {
|
||||
buildPackages = final.buildPackages // { stdenv = stdenvLLVM; };
|
||||
stdenv = stdenvLLVM;
|
||||
argsOverride = let
|
||||
version = "6.8.12";
|
||||
suffix = "lqx2";
|
||||
hash = "sha256-/CoEY+d95CFatz+P6yGerJ1p076QP7nCny4ipO3MXDQ=";
|
||||
|
||||
no-dynamic-linker-patch = {
|
||||
name = "no-dynamic-linker";
|
||||
patch = ./no-dynamic-linker.patch;
|
||||
};
|
||||
in {
|
||||
inherit version;
|
||||
modDirVersion = lib.versions.pad 3 "${version}-${suffix}";
|
||||
src = prev.fetchFromGitHub {
|
||||
owner = "zen-kernel";
|
||||
repo = "zen-kernel";
|
||||
rev = "v${version}-${suffix}";
|
||||
inherit hash;
|
||||
};
|
||||
extraMakeFlags = [ "LLVM=1" "LLVM_IAS=1" ];
|
||||
kernelPatches = [ no-dynamic-linker-patch ] ++ lpprev.kernel.kernelPatches;
|
||||
structuredExtraConfig = with lib.kernel;
|
||||
lpprev.kernel.structuredExtraConfig //
|
||||
builtins.mapAttrs (_: v: lib.mkForce v) {
|
||||
CC_OPTIMIZE_FOR_PERFORMANCE_O3 = yes;
|
||||
# GENERIC_CPU3 = yes;
|
||||
MZEN = yes;
|
||||
INIT_ON_ALLOC_DEFAULT_ON = yes;
|
||||
INIT_STACK_ALL_ZERO = yes;
|
||||
LTO_CLANG_FULL = yes;
|
||||
MODULE_COMPRESS_XZ = no;
|
||||
MODULE_COMPRESS_ZSTD = yes;
|
||||
RCU_BOOST = no;
|
||||
RCU_BOOST_DELAY = option (freeform "500");
|
||||
RCU_LAZY = no;
|
||||
};
|
||||
};
|
||||
});
|
||||
});
|
||||
})
|
||||
];
|
||||
|
||||
assertions = [{
|
||||
assertion = config.programs.ccache.enable;
|
||||
message = "To compile custom kernel you must enable and setup ccache";
|
||||
}];
|
||||
}
|
40
machines/AMD-Workstation/kernel/no-dynamic-linker.patch
Normal file
40
machines/AMD-Workstation/kernel/no-dynamic-linker.patch
Normal file
@ -0,0 +1,40 @@
|
||||
diff --git a/Makefile b/Makefile
|
||||
index a171eafce2a3b..10ed19caecb1b 100644
|
||||
--- a/Makefile
|
||||
+++ b/Makefile
|
||||
@@ -531,6 +531,9 @@ RUSTFLAGS_KERNEL =
|
||||
AFLAGS_KERNEL =
|
||||
LDFLAGS_vmlinux =
|
||||
|
||||
+LDFLAGS_MODULE += --no-dynamic-linker
|
||||
+LDFLAGS_vmlinux += --no-dynamic-linker
|
||||
+
|
||||
# Use USERINCLUDE when you must reference the UAPI directories only.
|
||||
USERINCLUDE := \
|
||||
-I$(srctree)/arch/$(SRCARCH)/include/uapi \
|
||||
diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
|
||||
index 3cece19b74732..390a4604166eb 100644
|
||||
--- a/arch/x86/boot/Makefile
|
||||
+++ b/arch/x86/boot/Makefile
|
||||
@@ -102,7 +102,7 @@ $(obj)/zoffset.h: $(obj)/compressed/vmlinux FORCE
|
||||
AFLAGS_header.o += -I$(objtree)/$(obj)
|
||||
$(obj)/header.o: $(obj)/zoffset.h
|
||||
|
||||
-LDFLAGS_setup.elf := -m elf_i386 -z noexecstack -T
|
||||
+LDFLAGS_setup.elf := --no-dynamic-linker -m elf_i386 -z noexecstack -T
|
||||
$(obj)/setup.elf: $(src)/setup.ld $(SETUP_OBJS) FORCE
|
||||
$(call if_changed,ld)
|
||||
|
||||
diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
|
||||
index f614009d3e4e2..4b42006d9ce02 100644
|
||||
--- a/arch/x86/realmode/rm/Makefile
|
||||
+++ b/arch/x86/realmode/rm/Makefile
|
||||
@@ -50,7 +50,7 @@ $(obj)/pasyms.h: $(REALMODE_OBJS) FORCE
|
||||
targets += realmode.lds
|
||||
$(obj)/realmode.lds: $(obj)/pasyms.h
|
||||
|
||||
-LDFLAGS_realmode.elf := -m elf_i386 --emit-relocs -T
|
||||
+LDFLAGS_realmode.elf := --no-dynamic-linker -m elf_i386 --emit-relocs -T
|
||||
CPPFLAGS_realmode.lds += -P -C -I$(objtree)/$(obj)
|
||||
|
||||
targets += realmode.elf
|
108
patches/fix-args-override.patch
Normal file
108
patches/fix-args-override.patch
Normal file
@ -0,0 +1,108 @@
|
||||
diff --git a/pkgs/os-specific/linux/kernel/update-zen.py b/pkgs/os-specific/linux/kernel/update-zen.py
|
||||
index 3c51f806d..a8a363761 100755
|
||||
--- a/pkgs/os-specific/linux/kernel/update-zen.py
|
||||
+++ b/pkgs/os-specific/linux/kernel/update-zen.py
|
||||
@@ -64,16 +64,16 @@ def update_file(relpath, variant, version, suffix, sha256):
|
||||
for line in f:
|
||||
result = line
|
||||
result = re.sub(
|
||||
- fr'^ version = ".+"; #{variant}',
|
||||
- f' version = "{version}"; #{variant}',
|
||||
+ fr'^ version = ".+"; #{variant}',
|
||||
+ f' version = "{version}"; #{variant}',
|
||||
result)
|
||||
result = re.sub(
|
||||
- fr'^ suffix = ".+"; #{variant}',
|
||||
- f' suffix = "{suffix}"; #{variant}',
|
||||
+ fr'^ suffix = ".+"; #{variant}',
|
||||
+ f' suffix = "{suffix}"; #{variant}',
|
||||
result)
|
||||
result = re.sub(
|
||||
- fr'^ sha256 = ".+"; #{variant}',
|
||||
- f' sha256 = "{sha256}"; #{variant}',
|
||||
+ fr'^ sha256 = ".+"; #{variant}',
|
||||
+ f' sha256 = "{sha256}"; #{variant}',
|
||||
result)
|
||||
print(result, end='')
|
||||
|
||||
diff --git a/pkgs/os-specific/linux/kernel/zen-kernels.nix b/pkgs/os-specific/linux/kernel/zen-kernels.nix
|
||||
index 3acf40121..9e2c968ac 100644
|
||||
--- a/pkgs/os-specific/linux/kernel/zen-kernels.nix
|
||||
+++ b/pkgs/os-specific/linux/kernel/zen-kernels.nix
|
||||
@@ -1,20 +1,22 @@
|
||||
-{ lib, stdenv, fetchFromGitHub, buildLinux, ... } @ args:
|
||||
+{ lib, stdenv, fetchFromGitHub, buildLinux, variant, ... } @ args:
|
||||
|
||||
let
|
||||
# comments with variant added for update script
|
||||
- # ./update-zen.py zen
|
||||
- zenVariant = {
|
||||
- version = "6.9.8"; #zen
|
||||
- suffix = "zen1"; #zen
|
||||
- sha256 = "1ixrdx2a6jp1x8kryjmxnrgl0fsrjg6fngg5c48vbl2574nizlbz"; #zen
|
||||
- isLqx = false;
|
||||
- };
|
||||
- # ./update-zen.py lqx
|
||||
- lqxVariant = {
|
||||
- version = "6.9.8"; #lqx
|
||||
- suffix = "lqx1"; #lqx
|
||||
- sha256 = "1r5ld2xibr0qkwi1yy7h746sclsmd8cq68z0zdpbbn2qrgyx302k"; #lqx
|
||||
- isLqx = true;
|
||||
+ variants = {
|
||||
+ # ./update-zen.py zen
|
||||
+ zen = {
|
||||
+ version = "6.9.8"; #zen
|
||||
+ suffix = "zen1"; #zen
|
||||
+ sha256 = "1ixrdx2a6jp1x8kryjmxnrgl0fsrjg6fngg5c48vbl2574nizlbz"; #zen
|
||||
+ isLqx = false;
|
||||
+ };
|
||||
+ # ./update-zen.py lqx
|
||||
+ lqx = {
|
||||
+ version = "6.9.8"; #lqx
|
||||
+ suffix = "lqx1"; #lqx
|
||||
+ sha256 = "1r5ld2xibr0qkwi1yy7h746sclsmd8cq68z0zdpbbn2qrgyx302k"; #lqx
|
||||
+ isLqx = true;
|
||||
+ };
|
||||
};
|
||||
zenKernelsFor = { version, suffix, sha256, isLqx }: buildLinux (args // {
|
||||
inherit version;
|
||||
@@ -123,7 +125,4 @@ let
|
||||
|
||||
} // (args.argsOverride or { }));
|
||||
in
|
||||
-{
|
||||
- zen = zenKernelsFor zenVariant;
|
||||
- lqx = zenKernelsFor lqxVariant;
|
||||
-}
|
||||
+zenKernelsFor variants.${variant}
|
||||
\ No newline at end of file
|
||||
diff --git a/pkgs/top-level/linux-kernels.nix b/pkgs/top-level/linux-kernels.nix
|
||||
index bc80ec658..edc94fc34 100644
|
||||
--- a/pkgs/top-level/linux-kernels.nix
|
||||
+++ b/pkgs/top-level/linux-kernels.nix
|
||||
@@ -227,19 +227,21 @@ in {
|
||||
# https://github.com/NixOS/nixpkgs/pull/161773#discussion_r820134708
|
||||
zenKernels = callPackage ../os-specific/linux/kernel/zen-kernels.nix;
|
||||
|
||||
- linux_zen = (zenKernels {
|
||||
+ linux_zen = zenKernels {
|
||||
+ variant = "zen";
|
||||
kernelPatches = [
|
||||
kernelPatches.bridge_stp_helper
|
||||
kernelPatches.request_key_helper
|
||||
];
|
||||
- }).zen;
|
||||
+ };
|
||||
|
||||
- linux_lqx = (zenKernels {
|
||||
+ linux_lqx = zenKernels {
|
||||
+ variant = "lqx";
|
||||
kernelPatches = [
|
||||
kernelPatches.bridge_stp_helper
|
||||
kernelPatches.request_key_helper
|
||||
];
|
||||
- }).lqx;
|
||||
+ };
|
||||
|
||||
# This contains the variants of the XanMod kernel
|
||||
xanmodKernels = callPackage ../os-specific/linux/kernel/xanmod-kernels.nix {
|
Loading…
x
Reference in New Issue
Block a user