Aller au contenu

Using niv#

What is niv?#

Niv is a tool for sources convenient management in nix. Il simplifies the process of adding sources and tracking specific branches, tags or other. Current home of this project. This project is currently considered as deprecated. nix users are supposed to use nix flakes today.

Init niv#

Niv will add a json file to track sources and a nix file to parse it and grab the corresponding sources. Both files are put under a nix directory

niv init

Add a source#

niv can track sources via github or other HTTP server repo. It can track branches or specific tags. A template can be used to build url from version, branches or other settings provided to the command line.

# Using github
niv add stedolan/jq
niv add NixOS/nixpkgs -n nixpkgs -b nixpkgs-unstable

# Using an http source
niv add my-package -v alpha-0.1 -t http://example.com/archive/<version>.zip

# Using a git source (EXPERIMENTAL COMMAND)
niv add git https://git.corp.caascad.com/caascad/applications/trackbone.git
niv show

Update sources references#

niv can also retrieve updates from sources.

niv update my-package

Target a branch#

niv modify trackbone -b test

Use niv sources in nix expression#

The niv command only manages the nix directory it has created. To be able to use it in nix expressions, it is necessary to import the sources.nix file. This is a full example managing the trackbone build:

mkdir /tmp/build-trackbone && cd /tmp/build-trackbone

niv init
niv add git https://git.corp.caascad.com/caascad/applications/trackbone.git

cat <<EOF>default.nix
let
  sources= import ./nix/sources.nix;
in {
  trackbone = import sources.trackbone.outPath {
    doCheck = false;
    dontStrip = false;
  }
}
EOF