diff --git a/kernel/nvidia-oot.nix b/kernel/nvidia-oot.nix index 3b5508d..9947a66 100644 --- a/kernel/nvidia-oot.nix +++ b/kernel/nvidia-oot.nix @@ -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" + # + # 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 < /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 ]; - }; } diff --git a/modules/default.nix b/modules/default.nix index 4a2cd1d..ba79e3d 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -207,15 +207,11 @@ in ''; # For Orin. Unsupported with PREEMPT_RT. - # boot.extraModulePackages = lib.optional - # ( - # !cfg.kernel.realtime - # ) - # config.boot.kernelPackages.nvidia-oot ; - # # FIXME - # # config.boot.kernelPackages.nvgpu - # #config.boot.kernelPackages.nvidia-display-driver - + boot.extraModulePackages = lib.optional + ( + !cfg.kernel.realtime + ) + config.boot.kernelPackages.nvidia-oot ; hardware.firmware = with pkgs.nvidia-jetpack; [ l4t-firmware diff --git a/overlay.nix b/overlay.nix index 32e3e3e..f4f0112 100644 --- a/overlay.nix +++ b/overlay.nix @@ -98,9 +98,7 @@ in tests = prev.callPackages ./pkgs/tests { inherit l4tVersion; }; kernelPackagesOverlay = final: prev: { - # nvidia-display-driver = self.callPackage ./kernel/display-driver.nix { }; - #nvgpu = self.callPackage ./kernel/nvgpu.nix { }; - # nvidia-oot = self.callPackage ./kernel/nvidia-oot.nix { }; + nvidia-oot = self.callPackage ./kernel/nvidia-oot.nix { }; }; kernel = self.callPackage ./kernel { kernelPatches = [ ]; };