Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

treewide: nixfmt everything except distros #535

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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
39 changes: 27 additions & 12 deletions .github/actions/nix-ros-build-action/eval.nix
Original file line number Diff line number Diff line change
@@ -1,22 +1,37 @@
# Evaluate `release.nix' like Hydra would. Too bad nix-instantiate can't to do this.
{ lib ? pkgs.lib, pkgs }:
{
lib ? pkgs.lib,
pkgs,
}:

let
trace = if builtins.getEnv "VERBOSE" == "1" then builtins.trace else (x: y: y);

# Add the ‘recurseForDerivations’ attribute to ensure that
# nix-instantiate recurses into nested attribute sets.
recurse = path: attrs:
recurse =
path: attrs:
if (builtins.tryEval attrs).success then
if lib.isDerivation attrs
then
if (builtins.tryEval attrs.drvPath).success
then { inherit (attrs) name drvPath; }
else { failed = true; }
if lib.isDerivation attrs then
if (builtins.tryEval attrs.drvPath).success then
{ inherit (attrs) name drvPath; }
else
{ failed = true; }
else if lib.isAttrs attrs && (attrs.recurseForDerivations or false) then
{ recurseForDerivations = true; } //
lib.mapAttrs (n: v: let path' = path ++ [n]; in trace path' (recurse path' v)) attrs
else { }
else { };
{
recurseForDerivations = true;
}
// lib.mapAttrs (
n: v:
let
path' = path ++ [ n ];
in
trace path' (recurse path' v)
) attrs
else
{ }
else
{ };

in recurse [] pkgs
in
recurse [ ] pkgs
6 changes: 5 additions & 1 deletion .github/actions/nix-ros-build-action/shell.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{ mkShell, nodejs, cachix }:
{
mkShell,
nodejs,
cachix,
}:

mkShell {
name = "nix-ros-build-action-shell";
Expand Down
66 changes: 66 additions & 0 deletions .github/workflows/check-nix-fmt.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# This file was mostly copied from nixpkgs's check-nix-format.yml,
# which itself wsa mostly copied from nixpkgs's check-maintainers-sorted.yaml.

name: Check that Nix files are formatted

on:
pull_request:
types: [opened, synchronize, reopened]
permissions:
contents: read

jobs:
nixos:
name: nixfmt-check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Calculate changed files
id: changed-files
run: echo "changed_files=$(git diff --name-only -r HEAD^1 HEAD | xargs)" >> $GITHUB_OUTPUT
- uses: cachix/install-nix-action@v30
with:
extra_nix_config: sandbox = true
nix_path: nixpkgs=channel:nixpkgs-unstable
- name: Install nixfmt
run: "nix-env -f '<nixpkgs>' -iAP nixfmt-rfc-style"
- name: Check that Nix files are formatted according to the RFC style
run: |
# List of changed files
changed_files="${{ steps.changed-files.outputs.changed_files }}"

# Convert the string of changed files into an array
IFS=' ' read -r -a files <<< "$changed_files"

# A variable to track failures
failure=0

# Function to check the file and run nixfmt
check_file() {
local file="$1"
if [[ -f "$file" ]]; then
if ! nixfmt --check "$file"; then
echo "::error file=$file::Formatting check failed for $file" >&2
failure=1
fi
else
echo "File does not exist: $file" >&2
fi
}

# Export the function and failure variable for parallel execution
export -f check_file
export failure

# Remove distros folder (not nixfmt-ed)
rm -rf distros

# Run the checks in parallel
printf "%s\n" "${files[@]}" | xargs -n 1 -P "$(nproc)" -I {} bash -c 'check_file "$@"' _ {}

# Exit with a status of 1 if any checks failed
if [[ $failure -eq 1 ]]; then
exit 1
fi
17 changes: 11 additions & 6 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@ let
sha256 = lock.nodes.nixpkgs.locked.narHash;
};
in
{ nixpkgs ? lockedNixpkgs
, overlays ? []
, ... }@args:
{
nixpkgs ? lockedNixpkgs,
overlays ? [ ],
...
}@args:

