forked from anduril/jetpack-nixos
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Tanel Dettenborn <[email protected]>
- Loading branch information
Tanel Dettenborn
committed
Oct 30, 2024
1 parent
0207766
commit 3602353
Showing
3 changed files
with
76 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,85 @@ | ||
# TODO: Should try to merge with upstream nixpkgs's open.nix nvidia driver | ||
{ stdenv | ||
, lib | ||
, kernel | ||
, gitRepos | ||
, l4tVersion | ||
{ | ||
stdenv, | ||
kernel, | ||
runCommand, | ||
fetchurl, | ||
lib, | ||
buildPackages | ||
}: | ||
let | ||
src = fetchurl { | ||
url = "https://developer.nvidia.com/downloads/embedded/l4t/r36_release_v3.0/sources/public_sources.tbz2"; | ||
hash = "sha256-6U2+ACWuMT7rYDBhaXr+13uWQdKgbfAiiIV0Vi3R9sU="; | ||
}; | ||
|
||
source = runCommand "source" { } '' | ||
tar xf ${src} | ||
cd Linux_for_Tegra/source | ||
mkdir $out | ||
tar -C $out -xf kernel_oot_modules_src.tbz2 | ||
tar -C $out -xf nvidia_kernel_display_driver_source.tbz2 | ||
''; | ||
|
||
stdenv.mkDerivation rec { | ||
# unclear why we need this, but some part of nvidia's conftest doesn't pick up the headers otherwise | ||
kernelIncludes = x: [ | ||
"${kernel.dev}/lib/modules/${kernel.modDirVersion}/source/include" | ||
"${kernel.dev}/lib/modules/${kernel.modDirVersion}/source/arch/${stdenv.hostPlatform.linuxArch}/include" | ||
"${kernel.dev}/lib/modules/${kernel.modDirVersion}/source/include/uapi/" | ||
"${kernel.dev}/lib/modules/${kernel.modDirVersion}/source/arch/${stdenv.hostPlatform.linuxArch}/include/uapi/" | ||
]; | ||
in | ||
stdenv.mkDerivation { | ||
pname = "nvidia-oot"; | ||
version = "jetson_${l4tVersion}"; | ||
inherit (kernel) version; | ||
|
||
src = gitRepos."nvidia-oot"; | ||
src = source; | ||
# Patch created like that: | ||
# nix-build ./packages.nix -A nvidia-oot-cross.src | ||
# mkdir source | ||
# cp -r result/* source | ||
# chmod -R +w source | ||
# cd source | ||
# git init . | ||
# git add . | ||
# git commit -m "Initial commit" | ||
# <make changes> | ||
# git diff > ../0001-build-fixes.patch | ||
patches = [ ./0001-build-fixes.patch ]; | ||
|
||
#setSourceRoot = "sourceRoot=$(echo /build/linux-nv-oot-*)"; | ||
sourceRoot="linux-nv-oot-564ce2a"; | ||
postUnpack = '' | ||
# make kernel headers readable for the nvidia build system. | ||
cp -r ${kernel.dev} linux-dev | ||
chmod -R u+w linux-dev | ||
export KERNEL_HEADERS=$(pwd)/linux-dev/lib/modules/${kernel.modDirVersion}/build | ||
nativeBuildInputs = kernel.moduleBuildDependencies; | ||
''; | ||
|
||
# makeFlags = kernel.makeFlags ++ [ | ||
makeFlags = [ | ||
"SYSSRC=${kernel.dev}/lib/modules/${kernel.modDirVersion}/source" | ||
"SYSOUT=${kernel.dev}/lib/modules/${kernel.modDirVersion}/build" | ||
"MODLIB=$(out)/lib/modules/${kernel.modDirVersion}" | ||
"O=${kernel.dev}/lib/modules/${kernel.modDirVersion}/source" | ||
] ++ lib.optionals ((stdenv.buildPlatform != stdenv.hostPlatform) && stdenv.hostPlatform.isAarch64) [ | ||
"TARGET_ARCH=aarch64" | ||
]; | ||
nativeBuildInputs = kernel.moduleBuildDependencies ++ [ ]; | ||
|
||
# Avoid an error in modpost: "__stack_chk_guard" [.../nvidia.ko] undefined | ||
# NIX_CFLAGS_COMPILE = "-fno-stack-protector"; | ||
# some calls still go to `gcc` in the build | ||
depsBuildBuild = [ buildPackages.stdenv.cc ]; | ||
|
||
postUnpack = '' | ||
cd linux-nv-oot-564ce2a | ||
sourceRoot=$(pwd -P) | ||
cat >> Makefile <<EOF | ||
makeFlags = | ||
[ | ||
"ARCH=${stdenv.hostPlatform.linuxArch}" | ||
"INSTALL_MOD_PATH=${placeholder "out"}" | ||
"modules" | ||
] | ||
++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ | ||
"CROSS_COMPILE=${stdenv.cc}/bin/${stdenv.cc.targetPrefix}" | ||
]; | ||
|
||
all: | ||
env > /dev/stdout | ||
make -C $SYSOUT | ||
CROSS_COMPILE = lib.optionalString ( | ||
stdenv.hostPlatform != stdenv.buildPlatform | ||
) "${stdenv.cc}/bin/${stdenv.cc.targetPrefix}"; | ||
|
||
clean: | ||
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean | ||
hardeningDisable = [ "pic" ]; | ||
|
||
EOF | ||
''; | ||
preBuildPhase = '' | ||
echo prebuildphase | ||
''; | ||
# unclear why we need to add nvidia-oot/sound/soc/tegra-virt-alt/include | ||
# this only happens in the nix-sandbox and not in the nix-shell | ||
NIX_CFLAGS_COMPILE = "-fno-stack-protector -Wno-error=attribute-warning -I ${source}/nvidia-oot/sound/soc/tegra-virt-alt/include ${ | ||
lib.concatMapStrings (x: "-isystem ${x} ") (kernelIncludes kernel.dev) | ||
}"; | ||
|
||
installTargets = [ "modules_install" ]; | ||
enableParallelBuilding = true; | ||
|
||
passthru.meta = { | ||
license = with lib.licenses; [ mit /* OR */ gpl2Only ]; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters