diff --git a/distros/distro-overlay.nix b/distros/distro-overlay.nix index b3a779a34e..d323d47de3 100644 --- a/distros/distro-overlay.nix +++ b/distros/distro-overlay.nix @@ -315,15 +315,6 @@ let nativeBuildInputs = nativeBuildInputs ++ [ self.qt5.wrapQtAppsHook ]; }); - rviz-ogre-vendor = rosSuper.rviz-ogre-vendor.overrideAttrs ({ - preFixup ? "", ... - }: { - preFixup = '' - # Prevent /build RPATH references - rm -r ogre_install - '' + preFixup; - }); - rxcpp-vendor = patchVendorUrl rosSuper.rxcpp-vendor { url = "https://github.com/ReactiveX/RxCpp/archive/v4.1.0.tar.gz"; sha256 = "1smxrcm0s6bz05185dx1i2xjgn47rq7m247pblil6p3bmk3lkfyk"; diff --git a/distros/rolling/overrides.nix b/distros/rolling/overrides.nix index b6cc294b08..fa9a585184 100644 --- a/distros/rolling/overrides.nix +++ b/distros/rolling/overrides.nix @@ -73,9 +73,24 @@ rosSelf: rosSuper: with rosSelf.lib; { }; }; - rviz-ogre-vendor = patchVendorUrl rosSuper.rviz-ogre-vendor { - url = "https://github.com/OGRECave/ogre/archive/v1.12.10.zip"; - sha256 = "sha256-lZDLywgShlWeWah7oTnyKBTqzN505LJKbQbgXRfJXlk="; + rviz-ogre-vendor = patchAmentVendorGit rosSuper.rviz-ogre-vendor { + url = "https://github.com/OGRECave/ogre.git"; + rev = "v1.12.10"; + fetchgitArgs.hash = "sha256-Z0ixdSmkV93coBBVZ5R3lPLfVMXRfWsFz/RsSyqPWFY="; + tarSourceArgs.hook = let + version = "1.79"; + imgui = (self.fetchFromGitHub rec { + name = "${repo}-${version}"; + owner = "ocornut"; + repo = "imgui"; + rev = "v${version}"; + hash = "sha256-GIVhZ8Q7WebfHeKeJdVABXrTT26FOS7updncbv2LRnQ="; + }); + imguiTar = tarSource { } imgui; + in '' + substituteInPlace Components/Overlay/CMakeLists.txt \ + --replace ${escapeShellArg imgui.url} file://${escapeShellArg imguiTar} + ''; }; urdfdom = rosSuper.urdfdom.overrideAttrs ({ diff --git a/lib/default.nix b/lib/default.nix index 059bda2b15..79f0c53f07 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -7,30 +7,79 @@ with lib; s = composeManyExtensions overlays s {}; in s; + # Create a tarball of a package source. If the source is already an archive, + # it will be unpacked and repacked as a tarball. + tarSource = { + compress ? false, + hook ? "" + }: src: self.runCommand ("${src.name}.tar" + lib.optionalString compress ".gz") { inherit src; } '' + unpackPhase + pushd "$sourceRoot" + ${hook} + popd + tar --sort=name \ + --format=gnu \ + --owner=0 --group=0 --numeric-owner \ + ${lib.optionalString compress "-z"} \ + -cf "$out" "$sourceRoot" + ''; + patchVendorUrl = pkg: { - url, sha256, + url, hash ? "", sha256 ? "", originalUrl ? url, file ? "CMakeLists.txt" }: pkg.overrideAttrs ({ postPatch ? "", ... }: { postPatch = '' - substituteInPlace '${file}' \ - --replace '${originalUrl}' '${self.fetchurl { inherit url sha256; }}' + substituteInPlace ${escapeShellArg file} \ + --replace ${escapeShellArg originalUrl} ${escapeShellArg (self.fetchurl { inherit url hash sha256; })} '' + postPatch; }); patchVendorGit = pkg: { url, + originalUrl ? url, file ? "CMakeLists.txt", fetchgitArgs ? {} }: pkg.overrideAttrs ({ postPatch ? "", ... }: { postPatch = '' - sed -i '\|GIT_REPOSITORY\s.*${escapeShellArg url}|c\ + sed -i '\|GIT_REPOSITORY\s.*${originalUrl}|c\ URL "${self.fetchgit ({ inherit url; } // fetchgitArgs)}"' \ - '${file}' + ${escapeShellArg file} + '' + postPatch; + }); + + # Patch a vendored download that uses ament_vendor() with a Git repo as the + # source. + patchAmentVendorGit = pkg: { + url, + originalUrl ? url, + rev, # Must correspond to the VCS_VERSION argument + file ? "CMakeLists.txt", + fetchgitArgs ? {}, + tarSourceArgs ? {} + }: pkg.overrideAttrs ({ + nativeBuildInputs ? [], + postPatch ? "", ... + }: let + # ament_vendor doesn't allow patches for path inputs, so we have to pack it + # into a tar first. Additionally, vcstool only accepts tarballs with the + # version number as the root directory name. + vendor = lib.tarSource tarSourceArgs (self.fetchgit (fetchgitArgs // { + name = rev; + inherit url rev; + })); + in { + # CMake ExternalProject patches are applied with git apply + nativeBuildInputs = nativeBuildInputs ++ [ self.git ]; + postPatch = '' + sed -i '\|VCS_URL\s*${originalUrl}|c\ + VCS_URL "file://${vendor}"\ + VCS_TYPE tar' \ + ${lib.escapeShellArg file} '' + postPatch; });