1
0
Fork 0
mirror of https://github.com/lopsided98/nix-ros-overlay.git synced 2025-06-21 14:48:39 +03:00
nix-ros-overlay/build-env/default.nix

64 lines
2.2 KiB
Nix
Raw Normal View History

{ lib, stdenv, buildPackages, writeText, buildEnv, catkin }:
{ paths ? [], ... }@args:
2019-03-21 00:23:14 -04:00
2019-04-06 02:18:37 -04:00
with lib;
2019-03-21 00:23:14 -04:00
let
propagatePackages = packages: let
validPackages = filter (d: d != null) packages;
partitionedPackages = partition (d: d.rosPackage or false) validPackages;
rosPackages = partitionedPackages.right;
otherPackages = partitionedPackages.wrong;
rosPropagatedPackages = unique (concatLists (catAttrs "propagatedBuildInputs" rosPackages));
recurse = propagatePackages rosPropagatedPackages;
in if length validPackages == 0 then {
rosPackages = [];
otherPackages = [];
} else {
rosPackages = unique (rosPackages ++ recurse.rosPackages);
otherPackages = unique (otherPackages ++ recurse.otherPackages);
};
propagatedPaths = propagatePackages paths;
env = (buildEnv (args // {
name = "ros-env";
# Only add ROS packages to environment. The rest are propagated like normal.
# ROS packages propagate a huge number of dependencies, which are added all
# added to the environment with nix-shell -p, but would not normally not be
# added with buildEnv. This file adds all specified ROS packages and their
# ROS dependencies to the environment, while propagating other packages like
# nix-shell -p does.
paths = propagatedPaths.rosPackages;
2019-03-21 00:23:14 -04:00
passthru.env = stdenv.mkDerivation {
name = "interactive-ros-env";
buildInputs = [ env ];
2019-03-21 00:23:14 -04:00
buildCommand = ''
echo >&2 ""
echo >&2 "*** ROS 'env' attributes are intended for interactive nix-shell sessions, not for building! ***"
echo >&2 ""
exit 1
'';
};
})).overrideAttrs ({ buildCommand, passAsFile ? [], ...}: {
# Hack to allow buildEnv to use propagatedBuildInputs
buildCommand = null;
oldBuildCommand = buildCommand;
passAsFile = (if passAsFile == null then [] else passAsFile) ++ [ "oldBuildCommand" ];
# catkin always needs to be propagated for its
propagatedBuildInputs = propagatedPaths.otherPackages;
buildPhase = ''
runHook preBuild
. "$oldBuildCommandPath"
"${buildPackages.perl}/bin/perl" "${./setup-hook-builder.pl}"
runHook postBuild
'';
phases = [ "buildPhase" "fixupPhase" ];
});
2019-03-21 00:23:14 -04:00
in env