This commit is contained in:
TheK0tYaRa 2026-03-26 04:31:31 +02:00
parent 9831a10505
commit ae936d55e3
3 changed files with 172 additions and 40 deletions

View file

@ -2,6 +2,22 @@ final: prev:
let
winePkg = final.wineWow64Packages.full;
sandboxSccacheDir = "/var/cache/sccache/nix-builds/packages";
# Toggle this to switch between shared socketed sccache and per-build daemon mode.
# Shared socketed mode still fails for sandboxed package builds; keep disabled.
useSocketedSccache = false;
sharedSccacheServerUds = "/run/sccache/server.sock";
effectiveSccacheServerUds = if useSocketedSccache then sharedSccacheServerUds else null;
sccacheRuntimeModeSetup = ''
unset SCCACHE_NO_DAEMON
${final.lib.optionalString (effectiveSccacheServerUds != null) ''
export SCCACHE_SERVER_UDS=${final.lib.escapeShellArg effectiveSccacheServerUds}
unset SCCACHE_IDLE_TIMEOUT
''}
${final.lib.optionalString (effectiveSccacheServerUds == null) ''
unset SCCACHE_SERVER_UDS
export SCCACHE_IDLE_TIMEOUT=0
''}
'';
sharedSccacheConfig = final.writeText "sccache.conf" ''
[cache.disk]
dir = "${sandboxSccacheDir}"
@ -82,9 +98,10 @@ let
{
name,
sccacheDir ? null,
sccacheServerUds ? null,
sccacheServerUds ? effectiveSccacheServerUds,
sccacheCacheSize ? "100G",
noDaemon ? false,
bypassIfCmakeLauncher ? false,
passthroughWrappedCompiler ? false,
extraSetup ? "",
}:
@ -125,6 +142,16 @@ let
return 1
}
has_cmake_compiler_launcher() {
[ -n "''${CMAKE_C_COMPILER_LAUNCHER:-}" ] \
|| [ -n "''${CMAKE_CXX_COMPILER_LAUNCHER:-}" ] \
|| [ -n "''${CMAKE_Fortran_COMPILER_LAUNCHER:-}" ] \
|| [ -n "''${CMAKE_CUDA_COMPILER_LAUNCHER:-}" ] \
|| [ -n "''${CMAKE_HIP_COMPILER_LAUNCHER:-}" ] \
|| [ -n "''${CMAKE_OBJC_COMPILER_LAUNCHER:-}" ] \
|| [ -n "''${CMAKE_OBJCXX_COMPILER_LAUNCHER:-}" ]
}
export SCCACHE_CONF=${final.lib.escapeShellArg effectiveSccacheConfig}
mkdir -p ${final.lib.escapeShellArg sandboxSccacheDir}
unset SCCACHE_START_SERVER
@ -135,15 +162,24 @@ let
${final.lib.optionalString (!noDaemon && sccacheServerUds != null) ''
export SCCACHE_SERVER_UDS=${final.lib.escapeShellArg sccacheServerUds}
''}
${final.lib.optionalString (!noDaemon && sccacheServerUds == null) ''
unset SCCACHE_SERVER_UDS
unset SCCACHE_NO_DAEMON
''}
${extraSetup}
if [ "$#" -eq 0 ] || [ "''${1#-}" != "$1" ]; then
if [ "$#" -eq 0 ]; then
exit 0
fi
if [ "''${1#-}" != "$1" ]; then
exec ${final.sccache}/bin/sccache "$@"
fi
compiler="$1"
shift
if [ "''${SCCACHE_WRAPPED_COMPILER_PASSTHROUGH:-}" = 1 ] || {
if [ "''${SCCACHE_WRAPPED_COMPILER_PASSTHROUGH:-}" = 1 ] \
|| { [ ${if bypassIfCmakeLauncher then "1" else "0"} -eq 1 ] && has_cmake_compiler_launcher; } \
|| {
is_cmake_derivation && is_cmake_probe_invocation "$@"
}; then
exec "$compiler" "$@"
@ -163,25 +199,12 @@ let
preConfigure = (old.preConfigure or "") + ''
mkdir -p ${final.lib.escapeShellArg sandboxSccacheDir}
export SCCACHE_SERVER_UDS="$TMPDIR/sccache/server.sock"
export SCCACHE_IDLE_TIMEOUT=0
unset SCCACHE_NO_DAEMON
mkdir -p "$(dirname "$SCCACHE_SERVER_UDS")"
if ! ${buildSccacheLauncher}/bin/build-sccache --show-stats >/dev/null 2>&1; then
rm -f "$SCCACHE_SERVER_UDS"
if ! ${buildSccacheLauncher}/bin/build-sccache --start-server >/tmp/sccache-start.log 2>&1; then
if ! grep -Fq "Address already in use" /tmp/sccache-start.log; then
cat /tmp/sccache-start.log >&2
exit 1
fi
fi
fi
${sccacheRuntimeModeSetup}
'';
postBuild = (old.postBuild or "") + ''
${buildSccacheLauncher}/bin/build-sccache --show-stats --stats-format text || true
${buildSccacheLauncher}/bin/build-sccache --stop-server || true
'';
};
mkCmakeSccacheAttrs =
@ -203,19 +226,7 @@ let
preConfigure = (old.preConfigure or "") + ''
mkdir -p ${final.lib.escapeShellArg sandboxSccacheDir}
export SCCACHE_WRAPPED_COMPILER_PASSTHROUGH=1
export SCCACHE_SERVER_UDS="$TMPDIR/sccache/server.sock"
export SCCACHE_IDLE_TIMEOUT=0
unset SCCACHE_NO_DAEMON
mkdir -p "$(dirname "$SCCACHE_SERVER_UDS")"
if ! ${sccacheLauncher}/bin/cmake-sccache --show-stats >/dev/null 2>&1; then
rm -f "$SCCACHE_SERVER_UDS"
if ! ${sccacheLauncher}/bin/cmake-sccache --start-server >/tmp/sccache-start.log 2>&1; then
if ! grep -Fq "Address already in use" /tmp/sccache-start.log; then
cat /tmp/sccache-start.log >&2
exit 1
fi
fi
fi
${sccacheRuntimeModeSetup}
'';
postConfigure = (old.postConfigure or "") + ''
@ -225,9 +236,24 @@ let
postBuild = (old.postBuild or "") + ''
${sccacheLauncher}/bin/cmake-sccache --show-stats --stats-format text || true
${sccacheLauncher}/bin/cmake-sccache --stop-server || true
'';
};
mkCmakeSccacheWithLlvmTargetAttrs =
llvmTarget: old:
let
base = mkCmakeSccacheAttrs old;
targetFlag = "-DLLVM_TARGETS_TO_BUILD=${llvmTarget}";
hasTargetFlag = flag: final.lib.hasPrefix "-DLLVM_TARGETS_TO_BUILD=" flag;
replacedFlags = map (flag: if hasTargetFlag flag then targetFlag else flag) (
base.cmakeFlags or [ ]
);
withTargetFlag =
replacedFlags ++ final.lib.optional (!(final.lib.any hasTargetFlag replacedFlags)) targetFlag;
in
base
// {
cmakeFlags = withTargetFlag;
};
mkSccacheExtraConfig =
{
sccacheDir ? sandboxSccacheDir,
@ -242,8 +268,7 @@ let
size = "100G"
''
)}
export SCCACHE_NO_DAEMON=1
unset SCCACHE_SERVER_UDS
${sccacheRuntimeModeSetup}
${extraConfig}
'';
mkWrappedCcForSccache =
@ -302,7 +327,7 @@ in
let
sccacheLauncher = mkSccacheLauncher {
name = "wrapped-sccache";
noDaemon = true;
bypassIfCmakeLauncher = true;
extraSetup = extraConfig;
};
in
@ -410,6 +435,17 @@ in
intel-sycl = modify prev.intel-sycl (
syFinal: syPrev:
let
llvmTargetForHost =
if syFinal.stdenv.hostPlatform.isx86_64 || syFinal.stdenv.hostPlatform.isi686 then
"X86"
else if syFinal.stdenv.hostPlatform.isAarch64 then
"AArch64"
else if syFinal.stdenv.hostPlatform.isRiscV64 then
"RISCV"
else if syFinal.stdenv.hostPlatform.isPower64 then
"PowerPC"
else
"Native";
sccacheWrappedDpcpp = final.sccache.links {
unwrappedCC = syFinal.dpcpp-compat;
extraConfig = mkSccacheExtraConfig { };
@ -427,8 +463,8 @@ in
});
in
{
llvm = modify syPrev.llvm mkCmakeSccacheAttrs;
lld = modify syPrev.lld mkCmakeSccacheAttrs;
llvm = modify syPrev.llvm (mkCmakeSccacheWithLlvmTargetAttrs llvmTargetForHost);
lld = modify syPrev.lld (mkCmakeSccacheWithLlvmTargetAttrs llvmTargetForHost);
stdenv = sccacheStdenv;
compatStdenv = sccacheWrappedCompatStdenv;
}
@ -760,6 +796,35 @@ in
};
torchDir = intelHwSrc + /pkgs/by-lang/intel-python/torch;
torchFn = import torchDir;
torchSyclRoot =
let
intelSyclLlvm = final."intel-sycl".llvm;
intelSyclDev = final.lib.getDev intelSyclLlvm;
intelSyclLib = final.lib.getLib intelSyclLlvm;
in
final.runCommand "torch-sycl-root" { } ''
mkdir -p "$out/bin" "$out/include" "$out/lib"
ln -s ${final."intel-sycl".stdenv.cc}/bin/clang "$out/bin/clang"
ln -s ${final."intel-sycl".stdenv.cc}/bin/clang++ "$out/bin/clang++"
ln -s clang "$out/bin/icx"
ln -s clang++ "$out/bin/icpx"
for path in ${intelSyclDev}/include/*; do
ln -s "$path" "$out/include/"
done
for path in ${intelSyclLib}/lib/libsycl*.so*; do
ln -s "$path" "$out/lib/"
done
ln -s ${final.ocl-icd}/lib/libOpenCL.so "$out/lib/libOpenCL.so"
ln -s ${final.ocl-icd}/lib/libOpenCL.so.1 "$out/lib/libOpenCL.so.1"
'';
torchCmakeSccache = mkSccacheLauncher {
name = "torch-cmake-sccache";
passthroughWrappedCompiler = true;
};
in
(torchFn {
inherit (final)
@ -815,13 +880,70 @@ in
inherit (final) git-unroll binutils;
}).overrideAttrs
(old: {
nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ [
final.shaderc
final.glibc.bin
torchCmakeSccache
];
buildInputs = (old.buildInputs or [ ]) ++ [
final.vulkan-headers
final.vulkan-loader
final.shaderc
];
postPatch = (old.postPatch or "") + ''
substituteInPlace cmake/Modules/FindOpenMP.cmake \
--replace-fail 'set(OMP_FLAG_Clang "-fopenmp=libomp" "-fopenmp=libiomp5" "-fopenmp")' \
'set(OMP_FLAG_Clang "-fopenmp=libomp -I''${OpenMP_PREFIX}/include" "-fopenmp=libiomp5 -I''${OpenMP_PREFIX}/include" "-fopenmp -I''${OpenMP_PREFIX}/include" "-fopenmp=libomp" "-fopenmp=libiomp5" "-fopenmp")'
'';
preBuild = ''
export MAX_JOBS=$NIX_BUILD_CORES
mkdir -p ${final.lib.escapeShellArg sandboxSccacheDir}
export SCCACHE_CONF=${final.lib.escapeShellArg sharedSccacheConfig}
${sccacheRuntimeModeSetup}
export SYCL_ROOT=${final.lib.escapeShellArg torchSyclRoot}
export CMPLR_ROOT=${final.lib.escapeShellArg torchSyclRoot}
export LD_LIBRARY_PATH="$SYCL_ROOT/lib''${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
export CMAKE_C_COMPILER_LAUNCHER=${torchCmakeSccache}/bin/torch-cmake-sccache
export CMAKE_CXX_COMPILER_LAUNCHER=${torchCmakeSccache}/bin/torch-cmake-sccache
omp_lib_dir=
for dep in $buildInputs $nativeBuildInputs; do
if [ -f "$dep/include/omp.h" ]; then
export OMP_PREFIX="$dep"
export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -I$dep/include"
export CFLAGS="$CFLAGS -I$dep/include"
export CXXFLAGS="$CXXFLAGS -I$dep/include"
if [ -f "$dep/nix-support/propagated-build-inputs" ]; then
for propagated in $(cat "$dep/nix-support/propagated-build-inputs"); do
if [ -f "$propagated/lib/libomp.so" ] || [ -f "$propagated/lib/libiomp5.so" ]; then
omp_lib_dir="$propagated/lib"
break
fi
done
fi
break
fi
done
if [ -n "$omp_lib_dir" ]; then
export LIBRARY_PATH="$omp_lib_dir''${LIBRARY_PATH:+:$LIBRARY_PATH}"
export NIX_LDFLAGS="$NIX_LDFLAGS -L$omp_lib_dir -Wl,-rpath,$omp_lib_dir"
export LDFLAGS="$LDFLAGS -L$omp_lib_dir -Wl,-rpath,$omp_lib_dir"
fi
export SCCACHE_WRAPPED_COMPILER_PASSTHROUGH=1
python setup.py build --cmake-only
unset SCCACHE_WRAPPED_COMPILER_PASSTHROUGH
cmake --build build
'';
postBuild = (old.postBuild or "") + ''
${torchCmakeSccache}/bin/torch-cmake-sccache --show-stats --stats-format text || true
'';
env = (old.env or { }) // {
SYCL_ROOT = "${torchSyclRoot}";
CMPLR_ROOT = "${torchSyclRoot}";
USE_VULKAN = "1";
USE_OPENCL = "1";
USE_XCCL = "0";
USE_OPENMP = "1";
VULKAN_SDK = "${final.shaderc}";
USE_CUDNN = "0";
@ -916,7 +1038,17 @@ in
cmakeSccacheAttrs
// {
cmakeFlags = (cmakeSccacheAttrs.cmakeFlags or [ ]) ++ [
(prev.lib.cmakeBool "NEO_ENABLE_XE" true)
(prev.lib.cmakeBool "DISABLE_WDDM_LINUX" true)
(prev.lib.cmakeBool "NEO_ENABLE_I915_PRELIM_DETECTION" false)
(prev.lib.cmakeBool "NEO_ENABLE_XE_PRELIM_DETECTION" false)
(prev.lib.cmakeBool "SUPPORT_GEN12LP" false)
(prev.lib.cmakeBool "SUPPORT_XE_HPG_CORE" false)
(prev.lib.cmakeBool "SUPPORT_XE_HPC_CORE" false)
(prev.lib.cmakeBool "SUPPORT_XE3_CORE" false)
(prev.lib.cmakeBool "SUPPORT_XE3P_CORE" false)
(prev.lib.cmakeBool "SUPPORT_XE2_HPG_CORE" true)
(prev.lib.cmakeBool "SUPPORT_LNL" false)
(prev.lib.cmakeBool "SUPPORT_BMG" true)
];
buildInputs = (old.buildInputs or [ ]) ++ [ kernelHeaders ];
postPatch = (old.postPatch or "") + ''

View file

@ -127,7 +127,7 @@
"root"
"thek0tyara"
];
sandbox = "relaxed";
sandbox = true;
extra-sandbox-paths = [
"/run/sccache"
"/var/cache/sccache"

View file

@ -104,7 +104,7 @@
# kdePackages.kdenlive
(python313.withPackages (
py: with py; [
torch
# torch
# triton-xpu
#
huggingface-hub