GitHub - nmattia/niv: Easy dependency management for Nix projects
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:
-
Adding Dependencies: Use commands like
niv add [name] -v [version] -t "[URL]"to specify versioned sources (e.g.,-t "https://.../<version>.tar.gz"). -
Private Repositories: Access private GitHub repos by creating a
.netrcfile with credentials and setting theGITHUB_TOKENenvironment variable duringniv 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
nixpkgsvia 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-srcoroutPath).
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.