Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 63 additions & 11 deletions lib/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,26 @@ rec {
# :lf .
# pkgs = packages.x86_64-linux

convertPkgNameToDrv =
{
pkgs,
name,
ignoreMissing ? false,
}:
if builtins.hasAttr name pkgs then
builtins.getAttr name pkgs
else if ignoreMissing then
builtins.trace "convertPkgNameToDrv: ignoring missing derivation '${name}'" null
else
throw "convertPkgNameToDrv: unsupported string or missing derivation: ${name}";

/**
Converts a list of strings or derivations into a list of derivations from `pkgs`.

Arguments:

- `pkgs`: The package set to resolve string names to derivations.
- `vals`: A list of strings (attribute names) or derivations.
- `vals`: A list of strings (attribute names) or derivations. Null elements are ignored.
- `ignoreMissing` (optional, default: `false`): If true, missing derivations are skipped with a warning.

Returns:
Expand Down Expand Up @@ -43,16 +56,14 @@ rec {
if builtins.isAttrs x && x ? type && x.type == "derivation" then
x
else if builtins.isString x then
if builtins.hasAttr x pkgs then
builtins.getAttr x pkgs
else if ignoreMissing then
builtins.trace "convertListToDrvs: ignoring missing derivation '${x}'" null
else
throw "convertListToDrvs: unsupported string or missing derivation: ${x}"
convertPkgNameToDrv {
inherit pkgs ignoreMissing;
name = x;
}
else
throw "convertListToDrvs: unsupported type: ${builtins.typeOf x}";
in
builtins.filter (x: x != null) (map toDrv vals);
lib.unique (builtins.filter (x: x != null) (map toDrv (builtins.filter (x: x != null) vals)));

/**
Converts a list of strings or derivations into a list of derivations from `pkgs`, throwing an error if any string is not found.
Expand Down Expand Up @@ -142,6 +153,42 @@ rec {
in
convertListToDrvs pkgs names;

/**
Gathers MuJoCo robot derivations from a list of robot modules.

Each robot module should provide `passthru.mujocoRobots = [ "robot-mj-description" ]`.

@param pkgs Set. The package set to look up derivations.
@param robots List of derivations. The robot modules.
@return List of derivations. The MuJoCo robot derivations from the modules.
*/
mujocoRobotsFromRobotModules =
pkgs: robots:
drvsFromPassthruField pkgs (drv: if drv ? mujocoRobots then drv.mujocoRobots else null) robots;

/**
Replaces the mc-mujoco derivation in the apps list with a version overridden with the given MuJoCo robots.

If an app in the list is `pkgs.mc-mujoco`, it is replaced with an overridden version using the provided `mujocoRobots`.
Other apps are left unchanged.

@param apps List of derivations. The applications list.
@param pkgs Set. The package set containing mc-mujoco and mc-mujoco-robots.
@param mujocoRobots List of derivations. The MuJoCo robots to use in the override.
@return List of derivations. The updated applications list.
*/
replaceMcMujocoInApps =
apps: pkgs: mujocoRobots:
let
addMujocoRobots = pkgs.mc-mujoco.override {
mc-mujoco-robots = pkgs.mc-mujoco-robots.override {
robots = mujocoRobots;
};
};
isMcMujoco = app: (app.pname or app.name or null) == "mc-mujoco";
in
map (app: if isMcMujoco app then addMujocoRobots else app) apps;

/**
mkControllerSuperbuild

Expand Down Expand Up @@ -199,15 +246,21 @@ rec {
convertStrict = attr: name: convertListToDrvsStrict pkgs (attr.${name} or [ ]);
convertSuggested =
attr: name: convertListToDrvs pkgs (lib.optionals with-suggested (attr.${name} or [ ]));
robots = convertStrict c "robots" ++ convertSuggested s "robots";
# Gather corresponding mj-description derivations
mujocoRobots = mujocoRobotsFromRobotModules pkgs robots;
apps = convertStrict c "apps" ++ convertSuggested s "apps";
runApps = convertStrict c "runApps";
in
{
extends = extends;
runtime = {
inherit robots;
apps = replaceMcMujocoInApps apps pkgs mujocoRobots;
runApps = replaceMcMujocoInApps runApps pkgs mujocoRobots;
controllers = [ controller-drv ];
robots = convertStrict c "robots" ++ convertSuggested s "robots";
plugins = convertStrict c "plugins" ++ convertSuggested s "plugins";
observers = convertStrict c "observers" ++ convertSuggested s "observers";
apps = convertStrict c "apps" ++ convertSuggested s "apps";
};
devel = {
controllers = [ controller-drv ];
Expand All @@ -219,5 +272,4 @@ rec {
// lib.optionalAttrs (c.controller.MainRobot != null && c.controller.MainRobot != "") {
mainRobot = c.controller.MainRobot;
};

}
8 changes: 8 additions & 0 deletions module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -428,9 +428,17 @@ in
rhps1-description
miroki-description
;
inherit (pkgs)
# hrp2-mj-description
hrp4-mj-description
hrp5p-mj-description
rhps1-mj-description
# miroki-mj-description
;
inherit (pkgs)
mc-hrp2
mc-hrp4
# mc-hrp4cr
mc-hrp5-p
mc-rhps1
mc-miroki
Expand Down
5 changes: 5 additions & 0 deletions modules/superbuild/options.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ let
default = [ ];
};

runApps = lib.mkOption {
type = lib.types.listOf lib.types.package;
default = [ ];
};

robots = lib.mkOption {
type = lib.types.listOf lib.types.package;
default = [ ];
Expand Down
2 changes: 2 additions & 0 deletions modules/superbuild/resolver.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ cfg:
let
mkComponent = {
apps = [ ];
runApps = [ ];
robots = [ ];
controllers = [ ];
observers = [ ];
Expand All @@ -29,6 +30,7 @@ let

mergeComponent = left: right: {
apps = lib.unique (left.apps ++ right.apps);
runApps = lib.unique (left.runApps ++ right.runApps);
robots = lib.unique (left.robots ++ right.robots);
controllers = lib.unique (left.controllers ++ right.controllers);
observers = lib.unique (left.observers ++ right.observers);
Expand Down
85 changes: 43 additions & 42 deletions modules/superbuild/superbuild.nix
Original file line number Diff line number Diff line change
Expand Up @@ -126,48 +126,49 @@ let

If no controllers match, the result is an empty attribute set: `{}`.
*/
runAllAppsScripts =
let
res = lib.listToAttrs (
map
(
controller:
let
name = controller.pname or controller.name or "controller";
apps = mc-rtc-lib.convertListToDrvs pkgs (controller.mc-rtc.runApps or [ ]);
appPaths = lib.forEach apps (
app:
if lib.isDerivation app && app ? meta && app.meta ? mainProgram then
"${app}/bin/${app.meta.mainProgram}"
else
null
);
filteredAppPaths = lib.filter (x: x != null) appPaths;
scriptBin = pkgs.writeShellScriptBin "run-${name}" ''
set -e
pids=""
trap 'echo "Stopping apps..."; [ -n "$pids" ] && kill -9 $pids 2>/dev/null || true; exit' INT
${lib.concatMapStringsSep "\n" (appPath: ''
echo "Starting ${appPath}"
"${appPath}" &
pids="$pids $!"
'') filteredAppPaths}
wait
'';
in
{
inherit name;
value = scriptBin;
}
)
(
lib.filter (
c: (c.mc-rtc.runApps or [ ]) != [ ] && (c.mc-rtc.isController or false)
) activeRuntime.controllers
)
);
in
builtins.trace (builtins.toJSON res) res;
runAllAppsScripts = lib.listToAttrs (
map
(
controller:
let
name = controller.pname or controller.name or "controller";
apps =
# FIXME this should be per-controller i guess
if activeRuntime.runApps != [ ] then
activeRuntime.runApps
else
mc-rtc-lib.convertListToDrvs pkgs (controller.mc-rtc.runApps or [ ]);
appPaths = lib.forEach apps (
app:
if lib.isDerivation app && app ? meta && app.meta ? mainProgram then
"${app}/bin/${app.meta.mainProgram}"
else
null
);
filteredAppPaths = lib.filter (x: x != null) appPaths;
scriptBin = pkgs.writeShellScriptBin "run-${name}" ''
set -e
pids=""
trap 'echo "Stopping apps..."; [ -n "$pids" ] && kill -9 $pids 2>/dev/null || true; exit' INT
${lib.concatMapStringsSep "\n" (appPath: ''
echo "Starting ${appPath}"
"${appPath}" &
pids="$pids $!"
'') filteredAppPaths}
wait
'';
in
{
inherit name;
value = scriptBin;
}
)
(
lib.filter (
c: (c.mc-rtc.runApps or [ ]) != [ ] && (c.mc-rtc.isController or false)
) activeRuntime.controllers
)
);

in
{
Expand Down
6 changes: 3 additions & 3 deletions overlay.nix
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@

mc-mujoco-robots = final.callPackage ./pkgs/mc-rtc/mc-mujoco/robots/default.nix { };
# mc-mujoco with all public robots
mc-mujoco-robots-public = final.callPackage ./pkgs/mc-rtc/mc-mujoco/robots/default.nix {
mc-mujoco-robots-public = final.mc-mujoco-robots.override {
robots = with final; [
g1-mj-description
h1-mj-description
Expand All @@ -184,9 +184,9 @@
];
};

mc-mujoco-full = final.callPackage ./pkgs/mc-rtc/mc-mujoco {
mc-mujoco-full = final.mc-mujoco.override {
jrl-cmakemodules = final.jrl-cmakemodulesv2;
mc-mujoco-robots = final.callPackage ./pkgs/mc-rtc/mc-mujoco/robots/default.nix {
mc-mujoco-robots = final.mc-mujoco-robots.override {
robots = final.mc-mujoco-robots-public.robots;
};
};
Expand Down
38 changes: 0 additions & 38 deletions pkgs/mc-rtc/mc-mujoco/robots/hrp4cr-mj-description.nix

This file was deleted.

6 changes: 3 additions & 3 deletions pkgs/mc-rtc/robots/descriptions/h1-description.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@

(if with-ros then buildRosPackage else stdenv.mkDerivation) {
pname = "h1-description";
version = "1.0.0";
version = "1.0.2";
separateDebugInfo = false;

src = fetchFromGitHub {
owner = "isri-aist";
repo = "h1_description";
rev = "v1.0.0";
hash = "sha256-dNZWX/vqE7EUxtw5qNbwx92LaQTlvnzhq1WLRmGMnrQ=";
rev = "v1.0.2";
hash = "sha256-WR6E2OBRBphVl1nxHo7rSDOTyVGzje3V7XjnfLR5lQ4=";
};

buildType = "ament_cmake";
Expand Down
4 changes: 4 additions & 0 deletions pkgs/mc-rtc/robots/modules/mc-g1.nix
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ stdenv.mkDerivation {
"-DBUILD_TESTING=OFF"
];

passthru = {
mujocoRobots = [ "g1-mj-description" ];
};

doCheck = false;

meta = with lib; {
Expand Down
4 changes: 4 additions & 0 deletions pkgs/mc-rtc/robots/modules/mc-h1.nix
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ stdenv.mkDerivation {
"-DBUILD_TESTING=OFF"
];

passthru = {
mujocoRobots = [ "h1-mj-description" ];
};

doCheck = false;

meta = with lib; {
Expand Down
5 changes: 5 additions & 0 deletions pkgs/mc-rtc/robots/modules/mc-hrp2.nix
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ stdenv.mkDerivation {
"-DMC_RTC_HONOR_INSTALL_PREFIX=ON"
];

passthru = {
# FIXME does not exist
# mujocoRobots = [ "hrp2-mj-description" ];
};

doCheck = false;

meta = with lib; {
Expand Down
4 changes: 4 additions & 0 deletions pkgs/mc-rtc/robots/modules/mc-hrp4.nix
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ stdenv.mkDerivation {
"-DINSTALL_DOCUMENTATION=OFF"
];

passthru = {
mujocoRobots = [ "hrp4-mj-description" ];
};

doCheck = false;

meta = with lib; {
Expand Down
4 changes: 4 additions & 0 deletions pkgs/mc-rtc/robots/modules/mc-hrp5-p.nix
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ stdenv.mkDerivation {
"-DINSTALL_DOCUMENTATION=OFF"
];

passthru = {
mujocoRobots = [ "hrp5p-mj-description" ];
};

doCheck = false;

meta = with lib; {
Expand Down
Loading
Loading