Skip to content

Instantly share code, notes, and snippets.

@SaltyKitkat
Created June 21, 2023 23:38
Show Gist options
  • Select an option

  • Save SaltyKitkat/e1bf2b1a637a688a302dbf047f9aa576 to your computer and use it in GitHub Desktop.

Select an option

Save SaltyKitkat/e1bf2b1a637a688a302dbf047f9aa576 to your computer and use it in GitHub Desktop.
kernel.nix
{ lib, pkgs, fetchFromGitHub, fetchurl, linuxManualConfig, llvmPackages_latest, overrideCC, ... }:
{ kernelConfig }:
let
kernel = pkgs.linuxManualConfig
(
let
majorv = "6";
minorv = "3";
mversion = "${majorv}.${minorv}";
msha256 = "sha256-ujSR9e1r0nCjcMRAQ049aQhfzdUoki+gHnPXZX23Ox4=";
pversion = "9";
psha256 = "sha256-r6Rkmrwg20YpSKIqayi9ygekT5yNyjML/Qj5HqgERPc=";
suffix = "custom";
llvm = llvmPackages_latest;
in
rec {
inherit lib;
version = "${mversion}.${pversion}";
configfile = kernelConfig;
allowImportFromDerivation = true;
# stdenv settings are copied from firefox
stdenv = overrideCC llvm.stdenv (llvm.stdenv.cc.override { inherit (llvm) bintools; }); # lld link kernel error
src = fetchurl {
name = "linux-${mversion}.tar.xz";
url = "https://mirrors.tuna.tsinghua.edu.cn/kernel/v${majorv}.x/linux-${mversion}.tar.xz";
sha256 = msha256;
};
kernelPatches = [
rec {
name = "mainline";
patch = fetchurl {
name = "${name}.patch";
url = "https://mirrors.tuna.tsinghua.edu.cn/kernel/v${majorv}.x/patch-${version}.xz";
sha256 = psha256;
postFetch = ''
mv $out $out.xz
xz -d $out.xz
'';
};
}
];
extraMakeFlags = [
"LLVM=1"
];
}
);
passthru = {
features = {
iwlwifi = true;
efiBootStub = true;
netfilterRPFilter = true;
ia32Emulation = true;
};
# Adds dependencies needed to edit the config:
# nix-shell '<nixpkgs>' -A linux.configEnv --command 'make nconfig'
configEnv = kernel.overrideAttrs (old: {
nativeBuildInputs = old.nativeBuildInputs or [ ] ++ (with pkgs; [
pkg-config
ncurses
]);
});
passthru = kernel.passthru // (removeAttrs passthru [ "passthru" ]);
};
finalKernel = kernel.overrideAttrs
(old: {
passthru = old.passthru // passthru;
});
in
pkgs.recurseIntoAttrs (pkgs.linuxPackagesFor (finalKernel))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment