Skip to content

Troubleshooting Guide

This guide covers common issues you might encounter when using Bufrnix and provides practical solutions to resolve them.

If you can’t find a solution here:

  1. Check the examples directory for similar use cases
  2. Enable debug mode for detailed error information
  3. Search existing GitHub issues
  4. Create a new issue with your configuration and error details

Enable debug mode to get detailed information about what Bufrnix is doing:

config = {
debug = {
enable = true;
verbosity = 3; # 1-3, higher = more verbose
logFile = "debug.log"; # Save to file for analysis
};
# Your other configuration...
};

Error Message:

error: proto file not found: ./proto/example/v1/example.proto

Causes and Solutions:

  1. File doesn’t exist: Verify the file exists at the specified path

    Terminal window
    ls -la proto/example/v1/example.proto
  2. Incorrect path: Check the path in your configuration

    protoc.files = [
    "./proto/example/v1/example.proto" # Relative to config.root
    ];
  3. Wrong root directory: Ensure root points to the correct directory

    config = {
    root = ./.; # Should point to directory containing proto/
    };

Error Message:

Import "google/protobuf/timestamp.proto" was not found

Solution: Add well-known types to include directories

protoc.includeDirectories = [
"./proto"
"${pkgs.protobuf}/include" # Well-known types
"${pkgs.googleapis-common-protos}/share/googleapis-common-protos" # Google APIs
];

Error Message:

package github.com/yourorg/yourproject/gen/go/example/v1 is not in GOROOT or GOPATH

Solutions:

  1. Check go_package option in proto file:

    option go_package = "github.com/yourorg/yourproject/gen/go/example/v1;examplev1";
  2. Ensure generated code is in Go module:

    Terminal window
    go mod tidy
  3. Verify Go module path matches generated code:

    Terminal window
    # Check go.mod file
    module github.com/yourorg/yourproject

Error Message:

error: builder for '/nix/store/...' failed with exit code 1

Troubleshooting steps:

  1. Enable debug mode for detailed logs:

    debug = {
    enable = true;
    verbosity = 3;
    };
  2. Check build dependencies are available:

    Terminal window
    nix-shell -p protobuf protoc-gen-go
  3. Verify system architecture matches configuration:

    let
    system = builtins.currentSystem; # Use this instead of hardcoding
  4. Clear Nix cache if persistent issues:

    Terminal window
    nix-collect-garbage
    nix build --no-cache

Error: Undefined gRPC methods

undefined: examplev1.UnimplementedGreetingServiceServer

Solution: Ensure gRPC generation is enabled

languages.go = {
enable = true;
grpc.enable = true; # This was missing
};

Error: Validation functions not found

undefined: req.Validate

Solution: Enable validation plugin

languages.go = {
enable = true;
validate.enable = true; # Legacy validation
# OR
protovalidate.enable = true; # Modern validation
};

Error: Module not found

Cannot find module '@myorg/proto'

Solutions:

  1. Check package.json generation:

    languages.js = {
    enable = true;
    es = {
    enable = true;
    generatePackageJson = true;
    packageName = "@myorg/proto";
    };
    };
  2. Install generated packages:

    Terminal window
    npm install ./gen/js # If package.json was generated

Error: TypeScript type errors

Property 'myField' does not exist on type 'MyMessage'

Solution: Ensure TypeScript target is enabled

languages.js = {
enable = true;
es = {
enable = true;
target = "ts"; # Generate TypeScript
};
};

Error: Package import issues

Target of URI doesn't exist: 'package:my_app_proto/...'

Solution: Run dart pub get in the project directory

Terminal window
cd path/to/dart/project
dart pub get

Error: Class not found

Class 'MyApp\Proto\MyMessage' not found

Solutions:

  1. Check namespace configuration:

    languages.php = {
    enable = true;
    namespace = "MyApp\\Proto";
    };
  2. Ensure Composer autoloading:

    {
    "autoload": {
    "psr-4": {
    "MyApp\\Proto\\": "gen/php/"
    }
    }
    }
  3. Run composer install:

    Terminal window
    composer install

Error: Package reference issues

The type or namespace name 'Google' could not be found

Solution: Ensure project file generation is enabled

