From a9a387b4958ef70f52193a87f1ba00cf672e96d4 Mon Sep 17 00:00:00 2001 From: Michal Sojka Date: Thu, 12 Sep 2024 23:22:00 +0200 Subject: [PATCH] Add flake template With this change, one can initialize a ROS project by running: nix flake init --template github:lopsided98/nix-ros-overlay Besides adding the template, this commit also updates the README to list the same template as the one from the flake. The listing in the README can be easily updated to match the flake.nix file by running the "mdsh" tool. --- README.md | 14 ++++++++++---- examples/flake/flake.nix | 32 ++++++++++++++++++++++++++++++++ flake.nix | 4 ++++ 3 files changed, 46 insertions(+), 4 deletions(-) create mode 100644 examples/flake/flake.nix diff --git a/README.md b/README.md index d2c1ec5bd4..47aeb1d886 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,9 @@ nix develop github:lopsided98/nix-ros-overlay#example-turtlebot3-gazebo Using the overlay in your `flake.nix`-based project could look like this: + + + ```nix { inputs = { @@ -59,10 +62,10 @@ Using the overlay in your `flake.nix`-based project could look like this: pkgs.colcon # ... other non-ROS packages (with pkgs.rosPackages.humble; buildEnv { - paths = [ - ros-core - # ... other ROS packages - ]; + paths = [ + ros-core + # ... other ROS packages + ]; }) ]; }; @@ -73,6 +76,9 @@ Using the overlay in your `flake.nix`-based project could look like this: }; } ``` +You can use the following command to use the above template easily: + + nix flake init --template github:lopsided98/nix-ros-overlay [flake]: https://wiki.nixos.org/wiki/Flakes diff --git a/examples/flake/flake.nix b/examples/flake/flake.nix new file mode 100644 index 0000000000..af8a33b3b8 --- /dev/null +++ b/examples/flake/flake.nix @@ -0,0 +1,32 @@ +{ + inputs = { + nix-ros-overlay.url = "github:lopsided98/nix-ros-overlay/master"; + 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 ]; + }; + in { + devShells.default = pkgs.mkShell { + name = "Example project"; + packages = [ + pkgs.colcon + # ... other non-ROS packages + (with pkgs.rosPackages.humble; buildEnv { + paths = [ + ros-core + # ... other ROS packages + ]; + }) + ]; + }; + }); + nixConfig = { + extra-substituters = [ "https://ros.cachix.org" ]; + extra-trusted-public-keys = [ "ros.cachix.org-1:dSyZxI8geDCJrwgvCOHDoAfOm5sV1wCPjBkKL+38Rvo=" ]; + }; +} diff --git a/flake.nix b/flake.nix index fe578fc02c..1cd2266f4e 100644 --- a/flake.nix +++ b/flake.nix @@ -32,6 +32,10 @@ nixosModule = nixpkgs.lib.warn "'nix-ros-overlay.nixosModule' is deprecated, use 'nix-ros-overlay.nixosModules.default' instead" self.nixosModules.default; + templates.default = { + path = ./examples/flake; + description = "Basic ROS flake"; + }; }; nixConfig = {