Skip to content
Open
Show file tree
Hide file tree
Changes from 6 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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,7 @@ site/*
Zone.Identifier

#Vector Lock File
can/dbc/**/*.ldb
can/dbc/**/*.ldb

# Arduino-cli files
.arduino*
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2022 UT Longhorn Racing Solar
Copyright (c) 2026 UT Longhorn Racing Solar

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
31 changes: 6 additions & 25 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
description = "LHRs STM32 Embedded Dev";
description = "LHRs Embedded Dev";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/23.05";
Expand All @@ -23,6 +23,7 @@
pkgs.gcc
pkgs.clang
pkgs.clang-tools
pkgs.arduino-cli
pkgs.lld
pkgs.bear
pkgs.cmake
Expand Down Expand Up @@ -69,32 +70,12 @@
echo "${armGccMessage}"
${if armGcc != null then "export PATH=$PATH:${armGcc}/bin" else ""}

# Provide lsusb-mac alias
if [[ "$OSTYPE" == "darwin"* ]]; then
lsusb_mac() {
system_profiler SPUSBDataType
}
export -f lsusb_mac
echo "Run: lsusb_mac (macOS USB info)"

ls_stm32_dev_port() {
ls /dev/cu.*
}
export -f ls_stm32_dev_port
echo "On Mac run: ls_stm32_dev_port (to list STM32 serial port)"
else
echo "Run: lsusb (Linux USB info)"
if [ -f "./nix-hook.sh" ]; then
# Make it executable
chmod +x ./nix-hook.sh
source ./nix-hook.sh
Comment on lines +71 to +73
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Modifying file permissions with chmod +x inside a shellHook is unnecessary and can fail on read-only filesystems (e.g., in certain CI environments or Nix builds). It is better to ensure the script is committed with executable permissions in the repository.

              source ./nix-hook.sh

fi

if [ ! -d .venv ]; then
python3 -m venv .venv
echo "Creating python venv"
fi
source .venv/bin/activate
echo "Installing python requirements"
if [ -f requirements.txt ]; then
pip install -r requirements.txt
fi
echo "Dev environment loaded for ${system}!"
'';
};
Expand Down
51 changes: 51 additions & 0 deletions nix-hook.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env bash

# Exit on error
set -e
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Using set -e in a script that is intended to be sourced into an interactive shell (as seen in flake.nix) is problematic. It modifies the behavior of the parent shell, causing the entire terminal session to exit if any subsequent command returns a non-zero status. This should be removed for scripts meant to be sourced.


# Get the directory where this script is located
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

# --- Python Setup ---
export PIP_DISABLE_PIP_VERSION_CHECK=1
VENV_PATH="$SCRIPT_DIR/.venv"
REQ_PATH="$SCRIPT_DIR/requirements.txt"
SENTINEL="$VENV_PATH/.pip_installed"

if [ ! -d "$VENV_PATH" ]; then
echo "Creating virtual environment..."
python3 -m venv "$VENV_PATH"
fi

source "$VENV_PATH/bin/activate"

if [ -f "$REQ_PATH" ]; then
# Only install if the sentinel doesn't exist OR requirements.txt is newer than the sentinel
if [ ! -f "$SENTINEL" ] || [ "$REQ_PATH" -nt "$SENTINEL" ]; then
echo "Updating python requirements..."
if pip install -q -r "$REQ_PATH"; then
touch "$SENTINEL"
else
echo "Error: pip install failed."
exit 1
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The exit command will terminate the entire shell session when this script is sourced. Use return instead to stop the script's execution while keeping the terminal open.

Suggested change
exit 1
return 1

fi
fi
fi

# --- Arduino Setup ---
# Isolate Arduino data to the project folder

if ! arduino-cli core list | grep -q "esp32" > /dev/null; then
echo "Installing ESP32 core..."
arduino-cli core update-index > /dev/null
arduino-cli core install esp32:esp32 > /dev/null
fi

# --- Helpers ---
if [[ "$OSTYPE" == "darwin"* ]]; then
lsusb_mac() { system_profiler SPUSBDataType; }
export -f lsusb_mac

ls_stm32_dev_port() { ls /dev/cu.*; }
export -f ls_stm32_dev_port
Comment on lines +67 to +71
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The ESP32 core installation command is currently commented out, but the check and the 'Installing...' message are active. This causes the script to print the installation message every time the shell is entered without actually performing the installation. Either uncomment the installation command or remove this block to avoid the redundant message loop.

Suggested change
lsusb_mac() { system_profiler SPUSBDataType; }
export -f lsusb_mac
ls_stm32_dev_port() { ls /dev/cu.*; }
export -f ls_stm32_dev_port
if ! arduino-cli core list | grep -q "esp32" > /dev/null; then
echo "Installing ESP32 core..."
arduino-cli core update-index > /dev/null
arduino-cli core install esp32:esp32 > /dev/null
fi

fi
File renamed without changes.
Loading