languages.csharp = {
enable = true;
generateProjectFile = true;
protobufVersion = "3.31.0";
};

Then restore packages:

Terminal window
dotnet restore gen/csharp/

Symptoms:

  • nix build takes a long time
  • Large number of proto files cause timeouts

Solutions:

  1. Use specific file lists instead of globbing:

    protoc.files = [
    "./proto/user/v1/user.proto"
    "./proto/product/v1/product.proto"
    ];
    # Instead of: ["./proto/**/*.proto"]
  2. Enable parallel builds:

    Terminal window
    # Add to ~/.config/nix/nix.conf
    max-jobs = auto
  3. Use binary caches:

    Terminal window
    # Add to ~/.config/nix/nix.conf
    substituters = https://cache.nixos.org https://nix-community.cachix.org
    trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=

Symptoms:

  • Generated code is much larger than expected
  • Build artifacts are consuming too much disk space

Solutions:

  1. Use lite runtime for C++:

    languages.cpp = {
    enable = true;
    runtime = "lite";
    optimizeFor = "CODE_SIZE";
    };
  2. Optimize JavaScript output:

    languages.js = {
    enable = true;
    es = {
    enable = true;
    target = "js"; # Smaller than TypeScript
    };
    };
  3. Use vtprotobuf for Go (smaller and faster):

    languages.go = {
    enable = true;
    vtprotobuf = {
    enable = true;
    options = ["features=marshal+unmarshal+size"];
    };
    };

Error Message:

error: experimental Nix feature 'flakes' is disabled

Solution: Enable flakes in Nix configuration

Terminal window
# For NixOS, add to /etc/nixos/configuration.nix:
nix.settings.experimental-features = [ "nix-command" "flakes" ];
# For non-NixOS systems, add to ~/.config/nix/nix.conf:
experimental-features = nix-command flakes

Error Message:

Permission denied: cannot write to gen/go/

Solutions:

  1. Check directory permissions:

    Terminal window
    ls -la gen/
    chmod -R u+w gen/
  2. Ensure output directory is writable:

    Terminal window
    mkdir -p gen/go
    chmod u+w gen/go
  3. On macOS, check Nix permissions:

    Terminal window
    # Ensure Nix daemon has necessary permissions
    sudo launchctl stop org.nixos.nix-daemon
    sudo launchctl start org.nixos.nix-daemon

Kotlin gRPC on Apple Silicon:

Bufrnix automatically handles gRPC Java plugin compatibility on Apple Silicon Macs by using Rosetta 2 for x86_64 binaries. If you encounter issues:

  1. Install Rosetta 2 (if not already installed):

    Terminal window
    /usr/sbin/softwareupdate --install-rosetta --agree-to-license
  2. Verify the plugin wrapper is working:

    Terminal window
    nix build .#proto
    ./result/bin/bufrnix
  3. If you see “Bad CPU type” errors:

    Terminal window
    # Check if Rosetta 2 is properly installed
    /usr/bin/arch -x86_64 /usr/bin/true && echo "Rosetta 2 is working"

The gRPC Java plugin is automatically wrapped to use Rosetta 2 when running on ARM64 systems, ensuring compatibility without requiring manual intervention.

Error Message:

error: a 'x86_64-linux' with features {} is required to build...

Solution: Use correct system identifier

let
system = builtins.currentSystem; # Auto-detect
# Or specify explicitly:
# system = "x86_64-darwin"; # macOS Intel
# system = "aarch64-darwin"; # macOS Apple Silicon
# system = "x86_64-linux"; # Linux x86_64
# system = "aarch64-linux"; # Linux ARM64

Error Message:

error: attribute 'invalidOption' missing

Solution: Check configuration against the Configuration Reference

Error Message:

error: conflicting options for protoc-gen-go

Solution: Check for conflicting options in different plugins

languages.go = {
enable = true;
options = ["paths=source_relative"];
grpc = {
enable = true;
options = ["paths=source_relative"]; # Consistent with parent
};
};

Error Message:

command not found: go

Solution: Add language runtimes to development shell

devShells.default = pkgs.mkShell {
packages = with pkgs; [
go
dart
nodejs
php83
python3
# Add other runtimes as needed
];
};

Problem: IDE doesn’t recognize generated code

