Summary (AI generated)

Archived original version »

Summary of Niv’s Dependency Management in Nix Projects:

Niv simplifies dependency management for Nix projects by maintaining a sources.json file that tracks packages, versions, and URLs. Key features include:

  1. Adding Dependencies: Use commands like niv add [name] -v [version] -t "[URL]" to specify versioned sources (e.g., -t "https://.../<version>.tar.gz").

  2. Private Repositories: Access private GitHub repos by creating a .netrc file with credentials and setting the GITHUB_TOKEN environment variable during niv add.

Importing into Nix Expressions:

  • Direct Import: For Nix-based packages (e.g., sources.niv), directly reference their derivations:

    
    { sources ? import ./sources.nix }:
    
    let niv = import sources.niv {}; in { ... }
    
    
  • Overlays: Integrate dependencies into nixpkgs via overlays to avoid duplication:

    
    overlay = _: pkgs: { niv = (import sources.niv {}).niv; };
    
    
  • File References: Use non-Nix packages by pointing to their store paths (e.g., src = sources.hello-src or outPath).

Subpaths and Modules: Access subdirectories of a source with:


sources.package + "/subdir"

Local Development Overrides: Temporarily replace remote dependencies with local paths via environment variables like NIV_OVERRIDE_<name>, where <name> is the package’s sanitized identifier (e.g., my_package_foo).

This workflow streamlines dependency management while allowing flexibility for development, testing, and integration into Nix expressions.