nip/docs/build-troubleshooting.md

9.7 KiB

NIP Build System - Troubleshooting Guide

Common Issues and Solutions

Build Failures

Issue: Build fails with "command not found"

Symptoms:

Error: nix-build: command not found

Cause: Source system not installed or not in PATH

Solution:

  1. Check if source is installed:

    nip sources
    
  2. Install the missing source system:

  3. Or use a different source:

    nip build <package> --source=<available-source>
    

Issue: Build times out

Symptoms:

Error: Build timed out after 2 hours

Cause: Large package or slow system

Solution:

  1. Increase timeout in config (~/.config/nip/build.kdl):

    build {
        timeout "4h"
    }
    
  2. Or check if binary packages are available (Nix, Gentoo)

Issue: Build fails with compilation errors

Symptoms:

Error: compilation failed
gcc: error: ...

Cause: Missing dependencies, incompatible variants, or upstream issues

Solution:

  1. Try without variants first:

    nip build <package>
    
  2. Use verbose mode to see full error:

    nip build <package> --verbose
    
  3. Try a different source system:

    nip build <package> --source=nix
    
  4. Check if package is available:

    nip sources <package>
    

Variant Issues

Issue: Variant not working

Symptoms:

⚠️  Warning: Unmapped variant: +myfeature

Cause: No mapping exists for this variant

Solution:

  1. Check available variants in documentation

  2. Create custom mapping in ~/.config/nip/variant-mappings.json:

    {
      "mypackage": {
        "feature": {
          "enabled": {
            "nix": "enableFeature = true",
            "pkgsrc": "feature",
            "gentoo": "feature",
            "description": "Enable feature"
          }
        }
      }
    }
    
  3. Use verbose mode to see how variants are translated:

    nip build <package> +myfeature --verbose
    

Issue: Conflicting variants

Symptoms:

Error: Cannot enable both +wayland and +X

Cause: Some variants are mutually exclusive

Solution: Choose one variant:

nip build firefox +wayland  # OR
nip build firefox +X

Cache Issues

Issue: Cache not working

Symptoms:

  • Rebuilds every time
  • Cache stats show 0 builds

Cause: Cache directory not writable or corrupted

Solution:

  1. Check cache directory permissions:

    ls -la ~/.cache/nip
    
  2. Clear and rebuild cache:

    nip cache clear
    nip build <package>
    
  3. Check disk space:

    df -h ~/.cache
    

Issue: Cache taking too much space

Symptoms:

  • Large cache directory
  • Low disk space

Solution:

  1. Check cache size:

    nip cache stats
    
  2. Clean old builds:

    nip cache clean
    
  3. Clear all cache:

    nip cache clear
    

Package Discovery Issues

Issue: Package not found

Symptoms:

Error: Package 'mypackage' not found in any source

Cause: Package name incorrect or not available

Solution:

  1. Search across all sources:

    nip sources mypackage
    
  2. Check package name spelling

  3. Try alternative names:

    nip sources firefox
    nip sources firefox-esr
    
  4. Check if source is installed:

    nip sources
    

Issue: Source system not detected

Symptoms:

⚠️  No source systems detected

Cause: No source systems installed

Solution:

  1. Install at least one source system:

    • Nix: Easiest to install, largest package collection
    • PKGSRC: Good for BSD systems
    • Gentoo: For Gentoo Linux
  2. Verify installation:

    # Nix
    ls /nix
    
    # PKGSRC
    ls /usr/pkgsrc
    
    # Gentoo
    which emerge
    

Installation Issues

Issue: Permission denied during installation

Symptoms:

Error: Permission denied: /Programs/...

Cause: Insufficient permissions to write to /Programs

Solution:

  1. Run with appropriate privileges (if needed)

  2. Or build without installing:

    nip build <package> --no-install
    

Symptoms:

  • Package installed but not in PATH
  • Executables not found

Cause: Symlink creation failed

Solution:

  1. Check /System/Links/Executables:

    ls -la /System/Links/Executables
    
  2. Manually create symlinks if needed

  3. Check permissions on /System/Links

Configuration Issues

Issue: Configuration not loaded

Symptoms:

  • Custom settings ignored
  • Using default values

Cause: Configuration file not found or invalid

Solution:

  1. Check configuration file location:

    cat ~/.config/nip/build.kdl
    
  2. Validate KDL syntax

  3. Use verbose mode to see loaded config:

    nip build <package> --verbose
    