Solutions:

  1. For VS Code with Go:

    {
    "go.toolsEnvVars": {
    "GOPATH": "${workspaceFolder}/gen/go"
    }
    }
  2. For IntelliJ with Kotlin:

    • Mark gen/kotlin as source directory
    • Ensure Gradle sync is enabled
  3. For general IDE support:

    • Ensure generated code is in the IDE’s source path
    • Run nix develop before starting the IDE

Error Message:

rpc error: code = Unavailable desc = connection error

Solutions:

  1. Check server is running:

    Terminal window
    netstat -ln | grep :50051
  2. Test with grpcurl:

    Terminal window
    grpcurl -plaintext localhost:50051 list
  3. Check firewall settings:

    Terminal window
    # On Linux
    sudo ufw allow 50051
    # On macOS
    sudo pfctl -f /etc/pf.conf

Error Message:

cannot import name 'user_pb2' from 'proto'

Solution: Ensure Python path includes generated code

import sys
sys.path.append('gen/python')
import user_pb2
Terminal window
# Check Nix installation
nix --version
# Check flakes are enabled
nix eval --expr 'builtins.currentSystem'
# Check available packages
nix search nixpkgs protobuf
Terminal window
# List generated files
find gen/ -name "*.pb.go" -o -name "*.pb.ts" -o -name "*.pb.dart"
# Check file sizes
du -sh gen/*/
# Verify file contents
head -20 gen/go/example/v1/example.pb.go
Terminal window
# Validate proto syntax
protoc --proto_path=proto --dry_run proto/**/*.proto
# Check imports
grep -r "import" proto/
# Lint with buf (if available)
buf lint
Terminal window
# Time the build
time nix build
# Check memory usage
nix build --option build-use-substitutes false --option build-max-jobs 1
# Profile build
nix build --option build-use-substitutes false --show-trace

Create a debug build with maximum verbosity:

{
packages.debug = bufrnix.lib.mkBufrnixPackage {
inherit (pkgs) lib pkgs;
config = {
debug = {
enable = true;
verbosity = 3;
logFile = "bufrnix-debug.log";
};
# Minimal configuration to isolate issues
languages.go = {
enable = true;
outputPath = "debug/go";
};
};
};
}

Test with minimal configuration:

config = {
root = ./.;
protoc.files = ["./proto/simple.proto"]; # Single file
languages.go = {
enable = true;
outputPath = "debug/go";
# No additional plugins
};
};

Verify all required packages are available:

Terminal window
nix-shell -p protobuf protoc-gen-go protoc-gen-go-grpc
protoc --version
protoc-gen-go --version
protoc-gen-go-grpc --version

When reporting issues, please include:

  1. Bufrnix version or commit hash
  2. Complete flake.nix configuration
  3. Error message and stack trace
  4. Debug log output (with debug.verbosity = 3)
  5. System information (OS, architecture)
  6. Example proto files that cause the issue

Create a minimal example that reproduces the issue:

{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
bufrnix.url = "github:conneroisu/bufrnix";
};
outputs = { nixpkgs, bufrnix, ... }:
let
system = "x86_64-linux";
pkgs = nixpkgs.legacyPackages.${system};
in {
packages.default = bufrnix.lib.mkBufrnixPackage {
inherit (pkgs) lib pkgs;
config = {
root = ./.;
debug.enable = true;
protoc.files = ["./example.proto"];
languages.go.enable = true;
};
};
};
}

With a simple proto file:

syntax = "proto3";
package example;
option go_package = "example.com/test;test";
message TestMessage {
string text = 1;
}

This helps maintainers reproduce and fix issues quickly.

  1. Start simple: Begin with basic configuration and add complexity gradually
  2. Use examples: Base your configuration on working examples
  3. Enable debug mode: Use debug mode during development
  4. Test incrementally: Test each language addition separately
  5. Keep configurations consistent: Use similar patterns across projects
  1. Update regularly: Keep Bufrnix and dependencies up to date
  2. Clean builds: Periodically run nix-collect-garbage
  3. Validate proto files: Use buf lint to catch issues early
  4. Monitor performance: Watch for degradation in build times

By following this guide, you should be able to resolve most issues with Bufrnix. For additional help, don’t hesitate to reach out to the community through GitHub issues or discussions.