q3-dsb-labs/devenv.nix
2025-02-10 15:16:23 +01:00

70 lines
1.5 KiB
Nix

{ pkgs, lib, config, inputs, ... }:
{
env.GREET = "devenv";
# https://devenv.sh/packages/
packages = [ pkgs.verilator pkgs.gtkwave ];
scripts.hello.exec = ''
echo hello from $GREET
'';
scripts.gen_wave.exec = ''
if [ -z "$1" ]; then
echo "Usage: $0 <filename> [additional_verilator_options]"
exit 1
fi
# Get the full filename and the base name without the extension
FILENAME="$1"
BASENAME="V''\${FILENAME%.*}"
# Shift the parameters to get any additional options
shift
# Run the verilator command with the given filename
verilator --trace --binary --timing "$FILENAME" "$@"
# Check if verilator generated the output successfully
if [ $? -ne 0 ]; then
echo "Verilator failed."
exit 1
fi
# Run the simulation
./obj_dir/"$BASENAME"
# Check if the simulation produced output.vcd
if [ $? -ne 0 ]; then
echo "Simulation failed."
exit 1
fi
# Open the VCD file with GTKWave
gtkwave output.vcd
'';
enterShell = ''
hello
git --version
'';
# https://devenv.sh/tasks/
# tasks = {
# "myproj:setup".exec = "mytool build";
# "devenv:enterShell".after = [ "myproj:setup" ];
# };
# https://devenv.sh/tests/
enterTest = ''
echo "Running tests"
git --version | grep --color=auto "${pkgs.git.version}"
'';
# https://devenv.sh/pre-commit-hooks/
# pre-commit.hooks.shellcheck.enable = true;
# See full reference at https://devenv.sh/reference/options/
}