diff --git a/bleeding/jaxlib/default.nix b/bleeding/jaxlib/default.nix new file mode 100644 index 0000000..c7c2e55 --- /dev/null +++ b/bleeding/jaxlib/default.nix @@ -0,0 +1,460 @@ +{ + lib, + pkgs, + stdenv, + + # Build-time dependencies: + addOpenGLRunpath, + autoAddDriverRunpath, + bazel_6, + binutils, + buildBazelPackage, + buildPythonPackage, + curl, + cython, + fetchFromGitHub, + git, + jsoncpp, + nsync, + openssl, + pybind11, + setuptools, + symlinkJoin, + wheel, + build, + which, + + # Python dependencies: + absl-py, + flatbuffers, + ml-dtypes, + numpy, + scipy, + six, + + # Runtime dependencies: + double-conversion, + giflib, + libjpeg_turbo, + python, + snappy, + zlib, + + config, + # CUDA flags: + cudaSupport ? config.cudaSupport, + cudaPackages, + + # MKL: + mklSupport ? true, +}@inputs: + +let + inherit (cudaPackages) + cudaFlags + cudaVersion + cudnn + nccl + ; + + pname = "jaxlib"; + version = "0.4.28"; + + # It's necessary to consistently use backendStdenv when building with CUDA + # support, otherwise we get libstdc++ errors downstream + stdenv = throw "Use effectiveStdenv instead"; + effectiveStdenv = if cudaSupport then cudaPackages.backendStdenv else inputs.stdenv; + + meta = with lib; { + description = "JAX is Autograd and XLA, brought together for high-performance machine learning research."; + homepage = "https://github.com/google/jax"; + license = licenses.asl20; + maintainers = with maintainers; [ ndl ]; + platforms = platforms.unix; + # aarch64-darwin is broken because of https://github.com/bazelbuild/rules_cc/pull/136 + # however even with that fix applied, it doesn't work for everyone: + # https://github.com/NixOS/nixpkgs/pull/184395#issuecomment-1207287129 + # NOTE: We always build with NCCL; if it is unsupported, then our build is broken. + broken = effectiveStdenv.isDarwin || nccl.meta.unsupported; + }; + + # These are necessary at build time and run time. + cuda_libs_joined = symlinkJoin { + name = "cuda-joined"; + paths = with cudaPackages; [ + cuda_cudart.lib # libcudart.so + cuda_cudart.static # libcudart_static.a + cuda_cupti.lib # libcupti.so + libcublas.lib # libcublas.so + libcufft.lib # libcufft.so + libcurand.lib # libcurand.so + libcusolver.lib # libcusolver.so + libcusparse.lib # libcusparse.so + ]; + }; + # These are only necessary at build time. + cuda_build_deps_joined = symlinkJoin { + name = "cuda-build-deps-joined"; + paths = with cudaPackages; [ + cuda_libs_joined + + # Binaries + cudaPackages.cuda_nvcc.bin # nvcc + + # Headers + cuda_cccl.dev # block_load.cuh + cuda_cudart.dev # cuda.h + cuda_cupti.dev # cupti.h + cuda_nvcc.dev # See https://github.com/google/jax/issues/19811 + cuda_nvml_dev # nvml.h + cuda_nvtx.dev # nvToolsExt.h + libcublas.dev # cublas_api.h + libcufft.dev # cufft.h + libcurand.dev # curand.h + libcusolver.dev # cusolver_common.h + libcusparse.dev # cusparse.h + ]; + }; + + backend_cc_joined = symlinkJoin { + name = "cuda-cc-joined"; + paths = [ + effectiveStdenv.cc + binutils.bintools # for ar, dwp, nm, objcopy, objdump, strip + ]; + }; + + # Copy-paste from TF derivation. + # Most of these are not really used in jaxlib compilation but it's simpler to keep it + # 'as is' so that it's more compatible with TF derivation. + tf_system_libs = [ + "absl_py" + "astor_archive" + "astunparse_archive" + # Not packaged in nixpkgs + # "com_github_googleapis_googleapis" + # "com_github_googlecloudplatform_google_cloud_cpp" + # Issue with transitive dependencies after https://github.com/grpc/grpc/commit/f1d14f7f0b661bd200b7f269ef55dec870e7c108 + # "com_github_grpc_grpc" + # ERROR: /build/output/external/bazel_tools/tools/proto/BUILD:25:6: no such target '@com_google_protobuf//:cc_toolchain': + # target 'cc_toolchain' not declared in package '' defined by /build/output/external/com_google_protobuf/BUILD.bazel + # "com_google_protobuf" + # Fails with the error: external/org_tensorflow/tensorflow/core/profiler/utils/tf_op_utils.cc:46:49: error: no matching function for call to 're2::RE2::FullMatch(absl::lts_2020_02_25::string_view&, re2::RE2&)' + # "com_googlesource_code_re2" + "curl" + "cython" + "dill_archive" + "double_conversion" + "flatbuffers" + "functools32_archive" + "gast_archive" + "gif" + "hwloc" + "icu" + "jsoncpp_git" + "libjpeg_turbo" + "lmdb" + "nasm" + "opt_einsum_archive" + "org_sqlite" + "pasta" + "png" + # ERROR: /build/output/external/pybind11/BUILD.bazel: no such target '@pybind11//:osx': + # target 'osx' not declared in package '' defined by /build/output/external/pybind11/BUILD.bazel + # "pybind11" + "six_archive" + "snappy" + "tblib_archive" + "termcolor_archive" + "typing_extensions_archive" + "wrapt" + "zlib" + ]; + + arch = + # KeyError: ('Linux', 'arm64') + if effectiveStdenv.hostPlatform.isLinux && effectiveStdenv.hostPlatform.linuxArch == "arm64" then + "aarch64" + else + effectiveStdenv.hostPlatform.linuxArch; + + xla = effectiveStdenv.mkDerivation { + pname = "xla-src"; + version = "unstable"; + + src = fetchFromGitHub { + owner = "openxla"; + repo = "xla"; + # Update this according to https://github.com/google/jax/blob/jaxlib-v${version}/third_party/xla/workspace.bzl. + rev = "e8247c3ea1d4d7f31cf27def4c7ac6f2ce64ecd4"; + hash = "sha256-ZhgMIVs3Z4dTrkRWDqaPC/i7yJz2dsYXrZbjzqvPX3E="; + }; + + dontBuild = true; + + # This is necessary for patchShebangs to know the right path to use. + nativeBuildInputs = [ python ]; + + # Main culprits we're targeting are third_party/tsl/third_party/gpus/crosstool/clang/bin/*.tpl + postPatch = '' + patchShebangs . + ''; + + installPhase = '' + cp -r . $out + ''; + }; + + bazel-build = buildBazelPackage rec { + name = "bazel-build-${pname}-${version}"; + + # See https://github.com/google/jax/blob/main/.bazelversion for the latest. + bazel = bazel_6; + + src = fetchFromGitHub { + owner = "google"; + repo = "jax"; + # google/jax contains tags for jax and jaxlib. Only use jaxlib tags! + rev = "refs/tags/${pname}-v${version}"; + hash = "sha256-qSHPwi3is6Ts7pz5s4KzQHBMbcjGp+vAOsejW3o36Ek="; + }; + + nativeBuildInputs = [ + cython + pkgs.flatbuffers + git + setuptools + wheel + build + which + ]; + + buildInputs = + [ + curl + double-conversion + giflib + jsoncpp + libjpeg_turbo + numpy + openssl + pkgs.flatbuffers + pkgs.protobuf + pybind11 + scipy + six + snappy + zlib + nsync + ]; + + # We don't want to be quite so picky regarding bazel version + postPatch = '' + rm -f .bazelversion + ''; + + bazelRunTarget = "//jaxlib/tools:build_wheel"; + runTargetFlags = [ + "--output_path=$out" + "--cpu=${arch}" + # This has no impact whatsoever... + "--jaxlib_git_hash='12345678'" + ]; + + removeRulesCC = false; + + GCC_HOST_COMPILER_PREFIX = lib.optionalString cudaSupport "${backend_cc_joined}/bin"; + GCC_HOST_COMPILER_PATH = lib.optionalString cudaSupport "${backend_cc_joined}/bin/gcc"; + + # The version is automatically set to ".dev" if this variable is not set. + # https://github.com/google/jax/commit/e01f2617b85c5bdffc5ffb60b3d8d8ca9519a1f3 + JAXLIB_RELEASE = "1"; + + preConfigure = + # Dummy ldconfig to work around "Can't open cache file /nix/store/-glibc-2.38-44/etc/ld.so.cache" error + '' + mkdir dummy-ldconfig + echo "#!${effectiveStdenv.shell}" > dummy-ldconfig/ldconfig + chmod +x dummy-ldconfig/ldconfig + export PATH="$PWD/dummy-ldconfig:$PATH" + '' + + + + # Construct .jax_configure.bazelrc. See https://github.com/google/jax/blob/b9824d7de3cb30f1df738cc42e486db3e9d915ff/build/build.py#L259-L345 + # for more info. We assume + # * `cpu = None` + # * `enable_nccl = True` + # * `target_cpu_features = "release"` + # * `rocm_amdgpu_targets = None` + # * `enable_rocm = False` + # * `build_gpu_plugin = False` + # * `use_clang = False` (Should we use `effectiveStdenv.cc.isClang` instead?) + # + # Note: We should try just running https://github.com/google/jax/blob/ceb198582b62b9e6f6bdf20ab74839b0cf1db16e/build/build.py#L259-L266 + # instead of duplicating the logic here. Perhaps we can leverage the + # `--configure_only` flag (https://github.com/google/jax/blob/ceb198582b62b9e6f6bdf20ab74839b0cf1db16e/build/build.py#L544-L548)? + '' + cat < ./.jax_configure.bazelrc + build --strategy=Genrule=standalone + build --repo_env PYTHON_BIN_PATH="${python}/bin/python" + build --action_env=PYENV_ROOT + build --python_path="${python}/bin/python" + build --distinct_host_configuration=false + build --define PROTOBUF_INCLUDE_PATH="${pkgs.protobuf}/include" + '' + + lib.optionalString cudaSupport '' + build --config=cuda + build --action_env CUDA_TOOLKIT_PATH="${cuda_build_deps_joined}" + build --action_env CUDNN_INSTALL_PATH="${cudnn}" + build --action_env TF_CUDA_PATHS="${cuda_build_deps_joined},${cudnn},${nccl}" + build --action_env TF_CUDA_VERSION="${lib.versions.majorMinor cudaVersion}" + build --action_env TF_CUDNN_VERSION="${lib.versions.major cudnn.version}" + build:cuda --action_env TF_CUDA_COMPUTE_CAPABILITIES="${builtins.concatStringsSep "," cudaFlags.realArches}" + '' + + + # Note that upstream conditions this on `wheel_cpu == "x86_64"`. We just + # rely on `effectiveStdenv.hostPlatform.avxSupport` instead. So far so + # good. See https://github.com/google/jax/blob/b9824d7de3cb30f1df738cc42e486db3e9d915ff/build/build.py#L322 + # for upstream's version. + lib.optionalString (effectiveStdenv.hostPlatform.avxSupport && effectiveStdenv.hostPlatform.isUnix) + '' + build --config=avx_posix + '' + + lib.optionalString mklSupport '' + build --config=mkl_open_source_only + '' + + '' + CFG + ''; + + # Make sure Bazel knows about our configuration flags during fetching so that the + # relevant dependencies can be downloaded. + bazelFlags = + [ + "-c opt" + # See https://bazel.build/external/advanced#overriding-repositories for + # information on --override_repository flag. + "--override_repository=xla=${xla}" + ] + ++ lib.optionals effectiveStdenv.cc.isClang [ + # bazel depends on the compiler frontend automatically selecting these flags based on file + # extension but our clang doesn't. + # https://github.com/NixOS/nixpkgs/issues/150655 + "--cxxopt=-x" + "--cxxopt=c++" + "--host_cxxopt=-x" + "--host_cxxopt=c++" + ]; + + # We intentionally overfetch so we can share the fetch derivation across all the different configurations + fetchAttrs = { + TF_SYSTEM_LIBS = lib.concatStringsSep "," tf_system_libs; + # we have to force @mkl_dnn_v1 since it's not needed on darwin + bazelTargets = [ + bazelRunTarget + "@mkl_dnn_v1//:mkl_dnn" + ]; + bazelFlags = + bazelFlags + ++ [ + "--config=avx_posix" + "--config=mkl_open_source_only" + ] + ++ lib.optionals cudaSupport [ + # ideally we'd add this unconditionally too, but it doesn't work on darwin + # we make this conditional on `cudaSupport` instead of the system, so that the hash for both + # the cuda and the non-cuda deps can be computed on linux, since a lot of contributors don't + # have access to darwin machines + "--config=cuda" + ]; + + sha256 = + ( + if cudaSupport then + { x86_64-linux = "sha256-zu+nS+YkmPg2haxUGqOsU+MEH3l0urSzM87N3wkQZSA="; } + else + { + x86_64-linux = "sha256-R5Bm+0GYN1zJ1aEUBW76907MxYKAIawHHJoIb1RdsKE="; + aarch64-linux = "sha256-P5JEmJljN1DeRA0dNkzyosKzRnJH+5SD2aWdV5JsoiY="; + } + ).${effectiveStdenv.system} or (throw "jaxlib: unsupported system: ${effectiveStdenv.system}"); + }; + + buildAttrs = { + outputs = [ "out" ]; + + TF_SYSTEM_LIBS = lib.concatStringsSep "," ( + tf_system_libs + ++ lib.optionals (!effectiveStdenv.isDarwin) [ + "nsync" # fails to build on darwin + ] + ); + }; + + inherit meta; + }; + platformTag = + if effectiveStdenv.hostPlatform.isLinux then + "manylinux2014_${arch}" + else if effectiveStdenv.system == "x86_64-darwin" then + "macosx_10_9_${arch}" + else if effectiveStdenv.system == "aarch64-darwin" then + "macosx_11_0_${arch}" + else + throw "Unsupported target platform: ${effectiveStdenv.hostPlatform}"; +in +buildPythonPackage { + inherit meta pname version; + format = "wheel"; + + src = + let + cp = "cp${builtins.replaceStrings [ "." ] [ "" ] python.pythonVersion}"; + in + "${bazel-build}/jaxlib-${version}-${cp}-${cp}-${platformTag}.whl"; + + # Note that jaxlib looks for "ptxas" in $PATH. See https://github.com/NixOS/nixpkgs/pull/164176#discussion_r828801621 + # for more info. + postInstall = lib.optionalString cudaSupport '' + mkdir -p $out/bin + ln -s ${cudaPackages.cuda_nvcc.bin}/bin/ptxas $out/bin/ptxas + + find $out -type f \( -name '*.so' -or -name '*.so.*' \) | while read lib; do + patchelf --add-rpath "${ + lib.makeLibraryPath [ + cuda_libs_joined + cudnn + nccl + ] + }" "$lib" + done + ''; + + nativeBuildInputs = lib.optionals cudaSupport [ autoAddDriverRunpath ]; + + dependencies = [ + absl-py + curl + double-conversion + flatbuffers + giflib + jsoncpp + libjpeg_turbo + ml-dtypes + numpy + scipy + six + snappy + ]; + + pythonImportsCheck = [ + "jaxlib" + # `import jaxlib` loads surprisingly little. These imports are actually bugs that appeared in the 0.4.11 upgrade. + "jaxlib.cpu_feature_guard" + "jaxlib.xla_client" + ]; + + # Without it there are complaints about libcudart.so.11.0 not being found + # because RPATH path entries added above are stripped. + dontPatchELF = cudaSupport; +} diff --git a/flake.lock b/flake.lock index 86e651c..020d367 100644 --- a/flake.lock +++ b/flake.lock @@ -2,11 +2,11 @@ "nodes": { "nixpkgs": { "locked": { - "lastModified": 1716542732, - "narHash": "sha256-0Y9fRr0CUqWT4KgBITmaGwlnNIGMYuydu2L8iLTfHU4=", + "lastModified": 1731239293, + "narHash": "sha256-q2yjIWFFcTzp5REWQUOU9L6kHdCDmFDpqeix86SOvDc=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "d12251ef6e8e6a46e05689eeccd595bdbd3c9e60", + "rev": "9256f7c71a195ebe7a218043d9f93390d49e6884", "type": "github" }, "original": { @@ -22,13 +22,31 @@ "utils": "utils" } }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, "utils": { + "inputs": { + "systems": "systems" + }, "locked": { - "lastModified": 1623875721, - "narHash": "sha256-A8BU7bjS5GirpAUv4QA+QnJ4CceLHkcXdRp4xITDB0s=", + "lastModified": 1726560853, + "narHash": "sha256-X6rJYSESBVr3hBoH0WbKE5KvhPU5bloyZ2L4K60/fPQ=", "owner": "numtide", "repo": "flake-utils", - "rev": "f7e004a55b120c02ecb6219596820fcd32ca8772", + "rev": "c1dfcf08411b08f6b8615f7d8971a2bfa81d5e8a", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index e6f0b41..719b818 100644 --- a/flake.nix +++ b/flake.nix @@ -3,7 +3,6 @@ inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05"; - utils.url = "github:numtide/flake-utils"; }; @@ -14,7 +13,8 @@ torch-family = import ./overlays/torch-family.nix; jax-family = import ./overlays/jax-family.nix; data-utils = import ./overlays/data-utils.nix; - simulators = import ./overlays/simulators.nix; + simulators = import ./overlays/haosu.nix; + haosu = import ./overlays/simulators.nix; math = import ./overlays/math.nix; misc = import ./overlays/misc.nix; apis = import ./overlays/apis.nix; @@ -29,6 +29,7 @@ self.overlays.jax-family self.overlays.data-utils self.overlays.simulators + self.overlays.haosu self.overlays.math self.overlays.misc self.overlays.apis @@ -70,10 +71,9 @@ jax = pkgs.callPackage ./pkgs/dev-shell/jax.nix {}; quicktest = pkgs.callPackage ./pkgs/dev-shell/quicktest.nix {}; ddddocr = pkgs.callPackage ./pkgs/dev-shell/ddddocr.nix {}; + maniskill = pkgs.callPackage ./pkgs/dev-shell/maniskill.nix {}; + habitat = pkgs.callPackage ./pkgs/dev-shell/habitat.nix {}; }; - # devShells.py38 = pkgs.callPackage ./pkgs/dev-shell { - # python3 = pkgs.python38; - # }; packages = { inherit (pkgs.python3Packages) @@ -102,7 +102,6 @@ mujoco-menagerie dm-control python-fcl - sapien glfw gputil aws-requests-auth @@ -113,6 +112,21 @@ robosuite robocasa + sapien + maniskill + pytorch-seed + pytorch-kinematics + arm-pytorch-utilities + fast-kinematics + tyro + toppra + mplib + stable-baselines3 + + magnum-bindings + habitat-sim + habitat-lab + # ----- Math ----- numpy-quaternion chumpy @@ -153,7 +167,10 @@ quickcpplib status-code eve - aider-chat; + physx5 + physx5-gpu + sapien-vulkan-2 + ompl; }; apps = { diff --git a/overlays/haosu.nix b/overlays/haosu.nix new file mode 100644 index 0000000..13daecd --- /dev/null +++ b/overlays/haosu.nix @@ -0,0 +1,75 @@ +final: prev: { + pythonPackagesExtensions = prev.pythonPackagesExtensions ++ [ + (python-final: python-prev: { + sapien = python-final.callPackage ../pkgs/sapien {}; + maniskill = python-final.callPackage ../pkgs/maniskill {}; + + pytorch-seed = python-final.callPackage ../pkgs/pytorch-seed { + torch = python-final.torchWithCuda; + }; + pytorch-kinematics = python-final.callPackage ../pkgs/pytorch-kinematics { + torch = python-final.torchWithCuda; + }; + arm-pytorch-utilities = python-final.callPackage ../pkgs/arm-pytorch-utilities { + torch = python-final.torchWithCuda; + }; + fast-kinematics = python-final.callPackage ../pkgs/fast-kinematics { + torch = python-final.torchWithCuda; + }; + toppra = python-final.callPackage ../pkgs/toppra {}; + mplib = python-final.callPackage ../pkgs/mplib {}; + stable-baselines3 = python-final.callPackage ../pkgs/stable-baselines3 {}; + + tyro = python-final.callPackage ../pkgs/tyro {}; + docstring-parser = python-prev.docstring-parser.overrideAttrs rec { + version = "0.16"; + src = final.fetchFromGitHub { + owner = "rr-"; + repo = "docstring_parser"; + rev = "${version}"; + hash = "sha256-xwV+mgCOC/MyCqGELkJVqQ3p2g2yw/Ieomc7k0HMXms="; + }; + }; + + pybind-smart-holder = python-final.pybind11.overrideAttrs { + src = final.fetchFromGitHub { + owner = "pybind"; + repo = "pybind11"; + rev = "3b35ce475fa359abc31d979972f650c601d6158b"; + hash = "sha256-zgWTcgO0BvCOjFrNPrLTi0JXedhW2Oai1qwf5DA7e6A="; + }; + postPatch = ""; + }; + }) + ]; + + physx5-gpu = final.callPackage ../pkgs/physx5-gpu {}; + physx5 = final.callPackage ../pkgs/physx5 {}; + sapien-vulkan-2 = final.callPackage ../pkgs/sapien-vulkan-2 {}; + assimp-sapien = final.assimp.overrideAttrs { + src = final.fetchFromGitHub { + owner = "fbxiang"; + repo = "assimp"; + rev = "0ea31aa6734336dc1e62c6d9bde3e49b6d71b811"; + sha256 = "sha256-IqF46UQNGQ/EZJ/D0SsOqp+Tyn5oSNtunNx0lxaTRGE="; + }; + }; + glm-sapien = final.glm.overrideAttrs { + src = final.fetchFromGitHub { + owner = "g-truc"; + repo = "glm"; + rev = "0.9.9.8"; + hash = "sha256-F//+3L5Ozrw6s7t4LrcUmO7sN30ZSESdrPAYX57zgr8="; + }; + }; + openexr-sapien = final.openexr_3.overrideAttrs { + postFixup = '' + substituteInPlace $dev/include/OpenEXR/*.h \ + --replace-warn '#include = 1.3.1 cereal = final.cereal_1_3_2; + magnum = final.callPackage ../pkgs/magnum {}; + magnum-integration = final.callPackage ../pkgs/magnum-integration {}; + magnum-plugins = final.callPackage ../pkgs/magnum-plugins {}; + corrade = final.callPackage ../pkgs/corrade {}; + basis-universal = final.callPackage ../pkgs/basis-universal {}; + recastnavigation = final.callPackage ../pkgs/recastnavigation {}; } diff --git a/overlays/torch-family.nix b/overlays/torch-family.nix index e743cdc..a0fcecf 100644 --- a/overlays/torch-family.nix +++ b/overlays/torch-family.nix @@ -12,20 +12,20 @@ final: prev: # https://github.com/SomeoneSerge/dust3r.nix/commit/8715f78a6f875fa5a1795da8f56e05fe2b2811d6 # # The proper fix is still a pending PR: https://github.com/NixOS/nixpkgs/pull/297590 - torchWithCuda = python-prev.torchWithCuda.overridePythonAttrs (oldAttrs: { - extraRunpaths = [ "${prev.lib.getLib final.cudaPackages.cuda_nvrtc}/lib" ]; - postPhases = prev.lib.optionals final.stdenv.hostPlatform.isUnix ["postPatchelfPhase" ]; - postPatchelfPhase = '' - while IFS= read -r -d $'\0' elf ; do - for extra in $extraRunpaths ; do - echo patchelf "$elf" --add-rpath "$extra" >&2 - patchelf "$elf" --add-rpath "$extra" - done - done < <( - find "''${!outputLib}" "$out" -type f -iname '*.so' -print0 - ) - ''; - }); + # torchWithCuda = python-prev.torchWithCuda.overridePythonAttrs (oldAttrs: { + # extraRunpaths = [ "${prev.lib.getLib final.cudaPackages.cuda_nvrtc}/lib" ]; + # postPhases = prev.lib.optionals final.stdenv.hostPlatform.isUnix ["postPatchelfPhase" ]; + # postPatchelfPhase = '' + # while IFS= read -r -d $'\0' elf ; do + # for extra in $extraRunpaths ; do + # echo patchelf "$elf" --add-rpath "$extra" >&2 + # patchelf "$elf" --add-rpath "$extra" + # done + # done < <( + # find "''${!outputLib}" "$out" -type f -iname '*.so' -print0 + # ) + # ''; + # }); LIV-robotics = python-final.callPackage ../pkgs/LIV-robotics { pytorch = python-final.torchWithCuda; diff --git a/pkgs/arm-pytorch-utilities/default.nix b/pkgs/arm-pytorch-utilities/default.nix new file mode 100644 index 0000000..18f627e --- /dev/null +++ b/pkgs/arm-pytorch-utilities/default.nix @@ -0,0 +1,45 @@ +{ lib +, pythonOlder +, buildPythonPackage +, fetchFromGitHub +, setuptools +, numpy +, torch +, matplotlib +, pytorch-seed +, scipy +}: + +buildPythonPackage rec { + pname = "arm_pytorch_utilities"; + version = "0.4.3"; + format = "pyproject"; + + src = fetchFromGitHub { + owner = "UM-ARM-Lab"; + repo = pname; + rev = "6312d5094f71a646041fa2994663a19f052ee857"; + hash = "sha256-CTe/cFc2KKG56IeLDDZiDt6GgBGe/vA/usqilvigC80="; + }; + + buildInputs = [ + setuptools + ]; + + propagatedBuildInputs = [ + numpy + torch + matplotlib + pytorch-seed + scipy + ]; + + pythonImportsCheck = [ "arm_pytorch_utilities" ]; + + meta = with lib; { + description = "University of Michigan ARM Lab PyTorch utilities"; + homepage = "https://github.com/UM-ARM-Lab/arm_pytorch_utilities"; + license = licenses.mit; + maintainers = with maintainers; [ breakds ]; + }; +} diff --git a/pkgs/basis-universal/default.nix b/pkgs/basis-universal/default.nix new file mode 100644 index 0000000..8e999bf --- /dev/null +++ b/pkgs/basis-universal/default.nix @@ -0,0 +1,31 @@ +{ + lib, + stdenv, + fetchFromGitHub, + cmake, +}: + +stdenv.mkDerivation rec { + pname = "basis-universal"; + version = "1_15_update2"; + + # Breaks magnum-plugins with every update, follow + # https://github.com/mosra/archlinux/blob/36275b5aea5e1521735b5da7819aea9ce1300976/basis-universal-src/PKGBUILD + src = fetchFromGitHub { + owner = "BinomialLLC"; + repo = "basis_universal"; + rev = "v${version}"; + hash = "sha256-2snzq/SnhWHIgSbUUgh24B6tka7EfkGO+nwKEObRkU4="; + }; + + nativeBuildInputs = [ cmake ]; + + meta = with lib; { + description = "Basis Universal GPU Texture Codec"; + homepage = "https://github.com/BinomialLLC/basis_universal"; + license = licenses.asl20; + maintainers = with maintainers; [ ]; + mainProgram = "basis-universal"; + platforms = platforms.all; + }; +} diff --git a/pkgs/corrade/default.nix b/pkgs/corrade/default.nix new file mode 100644 index 0000000..36203d1 --- /dev/null +++ b/pkgs/corrade/default.nix @@ -0,0 +1,32 @@ +{ + lib, + stdenv, + fetchFromGitHub, + cmake, +}: + +stdenv.mkDerivation rec { + pname = "corrade"; + version = "unstable-2024-03-05"; + + src = fetchFromGitHub { + owner = "mosra"; + repo = "corrade"; + rev = "295bbba1f49887da060465f88b8501965f6acd7d"; + hash = "sha256-8ucuEn/oGgbPitL15CDjmo+s1OAVI8bqcwppUWmLp4c="; + }; + + nativeBuildInputs = [ cmake ]; + + meta = with lib; { + description = "C++11 multiplatform utility library"; + homepage = "https://github.com/mosra/corrade"; + license = with licenses; [ + mit + unlicense + ]; + maintainers = with maintainers; [ SomeoneSerge ]; + mainProgram = "corrade"; + platforms = platforms.all; + }; +} diff --git a/pkgs/dev-shell/habitat.nix b/pkgs/dev-shell/habitat.nix new file mode 100644 index 0000000..de1da18 --- /dev/null +++ b/pkgs/dev-shell/habitat.nix @@ -0,0 +1,20 @@ +{ lib +, mkShell +, linuxPackages +, vulkan-loader +, python3Packages +, wayland +}: + +mkShell rec { + name = "habitat"; + + venvDir = "./env"; + packages = with python3Packages; [ + venvShellHook + python + debugpy + habitat-sim + habitat-lab + ]; +} diff --git a/pkgs/dev-shell/maniskill.nix b/pkgs/dev-shell/maniskill.nix new file mode 100644 index 0000000..f381f4d --- /dev/null +++ b/pkgs/dev-shell/maniskill.nix @@ -0,0 +1,30 @@ +{ lib +, mkShell +, linuxPackages +, vulkan-loader +, python3Packages +, wayland +}: + +mkShell rec { + name = "maniskill"; + + # TODO: fix these hacks + VK_ICD_FILENAMES = "/run/opengl-driver/share/vulkan/icd.d/nvidia_icd.x86_64.json"; + __EGL_VENDOR_LIBRARY_FILENAMES = "/run/opengl-driver/share/glvnd/egl_vendor.d/10_nvidia.json"; + LD_LIBRARY_PATH = lib.makeLibraryPath [ + "/run/opengl-driver" + vulkan-loader + wayland + ]; + + venvDir = "./env"; + packages = with python3Packages; [ + venvShellHook + python + maniskill + mujoco + pybullet + debugpy + ]; +} diff --git a/pkgs/fast-kinematics/default.nix b/pkgs/fast-kinematics/default.nix new file mode 100644 index 0000000..720e147 --- /dev/null +++ b/pkgs/fast-kinematics/default.nix @@ -0,0 +1,54 @@ +{ lib +, stdenv +, python +, buildPythonPackage +, fetchurl +, autoPatchelfHook +, torch +, numpy +}: +let + wheels = { + "x86_64-linux-python-3.9" = { + url = https://files.pythonhosted.org/packages/57/01/fe14947878e7cc05ed8beebbbf9e92955eb4d462e7a5be6540505835ef35/fast_kinematics-0.2.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl; + sha256 = "c01274f03fda3660c45816a86a5db820ec3d2ebc19abfac66a49451701a308f4"; + }; + "x86_64-linux-python-3.10" = { + url = https://files.pythonhosted.org/packages/49/c7/c11523db2e63fd50f87276128bf26f758ffae8fcc997cdbc437029409047/fast_kinematics-0.2.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl; + sha256 = "908f7ec94dfd947028170c0a37b326b3dde1b8c0a14417646e874f3e81b2cd71"; + }; + "x86_64-linux-python-3.11" = { + url = https://files.pythonhosted.org/packages/5a/6e/9f9d89f2c135d33b3c2568962415e9210b7f7e74a9d7646c638cbb5121e6/fast_kinematics-0.2.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl; + sha256 = "d2e24e736944aa7723f7445c8630d421eb61a6fcd2c23822e9bf4c6bc2d5bf69"; + }; + "x86_64-linux-python-3.12" = { + url = https://files.pythonhosted.org/packages/1b/03/6d52d961d47d0a3847967e477abfd41f4ac4b4b6001a0172359a4981491b/fast_kinematics-0.2.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl; + sha256 = "0500a63494e69d1e51d9770f4fa429e1d50dbbe27e5c448f8daca32bc4e03bb6"; + }; + }; +in buildPythonPackage rec { + pname = "fast-kinematics"; + version = "0.2.2"; + + src = fetchurl wheels."${stdenv.system}-python-${python.pythonVersion}"; + + format = "wheel"; + + nativeBuildInputs = [ + autoPatchelfHook + ]; + + propagatedBuildInputs = [ + numpy + torch + ]; + + pythonImportsCheck = [ "fast_kinematics" ]; + + meta = with lib; { + homepage = "https://github.com/Lexseal/fast_kinematics"; + description = "Cuda enabled library for calculating forward kinematics and Jacobian of a kinematics chain."; + license = licenses.mit; + platforms = platforms.unix; + }; +} diff --git a/pkgs/habitat-lab/default.nix b/pkgs/habitat-lab/default.nix new file mode 100644 index 0000000..5724183 --- /dev/null +++ b/pkgs/habitat-lab/default.nix @@ -0,0 +1,66 @@ +{ lib +, pythonOlder +, buildPythonPackage +, fetchFromGitHub +, setuptools +, gym +, numpy +, quaternion +, attrs +, opencv4 +, hydra-core +, omegaconf +, numba +, imageio +, imageio-ffmpeg +, scipy +, tqdm +, magnum-bindings +, habitat-sim +}: + +buildPythonPackage rec { + pname = "habitat-lab"; + version = "0.3.2"; + + src = fetchFromGitHub { + owner = "facebookresearch"; + repo = pname; + rev = "v${version}"; + hash = "sha256-o5q+Kx9Se99d4awlvrVGAdqT4i2SWCArRvNKaKOPImA="; + }; + + build-system = [ setuptools ]; + + patches = [ ./py311-dataclasses.patch ]; + postPatch = '' + cd habitat-lab + ''; + + propagatedBuildInputs = [ + gym + numpy + quaternion + attrs + opencv4 + hydra-core + omegaconf + numba + imageio + imageio-ffmpeg + scipy + tqdm + magnum-bindings + habitat-sim + ]; + + doCheck = false; + pythonImportsCheck = [ "habitat" ]; + + meta = with lib; { + description = "A modular high-level library to train embodied AI agents across a variety of tasks and environments."; + homepage = "https://aihabitat.org/"; + license = licenses.mit; + maintainers = with maintainers; [ breakds ]; + }; +} diff --git a/pkgs/habitat-lab/py311-dataclasses.patch b/pkgs/habitat-lab/py311-dataclasses.patch new file mode 100644 index 0000000..1af052b --- /dev/null +++ b/pkgs/habitat-lab/py311-dataclasses.patch @@ -0,0 +1,63 @@ +diff --git a/habitat-lab/habitat/config/default_structured_configs.py b/habitat-lab/habitat/config/default_structured_configs.py +index 5c542fe9..fd947c42 100644 +--- a/habitat-lab/habitat/config/default_structured_configs.py ++++ b/habitat-lab/habitat/config/default_structured_configs.py +@@ -120,7 +120,7 @@ class EnvironmentConfig(HabitatBaseConfig): + """ + max_episode_steps: int = 1000 + max_episode_seconds: int = 10000000 +- iterator_options: IteratorOptionsConfig = IteratorOptionsConfig() ++ iterator_options: IteratorOptionsConfig = field(default_factory=IteratorOptionsConfig) + + + # ----------------------------------------------------------------------------- +@@ -787,7 +787,7 @@ class TopDownMapMeasurementConfig(MeasurementConfig): + draw_goal_positions: bool = True + # axes aligned bounding boxes + draw_goal_aabbs: bool = True +- fog_of_war: FogOfWarConfig = FogOfWarConfig() ++ fog_of_war: FogOfWarConfig = field(default_factory=FogOfWarConfig) + + + @dataclass +@@ -1783,14 +1783,14 @@ class SimulatorConfig(HabitatBaseConfig): + # if default navmesh is used, should it include static objects + navmesh_include_static_objects: bool = False + +- habitat_sim_v0: HabitatSimV0Config = HabitatSimV0Config() ++ habitat_sim_v0: HabitatSimV0Config = field(default_factory=HabitatSimV0Config) + # ep_info is added to the config in some rearrange tasks inside + # merge_sim_episode_with_object_config + ep_info: Optional[Any] = None + # The offset id values for the object + object_ids_start: int = 100 + # Configuration for rendering +- renderer: RendererConfig = RendererConfig() ++ renderer: RendererConfig = field(default_factory=RendererConfig) + + + @dataclass +@@ -1852,7 +1852,7 @@ class PyrobotConfig(HabitatBaseConfig): + ) + base_controller: str = "proportional" + base_planner: str = "none" +- locobot: LocobotConfig = LocobotConfig() ++ locobot: LocobotConfig = field(default_factory=LocobotConfig) + + + @dataclass +@@ -1910,11 +1910,11 @@ class HabitatConfig(HabitatBaseConfig): + # The key of the gym environment in the registry to use in GymRegistryEnv + # for example: `Cartpole-v0` + env_task_gym_id: str = "" +- environment: EnvironmentConfig = EnvironmentConfig() +- simulator: SimulatorConfig = SimulatorConfig() ++ environment: EnvironmentConfig = field(default_factory=EnvironmentConfig) ++ simulator: SimulatorConfig = field(default_factory=SimulatorConfig) + task: TaskConfig = MISSING + dataset: DatasetConfig = MISSING +- gym: GymConfig = GymConfig() ++ gym: GymConfig = field(default_factory=GymConfig) + + + # ----------------------------------------------------------------------------- diff --git a/pkgs/habitat-sim/0001-cmake-recastnavigation-allow-dependency-injection.patch b/pkgs/habitat-sim/0001-cmake-recastnavigation-allow-dependency-injection.patch new file mode 100644 index 0000000..4ab1786 --- /dev/null +++ b/pkgs/habitat-sim/0001-cmake-recastnavigation-allow-dependency-injection.patch @@ -0,0 +1,56 @@ +From 41f70282a01db30ccc0ea1d3edafa20e00ee5f90 Mon Sep 17 00:00:00 2001 +From: Someone Serge +Date: Tue, 12 Mar 2024 16:43:04 +0000 +Subject: [PATCH] cmake: recastnavigation: allow dependency injection + +--- + src/cmake/dependencies.cmake | 20 ++++++++++++++------ + src/esp/nav/CMakeLists.txt | 2 +- + 2 files changed, 15 insertions(+), 7 deletions(-) + +diff --git a/src/cmake/dependencies.cmake b/src/cmake/dependencies.cmake +index a6b316f..54d4d71 100644 +--- a/src/cmake/dependencies.cmake ++++ b/src/cmake/dependencies.cmake +@@ -107,13 +107,21 @@ set(RECASTNAVIGATION_TESTS OFF CACHE BOOL "RECASTNAVIGATION_TESTS" FORCE) + set(RECASTNAVIGATION_EXAMPLES OFF CACHE BOOL "RECASTNAVIGATION_EXAMPLES" FORCE) + # Temp BUILD_SHARED_LIBS override for Recast, has to be reset back after to avoid affecting Bullet (which needs shared) and potentially other submodules + set(_PREV_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS}) +-set(BUILD_SHARED_LIBS OFF) + include(GNUInstallDirs) +-add_subdirectory("${DEPS_DIR}/recastnavigation/Recast") +-add_subdirectory("${DEPS_DIR}/recastnavigation/Detour") +-set(BUILD_SHARED_LIBS ${_PREV_BUILD_SHARED_LIBS}) +-# Needed so that Detour doesn't hide the implementation of the method on dtQueryFilter +-target_compile_definitions(Detour PUBLIC DT_VIRTUAL_QUERYFILTER) ++ ++find_package(recastnavigation COMPONENTS Detour Recast) ++ ++if (NOT TARGET RecastNavigation::Detour) ++ set(BUILD_SHARED_LIBS OFF) ++ add_subdirectory("${DEPS_DIR}/recastnavigation/Recast") ++ add_subdirectory("${DEPS_DIR}/recastnavigation/Detour") ++ add_library(RecastNavigation::Detour ALIAS Detour) ++ add_library(RecastNavigation::Recast ALIAS Recast) ++ # Needed so that Detour doesn't hide the implementation of the method on dtQueryFilter ++ target_compile_definitions(Detour PUBLIC DT_VIRTUAL_QUERYFILTER) ++ set(BUILD_SHARED_LIBS ${_PREV_BUILD_SHARED_LIBS}) ++endif() ++ + + if(BUILD_PYTHON_BINDINGS) + # Before calling find_package(PythonInterp) search for python executable not +diff --git a/src/esp/nav/CMakeLists.txt b/src/esp/nav/CMakeLists.txt +index b594a76..f9c6f09 100644 +--- a/src/esp/nav/CMakeLists.txt ++++ b/src/esp/nav/CMakeLists.txt +@@ -15,5 +15,5 @@ target_include_directories( + target_link_libraries( + nav + PUBLIC core agent scene +- PRIVATE Detour Recast ++ PRIVATE RecastNavigation::Detour RecastNavigation::Recast + ) +-- +2.43.1 + diff --git a/pkgs/habitat-sim/default.nix b/pkgs/habitat-sim/default.nix new file mode 100644 index 0000000..6a8b6e3 --- /dev/null +++ b/pkgs/habitat-sim/default.nix @@ -0,0 +1,132 @@ +{ + lib, + buildPythonPackage, + stdenv, + fetchFromGitHub, + cmake, + config, + withCuda ? config.cudaSupport, + ninja, + pip, + setuptools, + wheel, + pythonRelaxDepsHook, + attrs, + gitpython, + imageio, + imageio-ffmpeg, + matplotlib, + numba, + numpy, + quaternion, + pillow, + scipy, + tqdm, + bullet, + eigen, + openexr, + glfw3, + pybind11, + rapidjson, + rapidjson-for-habitat ? rapidjson.overrideAttrs (oldAttrs: { + src = fetchFromGitHub { + inherit (oldAttrs.src) owner repo; + rev = "73063f5002612c6bf64fe24f851cd5cc0d83eef9"; # 2018 + hash = "sha256-pfplYKp6kkTPcyOjbnFqmbTFt8NXKLjSVC0Wh9UNUIw="; + }; + patches = lib.flip builtins.filter oldAttrs.patches ( + # "Previously applied" + p: !(lib.isPath p && lib.hasSuffix "valgrind-failures.patch" p) + ); + }), + assimp, + corrade, + magnum, + magnum-bindings, + magnum-integration, + magnum-plugins, + recastnavigation, + xorg, +}: + +buildPythonPackage rec { + pname = "habitat-sim"; + version = "0.3.0"; + pyproject = true; + + src = fetchFromGitHub { + owner = "facebookresearch"; + repo = "habitat-sim"; + rev = "v${version}"; + hash = "sha256-vTXBg3PUmXFn6nyGIGEap+LEW5KftnIXfk4qIp4T9SU="; + }; + + patches = [ ./0001-cmake-recastnavigation-allow-dependency-injection.patch ]; + postPatch = '' + sed -i 's|option(USE_SYSTEM_\(.*\) OFF)|option(USE_SYSTEM_\1 ON)|' src/CMakeLists.txt + substituteInPlace src/esp/gfx/CMakeLists.txt \ + --replace-fail \ + "MagnumIntegration REQUIRED Eigen" \ + "MagnumIntegration COMPONENTS Eigen" + rm src/cmake/FindMagnum*.cmake + ''; + + nativeBuildInputs = [ + cmake + ninja + pip + setuptools + wheel + pythonRelaxDepsHook + ]; + + buildInputs = [ + (lib.getDev bullet) + eigen + openexr + glfw3 + pybind11 + rapidjson-for-habitat + assimp + corrade + magnum + magnum-bindings + magnum-integration + magnum-plugins + recastnavigation + ] ++ lib.optionals stdenv.hostPlatform.isUnix [ xorg.libX11 ]; + + propagatedBuildInputs = [ + attrs + gitpython + imageio + imageio-ffmpeg + matplotlib + numba + numpy + quaternion + pillow + scipy + tqdm + ]; + + dontUseCmakeConfigure = true; + preConfigure = '' + export CMAKE_ARGS=$cmakeFlags + ''; + + cmakeFlags = [ + (lib.cmakeBool "BUILD_WITH_CUDA" withCuda) + ]; + + pythonRelaxDeps = [ "numpy" ]; + + pythonImportsCheck = [ "habitat_sim" ]; + + meta = with lib; { + description = "A flexible, high-performance 3D simulator for Embodied AI research"; + homepage = "https://github.com/facebookresearch/habitat-sim"; + license = licenses.mit; + maintainers = with maintainers; [ ]; + }; +} diff --git a/pkgs/magnum-bindings/default.nix b/pkgs/magnum-bindings/default.nix new file mode 100644 index 0000000..d4d54cb --- /dev/null +++ b/pkgs/magnum-bindings/default.nix @@ -0,0 +1,74 @@ +{ + buildPythonPackage, + lib, + stdenv, + fetchFromGitHub, + cmake, + ninja, + corrade, + magnum, + libGL, + xorg, + pybind11, + setuptools, +}: + +buildPythonPackage rec { + pname = "magnum-bindings"; + version = "unstable-2024-03-08"; + pyproject = true; + + src = fetchFromGitHub { + owner = "mosra"; + repo = "magnum-bindings"; + rev = "a775640b027b1b541bd682300c1fe69d7f816a61"; + hash = "sha256-yIjVpphDDroEWK+M8MyhqVD/14fVaQvynwkQfqKuHys="; + }; + + nativeBuildInputs = [ + cmake + ninja + setuptools + ]; + + buildInputs = [ + corrade + magnum + libGL + pybind11 + ] ++ lib.optionals stdenv.hostPlatform.isLinux [ xorg.libX11 ]; + + cmakeFlags = [ "-GNinja" (lib.cmakeBool "MAGNUM_WITH_PYTHON" true) ]; + + patches = [ + ./imports.patch + ]; + + # Runs pre/postBuild hooks twice... + buildPhase = '' + runPhase ninjaBuildPhase + + # "$sourceRoot/build/src/python" + cd src/python + runPhase pypaBuildPhase + ''; + + installPhase = '' + runPhase pypaInstallPhase + + (cd ../.. ; runPhase ninjaInstallPhase) + ''; + + pythonImportsCheck = [ + "magnum" + ]; + + meta = with lib; { + description = "Bindings of the Magnum C++11 graphics engine into other languages"; + homepage = "https://github.com/mosra/magnum-bindings"; + license = licenses.mit; + maintainers = with maintainers; [ ]; + mainProgram = "magnum-bindings"; + platforms = platforms.all; + }; +} diff --git a/pkgs/magnum-bindings/imports.patch b/pkgs/magnum-bindings/imports.patch new file mode 100644 index 0000000..55fb9ed --- /dev/null +++ b/pkgs/magnum-bindings/imports.patch @@ -0,0 +1,36 @@ +diff --git a/src/python/magnum/__init__.py b/src/python/magnum/__init__.py +index 9eb1135..8980182 100644 +--- a/src/python/magnum/__init__.py ++++ b/src/python/magnum/__init__.py +@@ -28,6 +28,7 @@ + # Important -- performs various platform-specific setup like adding DLL paths + # on Windows + import corrade ++import importlib + + from _magnum import * + +@@ -40,12 +41,21 @@ sys.modules['magnum.math'] = math + # In case Magnum is built statically, the whole core project is put into + # _magnum. Then we need to do the same as above but for all modules. + for i in ['gl', 'materialtools', 'meshtools', 'platform', 'primitives', 'scenegraph', 'scenetools', 'shaders', 'text', 'trade']: +- if i in globals(): sys.modules['magnum.' + i] = globals()[i] ++ if i in globals(): ++ sys.modules['magnum.' + i] = globals()[i] ++ else: ++ globals()[i] = importlib.import_module(f'.{i}', package='magnum') + + # Platform has subpackages + if 'platform' in globals(): + for i in ['glfw', 'sdl2', 'cgl', 'glx', 'wgl', 'egl']: +- if hasattr(platform, i): sys.modules['magnum.platform.' + i] = getattr(platform, i) ++ if hasattr(platform, i): ++ sys.modules['magnum.platform.' + i] = getattr(platform, i) ++ else: ++ try: ++ setattr(platform, i, importlib.import_module(f'.platform.{i}', package='magnum')) ++ except ModuleNotFoundError: ++ pass + + # Scenegraph has subpackages + if 'scenegraph' in globals(): diff --git a/pkgs/magnum-integration/default.nix b/pkgs/magnum-integration/default.nix new file mode 100644 index 0000000..f1302a8 --- /dev/null +++ b/pkgs/magnum-integration/default.nix @@ -0,0 +1,46 @@ +{ + lib, + stdenv, + fetchFromGitHub, + cmake, + bullet, + corrade, + eigen, + magnum, + libGL, +}: + +stdenv.mkDerivation rec { + pname = "magnum-integration"; + version = "unstable-2024-03-07"; + + src = fetchFromGitHub { + owner = "mosra"; + repo = "magnum-integration"; + rev = "d0aab18311083a35a2372d71c3760d652d2e4849"; + hash = "sha256-eRmMFg5YUr4GPrv2y6O4Q0hT/1xgJk8p7ATR0rsE0X0="; + }; + + nativeBuildInputs = [ cmake ]; + buildInputs = [ + (lib.getDev bullet) + corrade + eigen + magnum + libGL + ]; + + cmakeFlags = [ + (lib.cmakeBool "MAGNUM_WITH_EIGEN" true) + (lib.cmakeBool "MAGNUM_WITH_BULLET" true) + ]; + + meta = with lib; { + description = "Integration libraries for the Magnum C++11 graphics engine"; + homepage = "https://github.com/mosra/magnum-integration"; + license = licenses.mit; + maintainers = with maintainers; [ ]; + mainProgram = "magnum-integration"; + platforms = platforms.all; + }; +} diff --git a/pkgs/magnum-plugins/default.nix b/pkgs/magnum-plugins/default.nix new file mode 100644 index 0000000..fda77ab --- /dev/null +++ b/pkgs/magnum-plugins/default.nix @@ -0,0 +1,57 @@ +{ + lib, + stdenv, + fetchFromGitHub, + cmake, + assimp, + basis-universal, + corrade, + magnum, + libGL, +}: + +stdenv.mkDerivation rec { + pname = "magnum-plugins"; + version = "unstable-2024-03-05"; + + src = fetchFromGitHub { + owner = "mosra"; + repo = "magnum-plugins"; + rev = "7dfbea3ed2e24273fde71ccb7cf26b8a48c99cd6"; + hash = "sha256-/sVZXYx4qqbdLk86miVIjv1RqaMTTy14jq7sMP20CIA="; + }; + + nativeBuildInputs = [ cmake ]; + buildInputs = [ + assimp + corrade + magnum + libGL + + # Not using because lacks exports. Only ships an executable in $out/bin + # basis-universal + ]; + + cmakeFlags = [ + (lib.cmakeBool "MAGNUM_WITH_GLTFIMPORTER" true) + (lib.cmakeBool "MAGNUM_WITH_STBIMAGEIMPORTER" true) + (lib.cmakeBool "MAGNUM_WITH_STBIMAGECONVERTER" true) + (lib.cmakeBool "MAGNUM_WITH_PRIMITIVEIMPORTER" true) + (lib.cmakeBool "MAGNUM_WITH_STANFORDIMPORTER" true) + + (lib.cmakeBool "MAGNUM_WITH_BASISIMPORTER" true) + (lib.cmakeFeature "BASIS_UNIVERSAL_DIR" "${basis-universal.src}") + + (lib.cmakeBool "MAGNUM_WITH_ASSIMPIMPORTER" true) + (lib.cmakeBool "MAGNUM_WITH_KTXIMPORTER" true) + ]; + + meta = with lib; { + description = "Plugins for the Magnum C++11 graphics engine"; + homepage = "https://github.com/mosra/magnum-plugins"; + license = licenses.mit; + maintainers = with maintainers; [ ]; + mainProgram = "magnum-plugins"; + platforms = platforms.all; + }; +} diff --git a/pkgs/magnum/default.nix b/pkgs/magnum/default.nix new file mode 100644 index 0000000..50e8f99 --- /dev/null +++ b/pkgs/magnum/default.nix @@ -0,0 +1,45 @@ +{ + lib, + stdenv, + fetchFromGitHub, + cmake, + corrade, + libGL, + xorg, +}: + +stdenv.mkDerivation rec { + pname = "magnum"; + version = "unstable-2024-03-11"; + + src = fetchFromGitHub { + owner = "mosra"; + repo = "magnum"; + rev = "b1419017650c83538d8fe4681de6f0bca524cf49"; + hash = "sha256-kN2NhUCfUavNpK/cYQ1XgVUUaQJCKLCcF6VnL6vP3qU="; + }; + + nativeBuildInputs = [ cmake ]; + buildInputs = [ + corrade + libGL # A shim that resolves into libglvnd on Linux + ] ++ lib.optionals stdenv.hostPlatform.isUnix [ + xorg.libX11 + ]; + + cmakeFlags = [ + (lib.cmakeBool "MAGNUM_WITH_ANYIMAGEIMPORTER" true) + (lib.cmakeBool "MAGNUM_WITH_ANYSCENEIMPORTER" true) + (lib.cmakeBool "MAGNUM_WITH_ANYIMAGECONVERTER" true) + (lib.cmakeBool "MAGNUM_WITH_WINDOWLESSGLXAPPLICATION" true) + ]; + + meta = with lib; { + description = "Lightweight and modular C++11 graphics middleware for games and data visualization"; + homepage = "https://github.com/mosra/magnum"; + license = licenses.mit; + maintainers = with maintainers; [ SomeoneSerge ]; + mainProgram = "magnum"; + platforms = platforms.all; + }; +} diff --git a/pkgs/maniskill/default.nix b/pkgs/maniskill/default.nix new file mode 100644 index 0000000..a506f73 --- /dev/null +++ b/pkgs/maniskill/default.nix @@ -0,0 +1,84 @@ +{ lib +, fetchFromGitHub +, buildPythonPackage +, pythonRelaxDepsHook +, python +, stdenv +, autoPatchelfHook +, numpy +, scipy +, dacite +, gymnasium +, sapien +, h5py +, pyyaml +, tqdm +, gitpython +, tabulate +, transforms3d +, trimesh +, imageio +, imageio-ffmpeg +, mplib +# , fast-kinematics +, ipython +, pytorch-kinematics +, tyro +, huggingface-hub +, pynvml +, psutil +, stable-baselines3 +}: + +buildPythonPackage rec { + pname = "maniskill"; + version = "3.0.0"; + + src = fetchFromGitHub { + owner = "haosulab"; + repo = pname; + rev = "41a5cede87379cf311cfb6dad3f10626bdee66c7"; + hash = "sha256-nQS09Iuvel5gj1L6Z9qy6JqVMLUeEDTzJ0EYpoZmqcw="; + }; + + propagatedBuildInputs = [ + numpy + scipy + dacite + gymnasium + sapien + h5py + pyyaml + tqdm + gitpython + tabulate + transforms3d + trimesh + imageio + imageio-ffmpeg + mplib + # fast-kinematics + ipython + pytorch-kinematics + tyro + huggingface-hub + pynvml + psutil + stable-baselines3 + ]; + + pythonImportsCheck = [ "mani_skill" ]; + + # check requires pip and network + doCheck = false; + + meta = with lib; { + homepage = "https://github.com/haosulab/ManiSkill"; + description = '' + ManiSkill3: A Unified Benchmark for Generalizable Manipulation Skills. + ''; + license = licenses.mit; + maintainers = with maintainers; [ breakds ]; + platforms = with platforms; linux; + }; +} diff --git a/pkgs/mplib/default.nix b/pkgs/mplib/default.nix new file mode 100644 index 0000000..d0119be --- /dev/null +++ b/pkgs/mplib/default.nix @@ -0,0 +1,58 @@ +{ lib +, stdenv +, pkgs +, python +, autoPatchelfHook +, buildPythonPackage +, fetchurl +, numpy +, toppra +, transforms3d +}: + +let + wheels = { + "x86_64-linux-python-3.9" = { + url = https://files.pythonhosted.org/packages/13/14/9c947ab4cfe25048efd74322bbe9e49285272e9aaf9c8a6610d8b79412a6/mplib-0.2.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl; + sha256 = "558bcd4936986d3c142c67d5ad1f383f24f7c7d83c90d46e2b6841a2888333a6"; + }; + "x86_64-linux-python-3.10" = { + url = https://files.pythonhosted.org/packages/c7/30/637fe639d5231d9bb267befde4fd409d2a1aececc692cd96052190e54232/mplib-0.2.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl; + sha256 = "87cd73ce6974bbb4035ddf941b4d05b3eafb071faf217c860f262be65581cbb4"; + }; + "x86_64-linux-python-3.11" = { + url = https://files.pythonhosted.org/packages/c9/3c/676109cc90f84db4e866f75c0241f5eb65788bb56296c941144be64b2d53/mplib-0.2.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl; + sha256 = "3596cb217ca7a226dbf952133dbff5cf5529d8893388fb0e042a9cb4e7f26eab"; + }; + "x86_64-linux-python-3.12" = { + url = https://files.pythonhosted.org/packages/dd/73/0316b490a15a0a0493b00b3078af173cc2ca825a5d5bc8e5529b31f2b456/mplib-0.2.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl; + sha256 = "9d90de48f982f1e7412994ba851b223b411533a69514dc2fa21d655aed761295"; + }; + }; +in buildPythonPackage rec { + pname = "mplib"; + version = "0.2.1"; + + src = fetchurl wheels."${stdenv.system}-python-${python.pythonVersion}"; + + format = "wheel"; + + nativeBuildInputs = [ + autoPatchelfHook + ]; + + propagatedBuildInputs = [ + numpy + toppra + transforms3d + ]; + + pythonImportsCheck = [ "mplib" ]; + + meta = with lib; { + description = "a Lightweight Motion Planning Package"; + homepage = "https://motion-planning-lib.readthedocs.io/"; + license = licenses.mit; + maintainers = with maintainers; [ breakds ]; + }; +} diff --git a/pkgs/mplib/docstrings.patch b/pkgs/mplib/docstrings.patch new file mode 100644 index 0000000..67bc0b1 --- /dev/null +++ b/pkgs/mplib/docstrings.patch @@ -0,0 +1,52 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 03e241d..609da60 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -46,16 +46,23 @@ set_target_properties(mp PROPERTIES POSITION_INDEPENDENT_CODE TRUE) + # pybind11_mkdoc + file(GLOB_RECURSE MPLIB_MKDOC_HEADER "${CMAKE_CURRENT_SOURCE_DIR}/include/mplib/*.h") + list(FILTER MPLIB_MKDOC_HEADER EXCLUDE REGEX "types.h|macros") +-add_custom_target( +- pybind11_mkdoc ALL +- COMMAND bash "${CMAKE_CURRENT_SOURCE_DIR}/dev/mkdoc.sh" +- "-I$,;-I>" +- BYPRODUCTS "${CMAKE_CURRENT_SOURCE_DIR}/pybind/docstring/*.h" +- DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/dev/mkdoc.sh" "${MPLIB_MKDOC_HEADER}" +- WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} +- COMMAND_EXPAND_LISTS +- VERBATIM +-) ++ ++# Check if the files in "${CMAKE_CURRENT_SOURCE_DIR}/pybind/docstring/*.h" already exist ++file(GLOB EXISTING_DOCSTRING_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/pybind/docstring/*.h") ++ ++# Only create the pybind11_mkdoc target if the docstring files do not already exist ++if(NOT EXISTING_DOCSTRING_HEADERS) ++ add_custom_target( ++ pybind11_mkdoc ALL ++ COMMAND bash "${CMAKE_CURRENT_SOURCE_DIR}/dev/mkdoc.sh" ++ "-I$,;-I>" ++ BYPRODUCTS "${CMAKE_CURRENT_SOURCE_DIR}/pybind/docstring/*.h" ++ DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/dev/mkdoc.sh" "${MPLIB_MKDOC_HEADER}" ++ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ++ COMMAND_EXPAND_LISTS ++ VERBATIM ++ ) ++endif() + + # Pybind11 + add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/third_party/pybind11") +@@ -63,7 +70,12 @@ file(GLOB_RECURSE PYBIND_SRC "${CMAKE_CURRENT_SOURCE_DIR}/pybind/*.cpp") + pybind11_add_module(pymp ${PYBIND_SRC}) + target_link_libraries(pymp PRIVATE mp) + target_include_directories(pymp PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/pybind") +-add_dependencies(pymp pybind11_mkdoc) ++ ++# Add dependency only if pybind11_mkdoc target exists ++if(TARGET pybind11_mkdoc) ++ add_dependencies(pymp pybind11_mkdoc) ++endif() ++ + + # compile test_articulated_model and run the test + add_executable(test_articulated_model "${CMAKE_CURRENT_SOURCE_DIR}/tests/test_articulated_model.cpp") diff --git a/pkgs/ompl/cmake_install.patch b/pkgs/ompl/cmake_install.patch new file mode 100644 index 0000000..86e3751 --- /dev/null +++ b/pkgs/ompl/cmake_install.patch @@ -0,0 +1,15 @@ +diff --git a/CMakeModules/ompl.pc.in b/CMakeModules/ompl.pc.in +index b7bbe3d1..b349ec9d 100644 +--- a/CMakeModules/ompl.pc.in ++++ b/CMakeModules/ompl.pc.in +@@ -1,8 +1,6 @@ + # This file was generated by CMake for @PROJECT_NAME@ +-prefix=@CMAKE_INSTALL_PREFIX@ +-exec_prefix=${prefix} +-libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@ +-includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@ ++libdir=@CMAKE_INSTALL_FULL_LIBDIR@ ++includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@ + + Name: @PKG_NAME@ + Description: @PKG_DESC@ diff --git a/pkgs/ompl/default.nix b/pkgs/ompl/default.nix new file mode 100644 index 0000000..752760a --- /dev/null +++ b/pkgs/ompl/default.nix @@ -0,0 +1,41 @@ +{ lib +, stdenv +, fetchFromGitHub +, cmake +, pkg-config +, eigen +, boost +}: + +stdenv.mkDerivation rec { + pname = "ompl"; + version = "1.6.0"; + + src = fetchFromGitHub { + owner = "ompl"; + repo = pname; + rev = "${version}"; + sha256 = "sha256-6jsB7uZThGvnMACmGE2k1v0aLnudJsWNduAJ2VAH2Oo="; + }; + + nativeBuildInputs = [ + cmake + pkg-config + ]; + + patches = [ + ./cmake_install.patch + ]; + + propagatedBuildInputs = [ + eigen + boost + ]; + + meta = with lib; { + homepage = "https://ompl.kavrakilab.org/"; + description = "The Open Motion Planning Library (OMPL)"; + license = licenses.bsd3; + platforms = platforms.unix; + }; +} diff --git a/pkgs/physx5-gpu/default.nix b/pkgs/physx5-gpu/default.nix new file mode 100644 index 0000000..ad714bf --- /dev/null +++ b/pkgs/physx5-gpu/default.nix @@ -0,0 +1,32 @@ +{ lib +, gcc12Stdenv +, fetchzip +, autoPatchelfHook +}: +let + stdenv = gcc12Stdenv; +in +stdenv.mkDerivation rec { + pname = "physx5-gpu"; + version = "105.1-physx-5.3.1.patch0"; + + src = fetchzip { + url = "https://github.com/sapien-sim/physx-precompiled/releases/download/${version}/linux-so.zip"; + sha256 = "sha256-oGHm1N9MNfHpeWCOyMNR/gNo3fqlpo7EeDsHaVWva5g="; + }; + + nativeBuildInputs = [ autoPatchelfHook ]; + buildInputs = [ stdenv.cc.cc.lib ]; + + installPhase = '' + mkdir -p $out/lib + cp libPhysXGpu_64.so $out/lib/ + ''; + + meta = with lib; { + description = "NVIDIA PhysX GPU library"; + homepage = "https://github.com/sapien-sim/physx-precompiled"; + # license = licenses.unfreeRedistributable; + platforms = platforms.linux; + }; +} diff --git a/pkgs/physx5/default.nix b/pkgs/physx5/default.nix new file mode 100644 index 0000000..e7a8fe4 --- /dev/null +++ b/pkgs/physx5/default.nix @@ -0,0 +1,28 @@ + { stdenv + , fetchzip + , fetchurl + , lib + }: + + stdenv.mkDerivation rec { + pname = "physx5"; + version = "105.1-physx-5.3.1.patch0"; + + src = fetchzip { + url = "https://github.com/sapien-sim/physx-precompiled/releases/download/${version}/linux-release.zip"; + sha256 = "sha256-HyMDwRchF7EgD3mnGfALDSikz0sMQrWdGEjowwNqEX8="; + stripRoot = false; + }; + + installPhase = '' + mkdir -p $out + cp -r * $out/ + ''; + + meta = with lib; { + description = "NVIDIA PhysX precompiled libraries"; + homepage = "https://github.com/sapien-sim/physx-precompiled"; + # license = licenses.unfreeRedistributable; + platforms = platforms.linux; + }; + } diff --git a/pkgs/pytorch-kinematics/default.nix b/pkgs/pytorch-kinematics/default.nix new file mode 100644 index 0000000..3f152cf --- /dev/null +++ b/pkgs/pytorch-kinematics/default.nix @@ -0,0 +1,51 @@ +{ lib +, pythonOlder +, buildPythonPackage +, fetchFromGitHub +, setuptools +, absl-py +, lxml +, numpy +, pyyaml +, torch +, matplotlib +, pytorch-seed +, arm-pytorch-utilities +}: + +buildPythonPackage rec { + pname = "pytorch_kinematics"; + version = "0.7.4"; + format = "pyproject"; + + src = fetchFromGitHub { + owner = "UM-ARM-Lab"; + repo = pname; + rev = "v${version}"; + hash = "sha256-/8USbxJh4nu9H8iM4BNnTxbKbmIYr7Y4thY7l6PVQX4="; + }; + + buildInputs = [ + setuptools + ]; + + propagatedBuildInputs = [ + absl-py + lxml + numpy + pyyaml + torch + matplotlib + pytorch-seed + arm-pytorch-utilities + ]; + + pythonImportsCheck = [ "pytorch_kinematics" ]; + + meta = with lib; { + description = "Robot kinematics implemented in pytorch"; + homepage = "https://github.com/UM-ARM-Lab/pytorch_kinematics"; + license = licenses.mit; + maintainers = with maintainers; [ breakds ]; + }; +} diff --git a/pkgs/pytorch-seed/default.nix b/pkgs/pytorch-seed/default.nix new file mode 100644 index 0000000..2bc1f7c --- /dev/null +++ b/pkgs/pytorch-seed/default.nix @@ -0,0 +1,39 @@ +{ lib +, pythonOlder +, buildPythonPackage +, fetchFromGitHub +, setuptools +, numpy +, torch +}: + +buildPythonPackage rec { + pname = "pytorch_seed"; + version = "0.2.0"; + format = "pyproject"; + + src = fetchFromGitHub { + owner = "UM-ARM-Lab"; + repo = pname; + rev = "96a99e62482212821a848c36115387de2bfaa921"; + hash = "sha256-r8Yux+qnCKYnEjNibvYQaJ6K3KZXqKD22XiRV41eBsg="; + }; + + buildInputs = [ + setuptools + ]; + + propagatedBuildInputs = [ + numpy + torch + ]; + + pythonImportsCheck = [ "pytorch_seed" ]; + + meta = with lib; { + description = "RNG seeding and context management for pytorch"; + homepage = "https://github.com/UM-ARM-Lab/pytorch_seed"; + license = licenses.mit; + maintainers = with maintainers; [ breakds ]; + }; +} diff --git a/pkgs/recastnavigation/0001-CMake-fix-write-correct-install-paths-in-the-.pc.patch b/pkgs/recastnavigation/0001-CMake-fix-write-correct-install-paths-in-the-.pc.patch new file mode 100644 index 0000000..594764d --- /dev/null +++ b/pkgs/recastnavigation/0001-CMake-fix-write-correct-install-paths-in-the-.pc.patch @@ -0,0 +1,31 @@ +From 059379b82bedd17eeeac2653ffa38cba25798fd8 Mon Sep 17 00:00:00 2001 +From: Someone Serge +Date: Tue, 12 Mar 2024 16:21:35 +0000 +Subject: [PATCH] CMake: fix: write correct install paths in the .pc + +The concatenation was resulting in paths like +libdir=${exec_prefix}//nix/store/...-recastnavigation-1.6.0/lib +--- + CMakeLists.txt | 6 +++--- + 1 file changed, 3 insertions(+), 3 deletions(-) + +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 9a4c8ab..e664d1b 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -31,9 +31,9 @@ install(FILES "${RecastNavigation_BINARY_DIR}/version.h" DESTINATION + # Needed for recastnavigation.pc.in + set(prefix ${CMAKE_INSTALL_PREFIX}) + set(exec_prefix "\${prefix}") +-set(libdir "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}") +-set(bindir "\${exec_prefix}/${CMAKE_INSTALL_BINDIR}") +-set(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}") ++set(libdir "${CMAKE_INSTALL_FULL_LIBDIR}") ++set(bindir "${CMAKE_INSTALL_FULL_BINDIR}") ++set(includedir "${CMAKE_INSTALL_FULL_INCLUDEDIR}") + set(PACKAGE_VERSION "${LIB_VERSION}") + if(RECASTNAVIGATION_DT_POLYREF64) + set(PKG_CONFIG_CFLAGS "${PKG_CONFIG_CFLAGS} -DDT_POLYREF64") +-- +2.43.1 + diff --git a/pkgs/recastnavigation/0001-habitat-unbreak-signature-mismatch.patch b/pkgs/recastnavigation/0001-habitat-unbreak-signature-mismatch.patch new file mode 100644 index 0000000..3a64be8 --- /dev/null +++ b/pkgs/recastnavigation/0001-habitat-unbreak-signature-mismatch.patch @@ -0,0 +1,25 @@ +From c1b21cfa4ef543393af5d605387169366d35907e Mon Sep 17 00:00:00 2001 +From: Someone Serge +Date: Tue, 12 Mar 2024 19:26:46 +0000 +Subject: [PATCH] habitat: unbreak signature mismatch + +--- + Detour/Include/DetourNavMeshQuery.h | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/Detour/Include/DetourNavMeshQuery.h b/Detour/Include/DetourNavMeshQuery.h +index d4ad890..68c3032 100644 +--- a/Detour/Include/DetourNavMeshQuery.h ++++ b/Detour/Include/DetourNavMeshQuery.h +@@ -387,7 +387,7 @@ public: + /// @returns The status flags for the query. + dtStatus moveAlongSurface(dtPolyRef startRef, const float* startPos, const float* endPos, + const dtQueryFilter* filter, +- float* resultPos, dtPolyRef* visited, int* visitedCount, const int maxVisitedSize, bool allowSliding) const; ++ float* resultPos, dtPolyRef* visited, int* visitedCount, const int maxVisitedSize, bool allowSliding=true) const; + + /// Casts a 'walkability' ray along the surface of the navigation mesh from + /// the start position toward the end position. +-- +2.43.1 + diff --git a/pkgs/recastnavigation/default.nix b/pkgs/recastnavigation/default.nix new file mode 100644 index 0000000..9ef4dae --- /dev/null +++ b/pkgs/recastnavigation/default.nix @@ -0,0 +1,73 @@ +{ + lib, + stdenv, + fetchFromGitHub, + fetchpatch, + cmake, + SDL2, + libGLU, +}: + +stdenv.mkDerivation rec { + pname = "recastnavigation"; + version = "1.6.0"; + + src = fetchFromGitHub { + owner = "recastnavigation"; + repo = "recastnavigation"; + rev = "v${version}"; + hash = "sha256-SNaGXm50n+7ZM6c4lgUnQYZDoEBdCajkDyYtcisev2U="; + }; + + patches = [ + ./0001-CMake-fix-write-correct-install-paths-in-the-.pc.patch + + # "Adds multi start shortest path ..." + (fetchpatch { + url = "https://github.com/recastnavigation/recastnavigation/commit/71db2688f2909e920aa95f806676a4983c9e0f2a.patch"; + hash = "sha256-F2p18hvBycyVqp5C6kw52V9N2NVmffM7wwT845ZO8wE="; + }) + + # "Hacky fix for ESP hot fix" + (fetchpatch { + url = "https://github.com/recastnavigation/recastnavigation/commit/c1a0c3282e4ac7475257cfa208f200e064477884.patch"; + hash = "sha256-JLU39Cgss3nWXy6L/8x02tz4+pM9vjap6RW4XiRdvx8="; + }) + + # "No sliding try step" + (fetchpatch { + url = "https://github.com/recastnavigation/recastnavigation/commit/43d050d0326c8d47c1de615103d2fb9ac01f426b.patch"; + hash = "sha256-o/+vcve2aSJYFa5nMeeRICotKXpidTIBTfHhE+32wDM="; + }) + + # "habitat: unbreak signature mismatch" + (fetchpatch { + url = "https://github.com/recastnavigation/recastnavigation/commit/8e634a30b7c001b61f2bf718452aa1dff056a417.patch"; + hash = "sha256-cqF0E9enKGNr/vq8gZlUMqHS/cQpjzkZXthzc8OJtqo="; + }) + ]; + + nativeBuildInputs = [ cmake ]; + buildInputs = [ + # "Dependency-Free - building Recast & Detour only requires a C++98-compliant compiler" + SDL2 + libGLU + ]; + + cmakeFlags = [ + # They vendor a broken copy of catch2 + (lib.cmakeBool "RECASTNAVIGATION_TESTS" false) + + # habitat-sim wants to see private symbols: + (lib.cmakeFeature "CMAKE_CXX_FLAGS" "-DDT_VIRTUAL_QUERYFILTER=1") + ]; + + meta = with lib; { + description = "Navigation-mesh Toolset for Games"; + homepage = "https://github.com/erikwijmans/recastnavigation"; + license = licenses.zlib; + maintainers = with maintainers; [ ]; + mainProgram = "recastnavigation"; + platforms = platforms.all; + }; +} diff --git a/pkgs/sapien-vulkan-2/cmake.patch b/pkgs/sapien-vulkan-2/cmake.patch new file mode 100644 index 0000000..e9e357c --- /dev/null +++ b/pkgs/sapien-vulkan-2/cmake.patch @@ -0,0 +1,126 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index c7431fe..ea66188 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -1,5 +1,5 @@ + cmake_minimum_required(VERSION 3.24 FATAL_ERROR) +-project(sapienvulkan2 LANGUAGES C CXX) ++project(sapienvulkan2 LANGUAGES C CXX CUDA) + set(CMAKE_CXX_STANDARD 20) + + option(SVULKAN2_SHARED "Force svulkan2 to be shared" ON) +@@ -20,17 +20,30 @@ add_compile_definitions("$<$:VK_VALIDATION>") + add_compile_definitions("$<$>:NDEBUG>") + + list(PREPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") +-include(glm) +-include(assimp) +-include(spdlog) +-include(glfw) +-include(ktx) +-include(vulkan) +-include(glslang) +-include(spirv-cross) + include(imgui) +-include(openexr) +-include(openvr) ++ ++find_package(glm REQUIRED) ++find_package(assimp REQUIRED) ++find_package(spdlog REQUIRED) ++find_package(glfw3 REQUIRED) ++find_package(Ktx REQUIRED) ++find_package(VulkanHeaders REQUIRED) ++find_package(glslang REQUIRED) ++find_package(SPIRV-Tools REQUIRED) ++find_package(spirv_cross_core REQUIRED) ++find_package(spirv_cross_glsl REQUIRED) ++find_package(spirv_cross_cpp REQUIRED) ++find_package(OpenEXR REQUIRED) ++ ++find_package(PkgConfig REQUIRED) ++ ++pkg_check_modules(OPENVR REQUIRED openvr) ++include_directories(${OPENVR_INCLUDE_DIRS}) ++link_directories(${OPENVR_LIBRARY_DIRS}) ++ ++pkg_check_modules(CUDART REQUIRED cudart) ++include_directories(${CUDART_INCLUDE_DIRS}) ++link_directories(${CUDART_LIBRARY_DIRS}) + + file(GLOB_RECURSE SVULKAN2_SRC "src/*.cpp") + +@@ -54,14 +67,21 @@ target_include_directories(svulkan2 PRIVATE + "3rd_party/stb" "3rd_party/OptiX7SDK/include" + "3rd_party/tinygltf" + ) +-target_link_libraries(svulkan2 PUBLIC Vulkan::Headers glm) ++target_link_libraries(svulkan2 PUBLIC ++ Vulkan::Headers glm::glm ++) + + find_package(Threads REQUIRED) +-target_link_libraries(svulkan2 PRIVATE assimp::assimp glslang SPIRV spirv-cross-cpp glfw spdlog::spdlog ktx imgui ${CMAKE_DL_LIBS} Threads::Threads OpenEXR) ++target_link_libraries(svulkan2 PRIVATE ++ assimp::assimp glslang::glslang glslang::SPIRV ++ spirv-cross-cpp glfw spdlog::spdlog KTX::ktx ++ imgui ${CMAKE_DL_LIBS} Threads::Threads ++ OpenEXR ${CUDART_LIBRARIES} ++) + if (MSVC) + target_link_libraries(svulkan2 PRIVATE openvr_api64) + else() +- target_link_libraries(svulkan2 PRIVATE openvr_api) ++ target_link_libraries(svulkan2 PRIVATE ${OPENVR_LIBRARIES}) + endif() + + if (${SVULKAN2_PROFILE}) +@@ -72,16 +92,12 @@ endif() + + + if (${SVULKAN2_CUDA_INTEROP}) +- find_package(CUDA REQUIRED) + target_compile_definitions(svulkan2 PUBLIC SVULKAN2_CUDA_INTEROP) + target_include_directories(svulkan2 PRIVATE "$ENV{CUDA_PATH}/include") + if (MSVC) + target_link_libraries(svulkan2 PRIVATE "$ENV{CUDA_PATH}/lib/x64/cudart_static.lib") +- else() +- target_link_libraries(svulkan2 PRIVATE "$ENV{CUDA_PATH}/lib64/libcudart_static.a" rt) + endif() + +- include(oidn) + target_link_libraries(svulkan2 PRIVATE OpenImageDenoise) + endif() + +@@ -92,13 +108,13 @@ target_compile_definitions(svulkan2 PRIVATE VULKAN_HPP_STORAGE_SHARED_EXPORT) + target_compile_definitions(svulkan2 PUBLIC VULKAN_HPP_STORAGE_SHARED) + + if (${SVULKAN2_CUDA_INTEROP}) +- install(TARGETS svulkan2 Vulkan-Headers glm OpenImageDenoise OpenImageDenoise_core OpenImageDenoise_common ++ install(TARGETS svulkan2 + EXPORT svulkan2Targets + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib + ) + else () +- install(TARGETS svulkan2 Vulkan-Headers glm ++ install(TARGETS svulkan2 + EXPORT svulkan2Targets + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib +@@ -106,14 +122,11 @@ else () + endif () + + install(EXPORT svulkan2Targets +- FILE svulkan2.cmake ++ FILE svulkan2Config.cmake + NAMESPACE svulkan2:: + DESTINATION lib/cmake/svulkan2 + ) + install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/svulkan2 DESTINATION "include") +-install(DIRECTORY "${vulkan_SOURCE_DIR}/include/vulkan" DESTINATION "include") +-install(DIRECTORY "${vulkan_SOURCE_DIR}/include/vk_video" DESTINATION "include") +-install(DIRECTORY "${glm_SOURCE_DIR}/glm" DESTINATION "include") + + add_executable(svulkan2_main app/main.cpp) + target_link_libraries(svulkan2_main svulkan2 glfw imgui) diff --git a/pkgs/sapien-vulkan-2/default.nix b/pkgs/sapien-vulkan-2/default.nix new file mode 100644 index 0000000..2bb8ec9 --- /dev/null +++ b/pkgs/sapien-vulkan-2/default.nix @@ -0,0 +1,142 @@ +{ lib +, stdenv +, fetchFromGitHub +, cmake +, git +, pkg-config +, cudatoolkit +, vulkan-headers +, vulkan-loader +, vulkan-validation-layers +, glm-sapien +, assimp-sapien +, spdlog +, fmt +, glfw +, ktx-tools +, glslang +, spirv-cross +, spirv-tools +, spirv-headers +, imath +, openexr-sapien +, openvr +, openimagedenoise +, xorg +, zlib +, minizip +, cudaPackages +, cudaSupport ? true +}: +let + imgui-src = fetchFromGitHub { + owner = "ocornut"; + repo = "imgui"; + rev = "ef07ddf087c879baff8c0cac0ff1f40b7f0f060c"; + sha256 = "sha256-/49/TlpJLZQRaSdhZqdB3zGZxt2H2auxpg5s8ybhgdw="; + }; + imguizmo-src = fetchFromGitHub { + owner = "CedricGuillemet"; + repo = "ImGuizmo"; + rev = "1.83"; + sha256 = "sha256-YAsfuw4blRIQs/Ev+tDBfqfO5ffX8xsQYMX1bU1y3JM="; + }; + imguifiledialog-src = fetchFromGitHub { + owner = "aiekick"; + repo = "ImGuiFileDialog"; + rev = "v0.6.5"; + sha256 = "sha256-UnhWWUu2Eo+gvhLZJCTq+XzefRcqOAbLRSSUZaO7nzs="; + }; +in +stdenv.mkDerivation rec { + pname = "sapien-vulkan-2"; + version = "47cca1405d3315553a0eee8d3377adc687bf9592"; + + src = fetchFromGitHub { + owner = "haosulab"; + repo = pname; + rev = version; + sha256 = "sha256-9otDhQTQI1heoQdSZuWykbExoCnPuS8WrSTFHD9wKQU="; + }; + + nativeBuildInputs = [ + cmake + cudatoolkit + pkg-config + ]; + + patches = [ + ./cmake.patch + ./imgui_cmake.patch + ./logger.patch + ]; + + postPatch = '' + substituteInPlace app/main.cpp src/core/context.cpp src/core/physical_device.cpp src/core/instance.cpp src/renderer/gui.cpp \ + --replace-fail '#include ' '#include <${vulkan-headers}/include/vulkan/vulkan.h> + #include ' + + substituteInPlace src/core/device.cpp src/core/instance.cpp src/renderer/vr.cpp \ + --replace-fail '#include ' '#include ' + + substituteInPlace src/common/image.cpp \ + --replace-fail '#include ' '#include ' + + substituteInPlace src/shader/glsl_compiler.cpp \ + --replace-fail '#include + #include + #include ++#include // Include fmt for runtime formatting + + namespace svulkan2 { + namespace logger { +@@ -11,28 +12,28 @@ std::shared_ptr getLogger(); + + template + inline void debug(spdlog::string_view_t fmt, const Args &...args) { +- getLogger()->debug(fmt, args...); ++ getLogger()->debug(fmt::runtime(fmt), args...); + }; + + template + inline void info(spdlog::string_view_t fmt, const Args &...args) { +- getLogger()->info(fmt, args...); ++ getLogger()->info(fmt::runtime(fmt), args...); + }; + + template + inline void warn(spdlog::string_view_t fmt, const Args &...args) { +- getLogger()->warn(fmt, args...); ++ getLogger()->warn(fmt::runtime(fmt), args...); + }; + + template + inline void error(spdlog::string_view_t fmt, const Args &...args) { +- getLogger()->error(fmt, args...); ++ getLogger()->error(fmt::runtime(fmt), args...); + }; + + template + inline void critical(spdlog::string_view_t fmt, const Args &...args) { +- getLogger()->critical(fmt, args...); ++ getLogger()->critical(fmt::runtime(fmt), args...); + }; + +-} // namespace log ++} // namespace logger + } // namespace svulkan2 +diff --git a/src/renderer/vr.cpp b/src/renderer/vr.cpp +index 33090c7..61a8f7f 100644 +--- a/src/renderer/vr.cpp ++++ b/src/renderer/vr.cpp +@@ -47,7 +47,7 @@ void VRDisplay::initDevices() { + logger::info("using action manifest {}", gActionManifestPath); + auto res = vr::VRInput()->SetActionManifestPath(gActionManifestPath.c_str()); + if (res != vr::EVRInputError::VRInputError_None) { +- logger::error("failed to read action manifest {}", res); ++ logger::error("failed to read action manifest"); + } + } + +@@ -168,7 +168,7 @@ std::vector> VRDisplay::getSkeletalDataLeft() { + vr::InputSkeletalActionData_t data{}; + auto res = vr::VRInput()->GetSkeletalActionData(mLeftHandHandle, &data, sizeof(data)); + if (res != vr::EVRInputError::VRInputError_None) { +- logger::error("failed to get skeletal data {}", res); ++ logger::error("failed to get skeletal data"); + } + if (data.bActive) { + uint32_t boneCount{}; +@@ -201,7 +201,7 @@ std::vector> VRDisplay::getSkeletalDataRight() { + vr::InputSkeletalActionData_t data{}; + auto res = vr::VRInput()->GetSkeletalActionData(mRightHandHandle, &data, sizeof(data)); + if (res != vr::EVRInputError::VRInputError_None) { +- logger::error("failed to get skeletal data {}", res); ++ logger::error("failed to get skeletal data"); + } + if (data.bActive) { + uint32_t boneCount{}; +@@ -270,7 +270,7 @@ void VRDisplay::updatePoses() { + actionSet.nPriority = 0; + auto res = vr::VRInput()->UpdateActionState(&actionSet, sizeof(actionSet), 1); + if (res != vr::EVRInputError::VRInputError_None) { +- logger::error("failed to update action state {}", res); ++ logger::error("failed to update action state"); + } + } + diff --git a/pkgs/sapien/cmake.patch b/pkgs/sapien/cmake.patch new file mode 100644 index 0000000..d9741c9 --- /dev/null +++ b/pkgs/sapien/cmake.patch @@ -0,0 +1,125 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 850ffd8a..247aa1bb 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -52,10 +52,33 @@ endmacro() + + list(PREPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") + +-include(physx5) +-include(zlib) +-include(eigen) +-include(vulkan) ++find_package(glm REQUIRED) ++find_package(assimp REQUIRED) ++find_package(spdlog REQUIRED) ++find_package(VulkanHeaders REQUIRED) ++find_package(svulkan2 REQUIRED) ++find_package(Eigen3 REQUIRED) ++find_package(OpenImageDenoise REQUIRED) ++ ++find_package(PkgConfig REQUIRED) ++ ++pkg_check_modules(CUDART REQUIRED cudart) ++include_directories(${CUDART_INCLUDE_DIRS}) ++link_directories(${CUDART_LIBRARY_DIRS}) ++ ++set(PHYSX_VERSION 105.1-physx-5.3.1.patch0) ++add_library(physx5 INTERFACE) ++target_link_directories(physx5 INTERFACE NIX_PATH_TO_PHYSX5/bin/linux.clang/release>) ++target_link_libraries(physx5 INTERFACE ++-Wl,--start-group ++libPhysXCharacterKinematic_static_64.a libPhysXCommon_static_64.a ++libPhysXCooking_static_64.a libPhysXExtensions_static_64.a ++libPhysXFoundation_static_64.a libPhysXPvdSDK_static_64.a ++libPhysX_static_64.a libPhysXVehicle_static_64.a ++-Wl,--end-group) ++target_include_directories(physx5 SYSTEM INTERFACE NIX_PATH_TO_PHYSX5/include>) ++target_compile_definitions(physx5 INTERFACE PX_PHYSX_STATIC_LIB) ++target_compile_definitions(physx5 INTERFACE PHYSX_VERSION="${PHYSX_VERSION}") + + if (${SAPIEN_DEBUG_VIEWER}) + add_definitions(_DEBUG_VIEWER) +@@ -79,8 +102,6 @@ else() + set(SVULKAN2_CUDA_INTEROP OFF CACHE BOOL "" FORCE) + endif() + +-add_subdirectory("3rd_party/sapien-vulkan-2" EXCLUDE_FROM_ALL) +- + if (${SAPIEN_CUDA}) + add_subdirectory("3rd_party/simsense") + set_target_properties(simsense PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/lib") +@@ -95,13 +116,11 @@ if (${SAPIEN_CUDA}) + + if (MSVC) + target_link_libraries(svulkan2 PRIVATE "$ENV{CUDA_PATH}/lib/x64/cudart_static.lib") +- else() +- target_link_libraries(sapien PRIVATE "$ENV{CUDA_PATH}/lib64/libcudart_static.a") + endif() + target_include_directories(sapien PRIVATE "3rd_party/dlpack/include" "$ENV{CUDA_PATH}/include") + endif () + +-target_link_libraries(sapien PUBLIC eigen svulkan2) ++target_link_libraries(sapien PUBLIC Eigen3::Eigen svulkan2::svulkan2) + target_link_libraries(sapien PRIVATE physx5 spdlog::spdlog ${CMAKE_DL_LIBS} assimp::assimp) + + if (UNIX) +@@ -109,7 +128,7 @@ if (UNIX) + endif () + + if (${SAPIEN_CUDA}) +- target_compile_definitions(sapien PUBLIC SAPIEN_CUDA SAPIEN_CUDA) ++ target_compile_definitions(sapien PUBLIC SAPIEN_CUDA SAPIEN_CUDA SVULKAN2_CUDA_INTEROP) + target_include_directories(sapien PUBLIC $) + endif() + +@@ -131,31 +150,27 @@ target_include_directories(sapien INTERFACE + ) + + if (${SAPIEN_CUDA}) +- add_dependencies(sapien OpenImageDenoise_device_cuda) +- ExternalProject_Get_property(OpenImageDenoise_device_cuda binary_dir) ++ add_dependencies(sapien OpenImageDenoise) ++ # ExternalProject_Get_property(OpenImageDenoise_device_cuda binary_dir) + + message(---- ${binary_dir}/../preinstall/lib) + install(DIRECTORY ${binary_dir}/../preinstall/lib DESTINATION "." OPTIONAL) + install(DIRECTORY ${binary_dir}/../preinstall/lib64 DESTINATION "." OPTIONAL) + + install( +- TARGETS sapien svulkan2 simsense physx5 OpenImageDenoise OpenImageDenoise_core OpenImageDenoise_common glm Vulkan-Headers ++ TARGETS sapien simsense physx5 + EXPORT sapienTargets + ) + else() + install( +- TARGETS sapien svulkan2 glm Vulkan-Headers ++ TARGETS sapien + EXPORT sapienTargets + ) + endif() + + install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/sapien" DESTINATION "include") +-install(DIRECTORY "${physx5_SOURCE_DIR}/include" DESTINATION "include/physx") ++install(DIRECTORY "NIX_PATH_TO_PHYSX5/include" DESTINATION "include/physx") + install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/3rd_party/dlpack/include/dlpack" DESTINATION "include") +-install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/3rd_party/sapien-vulkan-2/include/svulkan2" DESTINATION "include") +-install(DIRECTORY "${glm_SOURCE_DIR}/glm" DESTINATION "include") +-install(DIRECTORY "${vulkan_SOURCE_DIR}/include/vulkan" DESTINATION "include") +-install(DIRECTORY "${vulkan_SOURCE_DIR}/include/vk_video" DESTINATION "include") + + if (${SAPIEN_CUDA}) + install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/3rd_party/simsense/include/simsense" DESTINATION "include") +@@ -179,10 +194,10 @@ install( + ) + + if (SAPIEN_BUILD_PYTHON) +- include(pybind11) ++ find_package(pybind11 REQUIRED) + file(GLOB_RECURSE PYBIND_SRC "python/pybind/*.cpp") + pybind11_add_module(pysapien ${PYBIND_SRC} NO_EXTRAS) +- target_link_libraries(pysapien PRIVATE sapien eigen physx5 Vulkan::Headers glm) ++ target_link_libraries(pysapien PRIVATE sapien Eigen3::Eigen physx5 Vulkan::Headers glm::glm svulkan2::svulkan2) + if (TARGET simsense) + target_link_libraries(pysapien PRIVATE simsense) + endif() diff --git a/pkgs/sapien/default.nix b/pkgs/sapien/default.nix index 092fa19..f3eda5e 100644 --- a/pkgs/sapien/default.nix +++ b/pkgs/sapien/default.nix @@ -1,75 +1,132 @@ { lib -, fetchurl +, fetchFromGitHub +, cudatoolkit +, autoAddDriverRunpath , buildPythonPackage +, python3Packages , pythonRelaxDepsHook , python , stdenv +, pkg-config +, gcc12Stdenv +, stdenvAdapters +, cmake , autoPatchelfHook +, sapien-vulkan-2 +, physx5 +, physx5-gpu +, glm-sapien +, assimp-sapien +, spdlog +, pinocchio +, openimagedenoise +, vulkan-headers +, vulkan-loader +, pybind-smart-holder , numpy , requests , opencv4 , transforms3d , pyperclip -, vulkan-headers -, vulkan-loader +, eigen +, cudaSupport ? true }: - -let wheels = { - "x86_64-linux-python-3.8" = { - url = https://files.pythonhosted.org/packages/96/67/7b41e20984e8d7279fd182824a8765f6fed6b70c298b2d4513b7b0737766/sapien-2.2.1-cp38-cp38-manylinux2014_x86_64.whl; - sha256 = "00hlfnyxxgss0aksaxhwvsd69wxqwg9i68v39w0kwq6pqjy5lslk"; - }; - "x86_64-linux-python-3.9" = { - url = https://files.pythonhosted.org/packages/39/06/2b9e8477f87cca6df3f0cee7738934e2ee815818c952f526fd8eaf8c1085/sapien-2.2.1-cp39-cp39-manylinux2014_x86_64.whl; - sha256 = "0pp7ids7gc90q9g5ywj98lji57rzxsdrw72c55r8nwgal0nsi97j"; - }; - "x86_64-linux-python-3.10" = { - url = https://files.pythonhosted.org/packages/b9/8a/39dbc5128acf3939403fd8984c01f340c7bda3d6814fb069164290ab697a/sapien-2.2.1-cp310-cp310-manylinux2014_x86_64.whl; - sha256 = "0p24fxqb719yjwkd0rfgnbpilnjdg2m6j20kznwwg3zdhczk11gb"; - }; - "x86_64-linux-python-3.11" = { - url = https://files.pythonhosted.org/packages/18/e9/de53f5def0fefa55854c017349c42fe5c5322eda0a3e33636794fe21a4d3/sapien-2.2.1-cp311-cp311-manylinux2014_x86_64.whl; - sha256 = "1mpw78xvbqddwy874vgpbkb34kq8nr3iyywaxv5syjggk5166n7w"; - }; - }; - -in buildPythonPackage rec { +buildPythonPackage rec { pname = "sapien"; - version = "2.2.1"; - format = "wheel"; + version = "3.0.0"; - src = fetchurl wheels."${stdenv.system}-python-${python.pythonVersion}"; + src = fetchFromGitHub { + owner = "haosulab"; + repo = "SAPIEN"; + rev = "c877626fdefda29b2c33bea64f17830246508f05"; + sha256 = "sha256-8S4GasO+acLYKOQ2l/Ef3B4mecjJwGWaS1zGCR0pTmQ="; + fetchSubmodules = true; + }; - propagatedBuildInputs = [ - numpy - requests - opencv4 - transforms3d - pyperclip + stdenv = gcc12Stdenv; + + build-system = with python3Packages; [ + setuptools ]; - pythonRemoveDeps = [ "opencv-python" ]; + dontUseCmakeConfigure = true; + + nativeBuildInputs = [ + cmake + cudatoolkit + pkg-config + + autoPatchelfHook + autoAddDriverRunpath + ]; buildInputs = [ stdenv.cc.cc.lib vulkan-headers vulkan-loader + + pybind-smart-holder + sapien-vulkan-2 + glm-sapien + assimp-sapien.dev + spdlog.dev + pinocchio + + openimagedenoise + cudatoolkit + + physx5 + physx5-gpu + eigen ]; - nativeBuildInputs = [ - autoPatchelfHook - pythonRelaxDepsHook + propagatedBuildInputs = [ + numpy + requests + opencv4 + transforms3d + pyperclip + ]; + + patches = [ + ./cmake.patch + ./py_cmake.patch + ./pinocchio_cmake.patch + ./logger.patch + ./setup.patch + ./remove_tricks.patch ]; - # This is important, otherwise it will report ELF load command - # address/offset not page-aligned. - dontStrip = true; + postPatch = '' + rm -rf 3rd_party/sapien-vulkan-2 + + substituteInPlace CMakeLists.txt \ + --replace-fail '$ENV{CUDA_PATH}/include' '"${cudatoolkit}/include"' \ + --replace-fail 'set(CUDA_TOOLKIT_ROOT_DIR $ENV{CUDA_PATH})' 'set(CUDA_TOOLKIT_ROOT_DIR "${cudatoolkit}")' \ + --replace-fail 'libPhysX' '${physx5}/bin/linux.clang/release/libPhysX' \ + --replace-fail 'NIX_PATH_TO_PHYSX5' '${physx5}' + + substituteInPlace setup.py \ + --replace-fail 'os.environ.get("CUDA_PATH")' '"${cudatoolkit}"' \ + --replace-fail 'version = generate_version()' 'version = "3.0.0"' + + substituteInPlace python/py_package/physx/__init__.py \ + --replace-fail 'parent = Path.home() / ".sapien" / "physx" / physx_version' \ + 'parent = Path("${physx5-gpu}/lib")' \ + --replace-fail '"libcuda.so"' '"/run/opengl-driver/lib/libcuda.so"' + ''; + + preBuild = '' + export CUDA_PATH=${cudatoolkit} + ''; + + pythonImportsCheck = [ "sapien" ]; + + doCheck = false; meta = with lib; { homepage = "https://github.com/haosulab/SAPIEN"; - description = '' - A SimulAted Part-based Interactive ENvironment - ''; + description = "A SimulAted Part-based Interactive ENvironment"; license = licenses.mit; maintainers = with maintainers; [ breakds ]; platforms = with platforms; linux; diff --git a/pkgs/sapien/logger.patch b/pkgs/sapien/logger.patch new file mode 100644 index 0000000..0e762b0 --- /dev/null +++ b/pkgs/sapien/logger.patch @@ -0,0 +1,41 @@ +diff --git a/src/logger.h b/src/logger.h +index 0ba1b4dd..4be8c43d 100644 +--- a/src/logger.h ++++ b/src/logger.h +@@ -2,6 +2,7 @@ + #include "sapien/logger.h" + #include + #include ++#include + + namespace sapien { + namespace logger { +@@ -9,23 +10,23 @@ namespace logger { + std::shared_ptr getLogger(); + + template inline void debug(spdlog::string_view_t fmt, const Args &...args) { +- getLogger()->debug(fmt, args...); ++ getLogger()->debug(fmt::runtime(fmt), args...); + }; + + template inline void info(spdlog::string_view_t fmt, const Args &...args) { +- getLogger()->info(fmt, args...); ++ getLogger()->info(fmt::runtime(fmt), args...); + }; + + template inline void warn(spdlog::string_view_t fmt, const Args &...args) { +- getLogger()->warn(fmt, args...); ++ getLogger()->warn(fmt::runtime(fmt), args...); + }; + + template inline void error(spdlog::string_view_t fmt, const Args &...args) { +- getLogger()->error(fmt, args...); ++ getLogger()->error(fmt::runtime(fmt), args...); + }; + + template inline void critical(spdlog::string_view_t fmt, const Args &...args) { +- getLogger()->critical(fmt, args...); ++ getLogger()->critical(fmt::runtime(fmt), args...); + }; + + }; // namespace logger diff --git a/pkgs/sapien/pinocchio_cmake.patch b/pkgs/sapien/pinocchio_cmake.patch new file mode 100644 index 0000000..c93e86b --- /dev/null +++ b/pkgs/sapien/pinocchio_cmake.patch @@ -0,0 +1,24 @@ +diff --git a/pinocchio/CMakeLists.txt b/pinocchio/CMakeLists.txt +index 379f380e..1b8aba1e 100644 +--- a/pinocchio/CMakeLists.txt ++++ b/pinocchio/CMakeLists.txt +@@ -15,11 +15,13 @@ else () + endif () + + list(PREPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") +-include(pybind11) +-include(zlib) +-include(eigen) +-include(pinocchio) +- ++find_package(pybind11 REQUIRED) ++find_package(pinocchio REQUIRED) + find_package(sapien REQUIRED) ++find_package(Eigen3 REQUIRED) ++find_package(VulkanHeaders REQUIRED) ++find_package(svulkan2 REQUIRED) ++find_package(glm REQUIRED) ++ + pybind11_add_module(pysapien_pinocchio "pinocchio_model.cpp" NO_EXTRAS) +-target_link_libraries(pysapien_pinocchio PRIVATE sapien::sapien eigen pinocchio) ++target_link_libraries(pysapien_pinocchio PRIVATE sapien::sapien Eigen3::Eigen Vulkan::Headers pinocchio::pinocchio svulkan2::svulkan2 glm::glm) diff --git a/pkgs/sapien/py_cmake.patch b/pkgs/sapien/py_cmake.patch new file mode 100644 index 0000000..5275e0d --- /dev/null +++ b/pkgs/sapien/py_cmake.patch @@ -0,0 +1,25 @@ +diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt +index 832b1e19..214d4115 100644 +--- a/python/CMakeLists.txt ++++ b/python/CMakeLists.txt +@@ -26,14 +26,17 @@ macro(FetchContent_MakeAvailableExclude) + endmacro() + + list(PREPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../cmake") +-include(eigen) +-include(pybind11) ++find_package(Eigen3 REQUIRED) ++find_package(pybind11 REQUIRED) ++find_package(glm REQUIRED) ++find_package(VulkanHeaders REQUIRED) ++find_package(svulkan2 REQUIRED) + + find_package(sapien REQUIRED) + + file(GLOB_RECURSE PYBIND_SRC "pybind/*.cpp") + pybind11_add_module(pysapien ${PYBIND_SRC}) +-target_link_libraries(pysapien PRIVATE sapien::sapien eigen) ++target_link_libraries(pysapien PRIVATE sapien::sapien Eigen3::Eigen svulkan2::svulkan2 Vulkan::Headers glm::glm) + target_compile_definitions(pysapien PRIVATE PYBIND11_USE_SMART_HOLDER_AS_DEFAULT) + + if (MSVC) diff --git a/pkgs/sapien/remove_tricks.patch b/pkgs/sapien/remove_tricks.patch new file mode 100644 index 0000000..c46b19a --- /dev/null +++ b/pkgs/sapien/remove_tricks.patch @@ -0,0 +1,34 @@ +diff --git a/python/py_package/__init__.py b/python/py_package/__init__.py +index 00b9449a..8dd50c4b 100644 +--- a/python/py_package/__init__.py ++++ b/python/py_package/__init__.py +@@ -6,7 +6,6 @@ import platform + from .version import __version__ + + os.environ["SAPIEN_PACKAGE_PATH"] = os.path.dirname(__file__) +-from . import _oidn_tricks + + from . import pysapien + +@@ -18,8 +17,6 @@ from .pysapien import math, simsense + from . import physx + from . import render + +-from . import _vulkan_tricks +- + from .wrapper.scene import Scene, SceneConfig, Widget + from .wrapper.engine import Engine + from .wrapper.renderer import SapienRenderer +diff --git a/python/py_package/__init__.pyi b/python/py_package/__init__.pyi +index b2296087..4a642ce6 100644 +--- a/python/py_package/__init__.pyi ++++ b/python/py_package/__init__.pyi +@@ -21,8 +21,6 @@ from sapien.wrapper.engine import Engine + from sapien.wrapper.renderer import SapienRenderer + from sapien.wrapper.scene import Scene + from sapien.wrapper.scene import Widget +-from . import _oidn_tricks +-from . import _vulkan_tricks + from . import asset + from . import internal_renderer + from . import physx diff --git a/pkgs/sapien/setup.patch b/pkgs/sapien/setup.patch new file mode 100644 index 0000000..fa62275 --- /dev/null +++ b/pkgs/sapien/setup.patch @@ -0,0 +1,108 @@ +diff --git a/setup.py b/setup.py +index ea7be280..4a2cc0ed 100644 +--- a/setup.py ++++ b/setup.py +@@ -111,7 +111,7 @@ if args.get_version: + + def build_sapien(sapien_source_dir, sapien_build_dir): + build_dir = os.path.join(sapien_build_dir, "_sapien_build") +- install_dir = os.path.join(sapien_build_dir, "_sapien_install") ++ install_dir = os.environ["out"] + os.makedirs(build_dir, exist_ok=True) + os.makedirs(install_dir, exist_ok=True) + +@@ -193,7 +193,7 @@ class CMakeBuild(build_ext): + self.build_extension(ext) + + def build_pinocchio(self, ext): +- sapien_install_dir = os.path.join(self.sapien_build_dir, "_sapien_install") ++ sapien_install_dir = os.environ["out"] + build_dir = os.path.join(self.sapien_build_dir, "_pinocchio_build") + os.makedirs(build_dir, exist_ok=True) + original_full_path = self.get_ext_fullpath(ext.name) +@@ -215,7 +215,8 @@ class CMakeBuild(build_ext): + build_args = ["--config", cfg] + cmake_args += ["-DCMAKE_BUILD_TYPE=" + cfg] + cmake_args += [ +- "-Dsapien_DIR=" + os.path.join(sapien_install_dir, "lib/cmake/sapien") ++ "-Dsapien_DIR=" + os.path.join(sapien_install_dir, "lib/cmake/sapien"), ++ f"-DCMAKE_INSTALL_PREFIX={sapien_install_dir}", + ] + env = os.environ.copy() + subprocess.check_call( +@@ -229,7 +230,7 @@ class CMakeBuild(build_ext): + ) + + def build_pybind(self, ext): +- sapien_install_dir = os.path.join(self.sapien_build_dir, "_sapien_install") ++ sapien_install_dir = os.environ["out"] + + os.makedirs(self.build_temp, exist_ok=True) + original_full_path = self.get_ext_fullpath(ext.name) +@@ -247,7 +248,8 @@ class CMakeBuild(build_ext): + build_args = ["--config", cfg] + cmake_args += ["-DCMAKE_BUILD_TYPE=" + cfg] + cmake_args += [ +- "-Dsapien_DIR=" + os.path.join(sapien_install_dir, "lib/cmake/sapien") ++ "-Dsapien_DIR=" + os.path.join(sapien_install_dir, "lib/cmake/sapien"), ++ f"-DCMAKE_INSTALL_PREFIX={sapien_install_dir}", + ] + env = os.environ.copy() + subprocess.check_call( +@@ -266,31 +268,31 @@ class CMakeBuild(build_ext): + shutil.rmtree(include_path) + shutil.copytree(source_include_path, include_path) + +- if platform.system() == "Windows": +- bindir = os.path.join(sapien_install_dir, "bin") +- for f in os.listdir(bindir): +- if f.endswith("dll"): +- shutil.copy(os.path.join(bindir, f), extdir) +- +- oidn_library_path = os.path.join(extdir, "oidn_library") +- if os.path.exists(oidn_library_path): +- shutil.rmtree(oidn_library_path) +- os.makedirs(oidn_library_path, exist_ok=True) +- +- # provide oidn for linux +- if platform.system() == "Linux": +- for folder in ["lib", "lib64"]: +- library_dir = os.path.join(sapien_install_dir, folder) +- if not os.path.exists(library_dir): +- continue +- print("copy library from", library_dir) +- for lib in os.listdir(library_dir): +- if lib in [ +- "libOpenImageDenoise.so.2.0.1", +- "libOpenImageDenoise_core.so.2.0.1", +- "libOpenImageDenoise_device_cuda.so.2.0.1", +- ]: +- shutil.copy(os.path.join(library_dir, lib), oidn_library_path) ++ # if platform.system() == "Windows": ++ # bindir = os.path.join(sapien_install_dir, "bin") ++ # for f in os.listdir(bindir): ++ # if f.endswith("dll"): ++ # shutil.copy(os.path.join(bindir, f), extdir) ++ ++ # oidn_library_path = os.path.join(extdir, "oidn_library") ++ # if os.path.exists(oidn_library_path): ++ # shutil.rmtree(oidn_library_path) ++ # os.makedirs(oidn_library_path, exist_ok=True) ++ ++ # # provide oidn for linux ++ # if platform.system() == "Linux": ++ # for folder in ["lib", "lib64"]: ++ # library_dir = os.path.join(sapien_install_dir, folder) ++ # if not os.path.exists(library_dir): ++ # continue ++ # print("copy library from", library_dir) ++ # for lib in os.listdir(library_dir): ++ # if lib in [ ++ # "libOpenImageDenoise.so.2.0.1", ++ # "libOpenImageDenoise_core.so.2.0.1", ++ # "libOpenImageDenoise_device_cuda.so.2.0.1", ++ # ]: ++ # shutil.copy(os.path.join(library_dir, lib), oidn_library_path) + + def copy_assets(self, ext): + vulkan_shader_path = os.path.join(self.build_lib, "sapien", "vulkan_shader") diff --git a/pkgs/stable-baselines3/default.nix b/pkgs/stable-baselines3/default.nix new file mode 100644 index 0000000..127a171 --- /dev/null +++ b/pkgs/stable-baselines3/default.nix @@ -0,0 +1,57 @@ +{ lib +, pythonOlder +, buildPythonPackage +, fetchFromGitHub +, setuptools +, gymnasium +, numpy +, torch +, cloudpickle +, pandas +, matplotlib +, pytest +, pytest-cov +, pytest-env +, pytest-xdist +}: + +buildPythonPackage rec { + pname = "stable-baselines3"; + version = "2.3.2"; + + src = fetchFromGitHub { + owner = "DLR-RM"; + repo = pname; + rev = "v${version}"; + hash = "sha256-024kQVmuIs7jCt1m2a6cXKORAkpPK59XK3fVWDrO4ts="; + }; + + buildInputs = [ + setuptools + ]; + + propagatedBuildInputs = [ + gymnasium + numpy + torch + cloudpickle + pandas + matplotlib + ]; + + checkInputs = [ + pytest + pytest-cov + pytest-env + pytest-xdist + ]; + + pythonImportsCheck = [ "stable_baselines3" ]; + + meta = with lib; { + description = "Reliable PyTorch implementations of reinforcement learning algorithms."; + homepage = "https://stable-baselines3.readthedocs.io/"; + license = licenses.mit; + maintainers = with maintainers; [ breakds ]; + }; +} diff --git a/pkgs/toppra/default.nix b/pkgs/toppra/default.nix new file mode 100644 index 0000000..34157dc --- /dev/null +++ b/pkgs/toppra/default.nix @@ -0,0 +1,49 @@ +{ lib +, pythonOlder +, buildPythonPackage +, fetchFromGitHub +, python3Packages +, setuptools +, cython +, numpy +, scipy +, matplotlib +, pyyaml +, oldest-supported-numpy +}: + +buildPythonPackage rec { + pname = "toppra"; + version = "0.6.2"; + format = "pyproject"; + + src = fetchFromGitHub { + owner = "hungpham2511"; + repo = pname; + rev = "v${version}"; + hash = "sha256-QakM8HizcPSdTMrMCnynGBkd9HF1H/r2+Xt4Y9RH9ck="; + }; + + buildInputs = [ + setuptools + ]; + + propagatedBuildInputs = [ + numpy + cython + pyyaml + python3Packages.msgpack + oldest-supported-numpy + scipy + matplotlib + ]; + + pythonImportsCheck = [ "toppra" ]; + + meta = with lib; { + description = "robotic motion planning library"; + homepage = "https://hungpham2511.github.io/toppra/index.html"; + license = licenses.mit; + maintainers = with maintainers; [ breakds ]; + }; +} diff --git a/pkgs/tyro/default.nix b/pkgs/tyro/default.nix new file mode 100644 index 0000000..9183461 --- /dev/null +++ b/pkgs/tyro/default.nix @@ -0,0 +1,41 @@ +{ lib +, pythonOlder +, buildPythonPackage +, fetchFromGitHub +, setuptools +, docstring-parser +, typing-extensions +, rich +, shtab +}: + +buildPythonPackage rec { + pname = "tyro"; + version = "0.8.14"; + format = "pyproject"; + + src = fetchFromGitHub { + owner = "brentyi"; + repo = pname; + rev = "v${version}"; + hash = "sha256-ipkAgeHvKDbprRPNIC8XQtEi7TNo0rXgjs9TyM7mjPg="; + }; + + buildInputs = [ + setuptools + ]; + + propagatedBuildInputs = [ + docstring-parser + typing-extensions + rich + shtab + ]; + + meta = with lib; { + description = "tool for generating CLI interfaces in Python"; + homepage = "https://brentyi.github.io/tyro"; + license = licenses.mit; + maintainers = with maintainers; [ breakds ]; + }; +}