ros2nix/flake.nix

131 lines
4.7 KiB
Nix
Raw Permalink Normal View History

2024-08-22 17:25:28 +02:00
{
2024-09-15 11:06:29 +02:00
description = "Tool to convert ROS package.xml to Nix expressions compatible with nix-ros-overlay";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
2024-08-22 17:25:28 +02:00
inputs.flake-utils.url = "github:numtide/flake-utils";
inputs.nix-ros-overlay = { url = "github:lopsided98/nix-ros-overlay/develop"; inputs.nixpkgs.follows = "nixpkgs"; };
inputs.rosdistro = { url = "github:ros/rosdistro"; flake = false; };
2024-09-15 18:26:06 +02:00
inputs.flake-compat.url = "https://flakehub.com/f/edolstra/flake-compat/1.tar.gz";
2024-08-22 17:25:28 +02:00
outputs =
2024-09-16 08:26:07 +02:00
{ self, nixpkgs, flake-utils, nix-ros-overlay, ... } @ inputs:
2024-08-22 17:25:28 +02:00
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ nix-ros-overlay.overlays.default ];
};
rosdistro = pkgs.stdenv.mkDerivation {
pname = "rosdistro";
version = inputs.rosdistro.lastModifiedDate;
src = inputs.rosdistro;
postPatch = ''
substituteInPlace rosdep/sources.list.d/20-default.list \
--replace-fail https://raw.githubusercontent.com/ros/rosdistro/master/ file://${placeholder "out"}/
'';
postInstall = ''
mkdir -p $out
cp -r * $out
'';
};
rosdep-unwrapped = pkgs.python3Packages.rosdep.overrideAttrs ({ postPatch ? "", ...}: {
postPatch = postPatch + ''
substituteInPlace src/rosdep2/rep3.py \
--replace-fail https://raw.githubusercontent.com/ros/rosdistro/master/ file://${rosdistro}/
'';
});
rosdep-cache = pkgs.stdenv.mkDerivation {
pname = "rosdep-cache";
version = inputs.rosdistro.lastModifiedDate;
nativeBuildInputs = [
rosdep-unwrapped
];
ROSDEP_SOURCE_PATH = "${rosdistro}/rosdep/sources.list.d";
ROSDISTRO_INDEX_URL = "file://${rosdistro}/index-v4.yaml";
ROS_HOME = placeholder "out";
buildCommand = ''
mkdir -p $out
rosdep update
'';
};
# rosdep with offline database
rosdep = pkgs.python3Packages.rosdep.overrideAttrs ({ postFixup ? "", ...}: {
postFixup = postFixup + ''
wrapProgram $out/bin/rosdep --set-default ROS_HOME ${rosdep-cache}
'';
});
ros2nix = pkgs.python3Packages.buildPythonApplication {
pname = "ros2nix";
version = let lmd = self.lastModifiedDate; in with builtins;
"${substring 0 8 lmd}-${substring 8 6 lmd}";
src = pkgs.lib.cleanSource ./.;
pyproject = true;
2024-10-01 12:22:03 +02:00
build-system = with pkgs.python3Packages; [
setuptools
];
2024-10-01 12:22:03 +02:00
nativeBuildInputs = with pkgs; [
installShellFiles
python3Packages.argcomplete
];
2024-09-15 11:06:29 +02:00
propagatedBuildInputs = with pkgs; [
git
nix-prefetch-git
nixfmt-rfc-style
superflore
2024-10-01 12:22:03 +02:00
python3Packages.argcomplete
];
makeWrapperArgs = [
"--set ROS_HOME ${rosdep-cache}"
"--set ROSDEP_SOURCE_PATH ${rosdistro}/rosdep/sources.list.d"
"--set ROSDISTRO_INDEX_URL file://${rosdistro}/index-v4.yaml"
"--set ROS_OS_OVERRIDE nixos"
];
2024-10-01 12:22:03 +02:00
postInstall = ''
installShellCompletion --cmd ros2nix \
--bash <(register-python-argcomplete ros2nix) \
--fish <(register-python-argcomplete ros2nix -s fish) \
--zsh <(register-python-argcomplete ros2nix -s zsh)
'';
};
2024-08-22 17:25:28 +02:00
in
{
devShells.default = pkgs.mkShell {
inputsFrom = [
2024-09-15 11:06:29 +02:00
ros2nix
2024-08-22 17:25:28 +02:00
];
packages = [
pkgs.bashInteractive
2024-12-22 21:58:19 +01:00
(pkgs.bats.withLibraries (p: [
p.bats-support
p.bats-assert
p.bats-file
]))
2024-12-23 00:18:06 +01:00
pkgs.vcstool
2024-09-15 10:41:08 +02:00
pkgs.python3Packages.flake8
pkgs.python3Packages.flake8-bugbear
2024-09-15 21:16:50 +02:00
pkgs.python3Packages.isort
2024-12-22 21:58:19 +01:00
pkgs.python3Packages.distutils # needed for running ros2nix via python -m
2024-08-22 17:25:28 +02:00
];
ROSDEP_SOURCE_PATH = "${rosdistro}/rosdep/sources.list.d";
ROSDISTRO_INDEX_URL = "file://${rosdistro}/index-v4.yaml";
2024-12-23 00:18:06 +01:00
ROS_HOME = rosdep-cache;
};
packages = {
default = ros2nix;
inherit rosdistro rosdep-cache rosdep ros2nix;
2024-09-16 14:01:27 +02:00
inherit (pkgs) mdsh;
2024-08-22 17:25:28 +02:00
};
2024-09-16 08:26:07 +02:00
checks = {
2024-09-16 14:01:27 +02:00
mdsh-check-readme = pkgs.runCommandNoCC "mdsh"
{ nativeBuildInputs = [ ros2nix ]; } ''
mkdir $out; cd ${self};
if ! ${pkgs.mdsh}/bin/mdsh --frozen; then
echo 'Update README with `nix run .#mdsh`.'
fi'';
2024-09-16 08:26:07 +02:00
};
2024-08-22 17:25:28 +02:00
}
);
}