import nixpkgs (args // {
overlays = [ (import ./overlay.nix) ] ++ overlays;
})
import nixpkgs (
args
// {
overlays = [ (import ./overlay.nix) ] ++ overlays;
}
)
33 changes: 22 additions & 11 deletions examples/flake/flake.nix
Original file line number Diff line number Diff line change
@@ -1,30 +1,41 @@
{
inputs = {
nix-ros-overlay.url = "github:lopsided98/nix-ros-overlay/master";
nixpkgs.follows = "nix-ros-overlay/nixpkgs"; # IMPORTANT!!!
nixpkgs.follows = "nix-ros-overlay/nixpkgs"; # IMPORTANT!!!
};
outputs = { self, nix-ros-overlay, nixpkgs }:
nix-ros-overlay.inputs.flake-utils.lib.eachDefaultSystem (system:
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 {
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
];
})
(
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=" ];
Expand Down
4 changes: 3 additions & 1 deletion examples/ros2-basic.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Environment containing basic ROS2 tools

{ pkgs ? import ../. {} }:
{
pkgs ? import ../. { },
}:
with pkgs;
with rosPackages.humble;

Expand Down
74 changes: 38 additions & 36 deletions examples/ros2-gz.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,44 @@
# to run this dev shell use:
# NIXPKGS_ALLOW_INSECURE=1 nix develop --impure .\#example-ros2-gz

{pkgs ? import ../. {}}:
{
pkgs ? import ../. { },
}:
with pkgs;
with rosPackages.jazzy;
mkShell {
nativeBuildInputs = [
(buildEnv {
paths = [
colcon
ros-core
ament-cmake-core
python-cmake-module
# ros-gz
mkShell {
nativeBuildInputs = [
(buildEnv {
paths = [
colcon
ros-core
ament-cmake-core
python-cmake-module
# ros-gz

gz-cmake-vendor
gz-common-vendor
gz-dartsim-vendor
gz-fuel-tools-vendor
gz-gui-vendor
gz-launch-vendor
gz-math-vendor
gz-msgs-vendor
gz-ogre-next-vendor
gz-physics-vendor
gz-plugin-vendor
gz-rendering-vendor
gz-sensors-vendor
gz-sim-vendor
gz-tools-vendor
gz-transport-vendor
gz-utils-vendor
];
})
];
# Gazebo is currently broken on Wayland
# https://gazebosim.org/docs/ionic/troubleshooting/#wayland-issues
shellHook = ''
unset QT_QPA_PLATFORM
'';
}
gz-cmake-vendor
gz-common-vendor
gz-dartsim-vendor
gz-fuel-tools-vendor
gz-gui-vendor
gz-launch-vendor
gz-math-vendor
gz-msgs-vendor
gz-ogre-next-vendor
gz-physics-vendor
gz-plugin-vendor
gz-rendering-vendor
gz-sensors-vendor
gz-sim-vendor
gz-tools-vendor
gz-transport-vendor
gz-utils-vendor
];
})
];
# Gazebo is currently broken on Wayland
# https://gazebosim.org/docs/ionic/troubleshooting/#wayland-issues
shellHook = ''
unset QT_QPA_PLATFORM
'';
}
22 changes: 13 additions & 9 deletions examples/turtlebot3-gazebo.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,26 @@
# roslaunch turtlebot3_gazebo turtlebot3_world.launch
# roslaunch turtlebot3_teleop turtlebot3_teleop_key.launch

{ pkgs ? import ../. {} }:
{
pkgs ? import ../. { },
}:
with pkgs;
with rosPackages.noetic;
with pythonPackages;

mkShell {
buildInputs = [
glibcLocales
(buildEnv { paths = [
rosbash
turtlebot3-description
turtlebot3-teleop
turtlebot3-gazebo
gazebo-plugins
xacro
]; })
(buildEnv {
paths = [
rosbash
turtlebot3-description
turtlebot3-teleop
turtlebot3-gazebo
gazebo-plugins
xacro
];
})
];

ROS_HOSTNAME = "localhost";
Expand Down
50 changes: 28 additions & 22 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,41 @@
flake-utils.url = "github:numtide/flake-utils";
};

outputs = { self, nixpkgs, flake-utils }:
outputs =
{
self,
nixpkgs,
flake-utils,
}:
with nixpkgs.lib;
with flake-utils.lib;
eachSystem systems.flakeExposed (system: let
pkgs = import nixpkgs {
inherit system;
overlays = [ self.overlays.default ];
};
in {
legacyPackages = pkgs.rosPackages;
eachSystem systems.flakeExposed (
system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ self.overlays.default ];
};
in
{
legacyPackages = pkgs.rosPackages;

devShells = {
example-turtlebot3-gazebo = import ./examples/turtlebot3-gazebo.nix { inherit pkgs; };
example-ros2-basic = import ./examples/ros2-basic.nix { inherit pkgs; };
example-ros2-gz = import ./examples/ros2-gz.nix { inherit pkgs; };
devShells = {
example-turtlebot3-gazebo = import ./examples/turtlebot3-gazebo.nix { inherit pkgs; };
example-ros2-basic = import ./examples/ros2-basic.nix { inherit pkgs; };
example-ros2-gz = import ./examples/ros2-gz.nix { inherit pkgs; };

# Development environment for the custom GitHub action
nix-ros-build-action = pkgs.callPackage ./.github/actions/nix-ros-build-action/shell.nix { };
};
}) // {
# Development environment for the custom GitHub action
nix-ros-build-action = pkgs.callPackage ./.github/actions/nix-ros-build-action/shell.nix { };
};
}
)
// {
overlays.default = import ./overlay.nix;
nixosModules.default = ./modules;

overlay = nixpkgs.lib.warn
"'nix-ros-overlay.overlay' is deprecated, use 'nix-ros-overlay.overlays.default' instead"
self.overlays.default;
nixosModule = nixpkgs.lib.warn
"'nix-ros-overlay.nixosModule' is deprecated, use 'nix-ros-overlay.nixosModules.default' instead"
self.nixosModules.default;
overlay = nixpkgs.lib.warn "'nix-ros-overlay.overlay' is deprecated, use 'nix-ros-overlay.overlays.default' instead" self.overlays.default;
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";
Expand Down
Loading