Issue: Variant mappings not working

Symptoms:

  • Custom mappings ignored
  • Unmapped variant warnings

Cause: JSON syntax error or wrong location

Solution:

  1. Check file location:

    cat ~/.config/nip/variant-mappings.json
    
  2. Validate JSON syntax:

    python3 -m json.tool ~/.config/nip/variant-mappings.json
    
  3. Check for typos in package/domain/value names

Source-Specific Issues

Nix Issues

Issue: Nix expression generation fails

Symptoms:

Error: Failed to generate Nix expression

Solution:

  1. Check package name is valid
  2. Use verbose mode to see expression
  3. Try without overrides first

Issue: nix-build fails

Symptoms:

Error: nix-build failed

Solution:

  1. Check Nix installation:

    nix-env --version
    
  2. Update nixpkgs:

    nix-channel --update
    
  3. Try with verbose mode

PKGSRC Issues

Issue: Package not found in /usr/pkgsrc

Symptoms:

Error: Package not found in PKGSRC tree

Solution:

  1. Update PKGSRC tree:

    cd /usr/pkgsrc
    cvs update -dP
    
  2. Check package category:

    find /usr/pkgsrc -name <package>
    

Issue: bmake fails

Symptoms:

Error: bmake failed

Solution:

  1. Check mk.conf syntax
  2. Try without PKG_OPTIONS
  3. Check PKGSRC documentation

Gentoo Issues

Issue: emerge fails

Symptoms:

Error: emerge failed

Solution:

  1. Sync Portage tree:

    emerge --sync
    
  2. Check USE flags:

    emerge -pv <package>
    
  3. Try without USE flags first

Issue: Root privileges required

Symptoms:

Error: emerge requires root privileges

Solution:

  1. Run with sudo (if appropriate)
  2. Or use --no-install to build only

Performance Issues

Issue: Builds are slow

Symptoms:

  • Builds take very long
  • System is slow during builds

Solution:

  1. Increase parallel jobs:

    nip build <package> --jobs=8
    
  2. Or in config:

    build {
        jobs 8
    }
    
  3. Use binary packages when available (Nix, Gentoo)

  4. Check system resources:

    top
    df -h
    

Issue: High memory usage

Symptoms:

  • System runs out of memory
  • Build killed by OOM

Solution:

  1. Reduce parallel jobs:

    nip build <package> --jobs=2
    
  2. Close other applications

  3. Add swap space

Debugging Tips

Enable Verbose Mode

Always use verbose mode when troubleshooting:

nip build <package> --verbose

This shows:

  • Source detection
  • Variant translation
  • Build commands
  • Full build output
  • Grafting steps

Check Build Logs

Build logs are stored in cache directory:

ls ~/.cache/nip/logs/

View recent log:

cat ~/.cache/nip/logs/nix/firefox-*.log

Test Without Installing

Build without installing to test:

nip build <package> --no-install

Force Rebuild

Skip cache to ensure fresh build:

nip build <package> --rebuild

Keep Work Files

Keep intermediate files for inspection:

nip build <package> --keep-work

Getting More Help

Check Documentation

  • User Guide: source-build-guide.md
  • Help Reference: build-system-help.md
  • Configuration: build-configuration.md

Check Source System Documentation

Report Issues

If you encounter a bug:

  1. Use verbose mode to capture details
  2. Check if issue is reproducible
  3. Report with full error message and steps to reproduce

Quick Reference

Diagnostic Commands

# Check available sources
nip sources

# Search for package
nip sources <package>

# Check cache
nip cache stats

# Build with verbose output
nip build <package> --verbose

# Force rebuild
nip build <package> --rebuild

# Build without installing
nip build <package> --no-install

Common Fixes

# Clear cache
nip cache clear

# Clean old builds
nip cache clean

# Try different source
nip build <package> --source=nix

# Build without variants
nip build <package>

# Increase timeout
# Edit ~/.config/nip/build.kdl

Prevention

Best Practices

  1. Start simple: Build without variants first
  2. Use cache: Don't use --rebuild unnecessarily
  3. Check sources: Use nip sources before building
  4. Keep updated: Update source systems regularly
  5. Monitor space: Clean cache periodically
  6. Use verbose: When in doubt, use --verbose

Regular Maintenance

# Weekly: Clean old builds
nip cache clean

# Monthly: Check cache size
nip cache stats

# As needed: Clear cache
nip cache clear

Happy building! 🚀