From d59aab21f62375bf647d03ab2382319438491b60 Mon Sep 17 00:00:00 2001 From: Ben Wolsieffer Date: Fri, 6 Dec 2019 17:18:47 -0500 Subject: [PATCH] Refactor functions into lib attrset. --- distro-overlay.nix | 38 +++------------------------- distros.nix | 2 ++ lib/default.nix | 34 +++++++++++++++++++++++++ mk-overlay.nix => lib/mk-overlay.nix | 0 overlay.nix | 2 +- release.nix | 1 + 6 files changed, 42 insertions(+), 35 deletions(-) create mode 100644 lib/default.nix rename mk-overlay.nix => lib/mk-overlay.nix (100%) diff --git a/distro-overlay.nix b/distro-overlay.nix index e9e05fa081..a77f28dbb0 100644 --- a/distro-overlay.nix +++ b/distro-overlay.nix @@ -1,10 +1,9 @@ { distro, python }: self: super: -with self.lib; -with import ./mk-overlay.nix { inherit (self) lib; }; let - base = rosSelf: rosSuper: { + lib = super.lib // import ./lib { inherit self rosSelf; }; + callPackage = self.newScope rosSelf; buildRosPackage = rosSelf.callPackage ./build-ros-package { }; @@ -20,38 +19,9 @@ let python = rosSelf.python; enablePython = true; }; - - patchVendorUrl = pkg: { - url, sha256, - originalUrl ? url, - file ? "CMakeLists.txt" - }: pkg.overrideAttrs ({ - postPatch ? "", ... - }: { - postPatch = '' - substituteInPlace '${file}' \ - --replace '${originalUrl}' '${self.fetchurl { inherit url sha256; }}' - '' + postPatch; - }); }; - overrides = rosSelf: rosSuper: let - patchBoostPython = let - pythonVersion = rosSelf.python.sourceVersion; - pythonLib = "python${pythonVersion.major}${pythonVersion.minor}"; - in '' - sed -Ei CMakeLists.txt \ - -e 's/(Boost [^)]*)python[^ )]*([ )])/\1${pythonLib}\2/' - ''; - - patchBoostSignals = pkg: pkg.overrideAttrs ({ - postPatch ? "", ... - }: { - postPatch = '' - sed -i '/find_package(Boost [^)]*/s/signals//g' CMakeLists.txt - '' + postPatch; - }); - in { + overrides = rosSelf: rosSuper: with rosSelf.lib; { # ROS package overrides/fixups ament-cmake-core = rosSuper.ament-cmake-core.overrideAttrs ({ @@ -245,7 +215,7 @@ let sha256 = "1g45f71mk4gyca550177qf70v5cvavlsalmg7x8bi59j6z6f0mgz"; }; }; -in mkOverlay [ +in self.rosPackages.lib.mkOverlay [ base (import (./. + "/${distro}/generated.nix")) overrides diff --git a/distros.nix b/distros.nix index 67e49eb028..e712861316 100644 --- a/distros.nix +++ b/distros.nix @@ -2,6 +2,8 @@ self: super: { rosPackages = rec { + lib = super.lib // import ./lib { inherit self; }; + kinetic = import ./distro-overlay.nix { distro = "kinetic"; python = self.python2; diff --git a/lib/default.nix b/lib/default.nix new file mode 100644 index 0000000000..dabf4e0dc7 --- /dev/null +++ b/lib/default.nix @@ -0,0 +1,34 @@ +{ lib ? rosSelf.lib or self.lib +, self ? null +, rosSelf ? null }: +with lib; +{ + patchVendorUrl = pkg: { + url, sha256, + originalUrl ? url, + file ? "CMakeLists.txt" + }: pkg.overrideAttrs ({ + postPatch ? "", ... + }: { + postPatch = '' + substituteInPlace '${file}' \ + --replace '${originalUrl}' '${self.fetchurl { inherit url sha256; }}' + '' + postPatch; + }); + + patchBoostPython = let + pythonVersion = rosSelf.python.sourceVersion; + pythonLib = "python${pythonVersion.major}${pythonVersion.minor}"; + in '' + sed -Ei CMakeLists.txt \ + -e 's/(Boost [^)]*)python[^ )]*([ )])/\1${pythonLib}\2/' + ''; + + patchBoostSignals = pkg: pkg.overrideAttrs ({ + postPatch ? "", ... + }: { + postPatch = '' + sed -i '/find_package(Boost [^)]*/s/signals//g' CMakeLists.txt + '' + postPatch; + }); +} // (import ./mk-overlay.nix { inherit lib; }) diff --git a/mk-overlay.nix b/lib/mk-overlay.nix similarity index 100% rename from mk-overlay.nix rename to lib/mk-overlay.nix diff --git a/overlay.nix b/overlay.nix index b4554a1dac..1b49eb1fe9 100644 --- a/overlay.nix +++ b/overlay.nix @@ -1,5 +1,5 @@ self: super: -with import ./mk-overlay.nix { inherit (super) lib; }; +with import ./lib/mk-overlay.nix { inherit (super) lib; }; applyOverlays self super [ (import ./base.nix) (import ./distros.nix) diff --git a/release.nix b/release.nix index 11c31e0538..d416678630 100644 --- a/release.nix +++ b/release.nix @@ -1,6 +1,7 @@ { nixpkgs ? , nix-ros-overlay ? ./., distro }: removeAttrs (import nix-ros-overlay { inherit nixpkgs; }).rosPackages."${distro}" [ + "lib" "python" "python3" "python2"