here is my attempt to add an overlay to the nix ros overlay so i can ad a required compiler flag. I’m using this example to try and learn how overlays work in a flake context.
I am very new to Nix as well.
The goal of this attempt is to produce a derivation (am i using that word right?) that is just like the rplidar-ros package in the nix ros overlay, except it has the cmakeFlags changed.
inputs = {
nix-ros-overlay.url = "github:lopsided98/nix-ros-overlay";
nixpkgs.follows = "nix-ros-overlay/nixpkgs"; # IMPORTANT!!!
};
outputs = { self, nix-ros-overlay, nixpkgs }:
nix-ros-overlay.inputs.flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [
nix-ros-overlay.overlays.default
(final: prev: {
rosPackages = prev.rosPackages // {
humble = prev.rosPackages.humble // {
depthai-ros = prev.rosPackages.humble.depthai-ros.overrideAttrs (oldAttrs: {
cmakeFlags = (oldAttrs.cmakeFlags or []) ++ [ "-DDEPTHAI_ENABLE_BACKWARD=OFF_____THIS_DOES_NOT_HAPPEN________________" ];
});
};
};
})
];
};
in {
devShells.default = pkgs.mkShell {
name = "Example project";
packages = with pkgs.rosPackages.humble; [
pkgs.colcon
ros-core
nav2-core
rplidar-ros
depthai-ros
];
};
});
nixConfig = {
extra-substituters = [ "https://ros.cachix.org" ];
extra-trusted-public-keys = [ "ros.cachix.org-1:dSyZxI8geDCJrwgvCOHDoAfOm5sV1wCPjBkKL+38Rvo=" ];
};
}
What happens is the overlay attempt has no effect at all.
To ensure changes to depthai-ros
propagate to its dependents, you must use overrideScope
. You can find more documentation here.
I reworked the flakes file to use overrideScope, by basing it on this example
It now looks like this: (including an edit to this post to correct the name as mentioned below)
{
description = "Hero Jr.";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs?ref=master";
flake-utils.follows = "ros-flake/flake-utils";
ros-flake.url = "github:lopsided98/nix-ros-overlay";
};
outputs = { self, nixpkgs, ros-flake, flake-utils }:
flake-utils.lib.eachDefaultSystem
(system:
let
ros = ros-flake.legacyPackages.${system};
pkgs = import nixpkgs { inherit system; overlays = [ ]; };
humble-overrided = ros.humble.overrideScope (final: prev: {
depthai-ros = prev.depthai-ros.overrideAttrs (old: {
cmakeFlags = (old.cmakeFlags or []) ++ [ "-DDEPTHAI_ENABLE_BACKWARD=OFF_____THIS_DOES_NOT_HAPPEN________________" ];
});
});
in
{
inherit pkgs;
packages = {};
devShells.default =
pkgs.mkShell {
buildInputs = (with humble-overrided; [
#pkgs.colcon
ros-core
nav2-core
rplidar-ros
depthai-ros
]);
};});
nixConfig = {
extra-substituters = [ "https://ros.cachix.org" "https://robossembler.cachix.org" ];
extra-trusted-public-keys = [
"ros.cachix.org-1:dSyZxI8geDCJrwgvCOHDoAfOm5sV1wCPjBkKL+38Rvo="
"robossembler.cachix.org-1:56jBJHroRQSGpZFkW8XMquuzQTjAF/XTo6MogmBM7SQ="
];
};
}
and still find that the override has no effect,
ros-humble-depthai> cmake flags: -DCMAKE_FIND_USE_SYSTEM_PACKAGE_REGISTRY=OFF -DCMAKE_FIND_USE_PACKAGE_REGISTRY=OFF -DCMAKE_EXPORT_NO_PACKAGE_REGISTRY=ON -DCMAKE_BUILD_TYPE=Release -DBUIL
D_TESTING=OFF -DCMAKE_INSTALL_LOCALEDIR=/nix/store/kqncqlsgld3l8z72wwrs7c631qhzz1l9-ros-humble-depthai-2.24.0-r1/share/locale -DCMAKE_INSTALL_LIBEXECDIR=/nix/store/kqncqlsgld3l8z72wwrs7c6
31qhzz1l9-ros-humble-depthai-2.24.0-r1/libexec -DCMAKE_INSTALL_LIBDIR=/nix/store/kqncqlsgld3l8z72wwrs7c631qhzz1l9-ros-humble-depthai-2.24.0-r1/lib -DCMAKE_INSTALL_DOCDIR=/nix/store/kqncql
sgld3l8z72wwrs7c631qhzz1l9-ros-humble-depthai-2.24.0-r1/share/doc/depthai -DCMAKE_INSTALL_INFODIR=/nix/store/kqncqlsgld3l8z72wwrs7c631qhzz1l9-ros-humble-depthai-2.24.0-r1/share/info -DCMA
KE_INSTALL_MANDIR=/nix/store/kqncqlsgld3l8z72wwrs7c631qhzz1l9-ros-humble-depthai-2.24.0-r1/share/man -DCMAKE_INSTALL_OLDINCLUDEDIR=/nix/store/kqncqlsgld3l8z72wwrs7c631qhzz1l9-ros-humble-d
epthai-2.24.0-r1/include -DCMAKE_INSTALL_INCLUDEDIR=/nix/store/kqncqlsgld3l8z72wwrs7c631qhzz1l9-ros-humble-depthai-2.24.0-r1/include -DCMAKE_INSTALL_SBINDIR=/nix/store/kqncqlsgld3l8z72wwr
s7c631qhzz1l9-ros-humble-depthai-2.24.0-r1/sbin -DCMAKE_INSTALL_BINDIR=/nix/store/kqncqlsgld3l8z72wwrs7c631qhzz1l9-ros-humble-depthai-2.24.0-r1/bin -DCMAKE_INSTALL_NAME_DIR=/nix/store/kqn
cqlsgld3l8z72wwrs7c631qhzz1l9-ros-humble-depthai-2.24.0-r1/lib -DCMAKE_POLICY_DEFAULT_CMP0025=NEW -DCMAKE_OSX_SYSROOT= -DCMAKE_FIND_FRAMEWORK=LAST -DCMAKE_STRIP=/nix/store/lb6y9a5cf9fqvkp
67y5cdzpy909zryhf-gcc-wrapper-13.2.0/bin/strip -DCMAKE_RANLIB=/nix/store/lb6y9a5cf9fqvkp67y5cdzpy909zryhf-gcc-wrapper-13.2.0/bin/ranlib -DCMAKE_AR=/nix/store/lb6y9a5cf9fqvkp67y5cdzpy909zr
yhf-gcc-wrapper-13.2.0/bin/ar -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DCMAKE_INSTALL_PREFIX=/nix/store/kqncqlsgld3l8z72wwrs7c631qhzz1l9-ros-humble-depthai-2.24.0-r1 -DAMENT_CMAK
E_ENVIRONMENT_PARENT_PREFIX_PATH_GENERATION:BOOL=OFF -DPython3_EXECUTABLE:FILEPATH=/nix/store/dz8lm4h0ivibad5kfc0ya3p3zqyd2fyf-python3-3.11.7/bin/python3.11 -DAMENT_CMAKE_ENVIRONMENT_PARE
NT_PREFIX_PATH_GENERATION:BOOL=OFF -DPython3_EXECUTABLE:FILEPATH=/nix/store/dz8lm4h0ivibad5kfc0ya3p3zqyd2fyf-python3-3.11.7/bin/python3.11
is there anything else i might do to try and understand how to use overlays to set cmake flags?
Are you trying to override depthai-ros
or rplidar-ros
?
Thanks for taking a look at this!
I’m trying to override depthai
oops, sorry i swapped them in switching to the new approach
the override looks like ths:
humble-overrided = ros.humble.overrideScope (final: prev: {
depthai-ros = prev.depthai-ros.overrideAttrs (old: {
cmakeFlags = (old.cmakeFlags or []) ++ [ "-DDEPTHAI_ENABLE_BACKWARD=OFF_____THIS_DOES_NOT_HAPPEN________________" ];
});
});
in
and still has no effect
To really answer your question, I mostly want to learn how to use overrides so i can make more of the packages in nix-ros-overlay work. Needing cmake changes has been very common in my use of it so far.
Maybe try adding an apostrophe to overrideScope
? (i.e. overrideScope'
) No clue what the difference is, still investigating, but the wiki uses the one with an apostrophe so maybe it’s worth a shot.
that gives:
error: attribute 'overrideScope'' missing
Maybe try
humble-overrided = ros.humble.overrideScope (final: prev: {
depthai-ros = prev.depthai-ros.overrideAttrs (old: rec {
cmakeFlags = (old.cmakeFlags or []) ++ [ "-DDEPTHAI_ENABLE_BACKWARD=OFF_____THIS_DOES_NOT_HAPPEN________________" ];
preConfigure = (old.preConfigure or "") + ''
export CMAKE_ARGS=$cmakeFlags "''${cmakeFlagsArray[@]}"
'';
});
});
in
note the usage of the rec keyword in prev.depthai-ros.overrideAttrs (old: rec {