2019-01-17 23:59:01 +03:00
|
|
|
|
# niv
|
|
|
|
|
|
2019-02-01 00:05:45 +03:00
|
|
|
|
[![CircleCI](https://circleci.com/gh/nmattia/niv.svg?style=svg)](https://circleci.com/gh/nmattia/niv)
|
2019-04-15 16:17:37 +03:00
|
|
|
|
[![Netlify Status](https://api.netlify.com/api/v1/badges/48532eaa-259f-4ca2-aadf-67f7c6b957fd/deploy-status)](https://niv.nmattia.com)
|
2019-02-01 00:05:45 +03:00
|
|
|
|
|
2019-06-15 17:44:20 +03:00
|
|
|
|
Painless dependencies for [Nix] projects. Read more in the [Getting started](#getting-started) section below.
|
2019-01-17 23:59:01 +03:00
|
|
|
|
|
2019-04-14 15:49:13 +03:00
|
|
|
|
<p align="center">
|
|
|
|
|
<img src="https://niv.nmattia.com/niv.svg">
|
|
|
|
|
</p>
|
|
|
|
|
|
2019-02-05 17:18:42 +03:00
|
|
|
|
## Install
|
|
|
|
|
|
|
|
|
|
``` bash
|
|
|
|
|
$ nix-env -iA niv -f https://github.com/nmattia/niv/tarball/master
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## Build
|
2019-01-18 01:00:48 +03:00
|
|
|
|
|
|
|
|
|
Inside the provided nix shell:
|
|
|
|
|
|
|
|
|
|
``` bash
|
2019-04-05 12:43:57 +03:00
|
|
|
|
$ repl
|
2019-01-18 01:00:48 +03:00
|
|
|
|
```
|
|
|
|
|
|
2019-03-01 12:24:15 +03:00
|
|
|
|
Run the test suite with this command:
|
|
|
|
|
|
|
|
|
|
``` bash
|
|
|
|
|
$ ./script/test
|
|
|
|
|
```
|
|
|
|
|
|
2019-01-17 23:59:01 +03:00
|
|
|
|
## Usage
|
|
|
|
|
|
2019-02-08 21:29:48 +03:00
|
|
|
|
`niv` simplifies [adding](#add) and [updating](#update) dependencies in Nix
|
|
|
|
|
projects. It uses a single file, `nix/sources.json`, where it stores the data
|
|
|
|
|
necessary for fetching and updating the packages.
|
|
|
|
|
|
|
|
|
|
* [Add](#add): inserts a package in `nix/sources.json`.
|
|
|
|
|
* [Update](#update): updates one or all packages in `nix/sources.json`.
|
|
|
|
|
* [Drop](#drop): deletes a package from `nix/sources.json`.
|
|
|
|
|
|
|
|
|
|
`niv` has two more utility functions:
|
|
|
|
|
|
2019-04-15 00:50:42 +03:00
|
|
|
|
* [Init](#init): bootstraps a Nix project, in particular creates a
|
2019-02-08 21:29:48 +03:00
|
|
|
|
`nix/sources.json` file containing `niv` and `nixpkgs` as well as a
|
|
|
|
|
`nix/sources.nix` file that returns the sources as a Nix object.
|
|
|
|
|
* [Show](#show): shows the packages' information.
|
2019-01-17 23:59:01 +03:00
|
|
|
|
|
2019-06-15 17:44:20 +03:00
|
|
|
|
The next two sections cover [common use cases](#getting-started) and [full command
|
2019-02-11 22:33:10 +03:00
|
|
|
|
description](#commands).
|
|
|
|
|
|
2019-06-15 17:44:20 +03:00
|
|
|
|
### Getting started
|
2019-02-11 22:33:10 +03:00
|
|
|
|
|
2019-02-11 22:56:42 +03:00
|
|
|
|
This section covers common use cases:
|
2019-02-11 22:33:10 +03:00
|
|
|
|
|
|
|
|
|
* [Bootstrapping a Nix project](#bootstrapping-a-nix-project).
|
2019-02-11 23:23:39 +03:00
|
|
|
|
* [Tracking a different nixpkgs branch](#tracking-a-nixpkgs-branch).
|
2019-02-11 22:56:42 +03:00
|
|
|
|
* [Importing packages from GitHub](#importing-packages-from-github).
|
2019-02-11 22:33:10 +03:00
|
|
|
|
* [Fetching packages from custom URLs](#using-custom-urls).
|
|
|
|
|
|
|
|
|
|
#### Bootstrapping a Nix project
|
|
|
|
|
|
2019-06-15 17:44:20 +03:00
|
|
|
|
Use the `init` command when starting a new Nix project or when porting an
|
|
|
|
|
existing Nix project to niv:
|
2019-02-11 22:33:10 +03:00
|
|
|
|
|
|
|
|
|
``` shell
|
|
|
|
|
$ niv init
|
|
|
|
|
...
|
|
|
|
|
$ tree
|
|
|
|
|
.
|
2019-06-15 17:44:20 +03:00
|
|
|
|
└── nix
|
|
|
|
|
├── sources.json
|
|
|
|
|
└── sources.nix
|
|
|
|
|
|
|
|
|
|
1 directory, 2 files
|
2019-02-11 22:33:10 +03:00
|
|
|
|
```
|
|
|
|
|
|
2019-02-11 22:56:42 +03:00
|
|
|
|
The file `nix/sources.json` is the file used by niv to store versions and is
|
|
|
|
|
initialized with niv and nixpkgs:
|
2019-02-11 22:33:10 +03:00
|
|
|
|
|
|
|
|
|
``` json
|
|
|
|
|
{
|
|
|
|
|
"nixpkgs": {
|
2019-02-11 23:23:39 +03:00
|
|
|
|
"url": "https://github.com/NixOS/nixpkgs-channels/archive/109a28ab954a0ad129f7621d468f829981b8b96c.tar.gz",
|
2019-02-11 22:33:10 +03:00
|
|
|
|
"owner": "NixOS",
|
|
|
|
|
"branch": "nixos-18.09",
|
|
|
|
|
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz",
|
|
|
|
|
"repo": "nixpkgs-channels",
|
2019-02-11 23:23:39 +03:00
|
|
|
|
"sha256": "12wnxla7ld4cgpdndaipdh3j4zdalifk287ihxhnmrzrghjahs3q",
|
2019-02-11 22:33:10 +03:00
|
|
|
|
"description": "Nixpkgs/NixOS branches that track the Nixpkgs/NixOS channels",
|
2019-02-11 23:23:39 +03:00
|
|
|
|
"rev": "109a28ab954a0ad129f7621d468f829981b8b96c"
|
2019-02-11 22:33:10 +03:00
|
|
|
|
},
|
|
|
|
|
"niv": {
|
2019-02-11 22:54:27 +03:00
|
|
|
|
"homepage": "https://github.com/nmattia/niv",
|
2019-02-11 23:23:39 +03:00
|
|
|
|
"url": "https://github.com/nmattia/niv/archive/72e77204544527279e8f1e2d982d29503482b8f4.tar.gz",
|
2019-02-11 22:33:10 +03:00
|
|
|
|
"owner": "nmattia",
|
|
|
|
|
"branch": "master",
|
|
|
|
|
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz",
|
|
|
|
|
"repo": "niv",
|
2019-02-11 23:23:39 +03:00
|
|
|
|
"sha256": "1zjcyzxhq9iwxh58j5d7sx1vz5s3r1f6gpmnfgj2a3rxmclwvn3c",
|
|
|
|
|
"description": "Easy dependency management for Nix projects",
|
|
|
|
|
"rev": "72e77204544527279e8f1e2d982d29503482b8f4"
|
2019-02-11 22:33:10 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2019-06-15 17:44:20 +03:00
|
|
|
|
To use those dependencies `import` the file `nix/sources.nix`, e.g.:
|
2019-02-11 22:33:10 +03:00
|
|
|
|
|
|
|
|
|
``` nix
|
2019-06-15 17:44:20 +03:00
|
|
|
|
{ sources ? import ./sources.nix }: # import the sources
|
2019-02-11 22:33:10 +03:00
|
|
|
|
with
|
|
|
|
|
{ overlay = _: pkgs:
|
2019-06-15 17:44:20 +03:00
|
|
|
|
{ niv = import sources.niv {}; # use the sources :)
|
2019-02-11 22:33:10 +03:00
|
|
|
|
};
|
|
|
|
|
};
|
2019-06-15 17:44:20 +03:00
|
|
|
|
import sources.nixpkgs # and use them again!
|
2019-02-11 22:33:10 +03:00
|
|
|
|
{ overlays = [ overlay ] ; config = {}; }
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
#### Tracking a nixpkgs branch
|
|
|
|
|
|
|
|
|
|
The `init` command sets the `nix/sources.json` file to track the latest commit
|
2019-06-16 11:22:57 +03:00
|
|
|
|
present on nixpkgs 18.09 when the command was run. Run the following command to
|
|
|
|
|
update it:
|
2019-02-11 22:33:10 +03:00
|
|
|
|
|
|
|
|
|
``` shell
|
|
|
|
|
$ niv update nixpkgs
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
To change the branch being tracked run this command:
|
|
|
|
|
|
|
|
|
|
``` shell
|
2019-02-11 22:46:54 +03:00
|
|
|
|
$ niv update nixpkgs -b nixos-19.03 # equivalent to --branch nixos-19.03
|
2019-02-11 22:33:10 +03:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
#### Importing packages from GitHub
|
|
|
|
|
|
|
|
|
|
The `add` command will infer information about the package being added, when
|
|
|
|
|
possible. This works very well for GitHub repositories. Run this command to add
|
|
|
|
|
[jq] to your project:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
``` shell
|
|
|
|
|
$ niv add stedolan/jq
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
The following data was added in `nix/sources.json` for `jq`:
|
|
|
|
|
|
|
|
|
|
``` json
|
|
|
|
|
{
|
|
|
|
|
"homepage": "http://stedolan.github.io/jq/",
|
2019-02-11 23:23:39 +03:00
|
|
|
|
"url": "https://github.com/stedolan/jq/archive/9fa2e51099c55af56e3e541dc4b399f11de74abe.tar.gz",
|
2019-02-11 22:33:10 +03:00
|
|
|
|
"owner": "stedolan",
|
|
|
|
|
"branch": "master",
|
|
|
|
|
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz",
|
|
|
|
|
"repo": "jq",
|
2019-02-11 23:23:39 +03:00
|
|
|
|
"sha256": "0819rvk8057qgcqvgn7fpldvly2pfdw9fxcjrlqa8gr59p8a1cic",
|
2019-02-11 22:33:10 +03:00
|
|
|
|
"description": "Command-line JSON processor",
|
2019-02-11 23:23:39 +03:00
|
|
|
|
"rev": "9fa2e51099c55af56e3e541dc4b399f11de74abe"
|
2019-02-11 22:33:10 +03:00
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
#### Using custom URLs
|
|
|
|
|
|
|
|
|
|
It is possible to use niv to fetch packages from custom URLs. Run this command
|
|
|
|
|
to add the Haskell compiler [GHC] to your `nix/sources.json`:
|
|
|
|
|
|
|
|
|
|
``` shell
|
|
|
|
|
$ niv add ghc \
|
|
|
|
|
-v 8.4.3 \
|
|
|
|
|
-t 'https://downloads.haskell.org/~ghc/<version>/ghc-<version>-i386-deb8-linux.tar.xz'
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
The option `-v` sets the "version" attribute to `8.4.3`. The option `-t` sets a
|
|
|
|
|
template that can be reused by niv when fetching a new URL (see the
|
|
|
|
|
documentation for [add](#add) and [update](#update)).
|
|
|
|
|
|
|
|
|
|
For updating the version of GHC used run this command:
|
|
|
|
|
|
|
|
|
|
``` shell
|
|
|
|
|
$ niv update ghc -v 8.6.2
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### Commands
|
|
|
|
|
|
2019-01-29 00:37:13 +03:00
|
|
|
|
```
|
|
|
|
|
NIV - Version manager for Nix projects
|
2019-01-24 23:58:22 +03:00
|
|
|
|
|
2019-01-29 00:37:13 +03:00
|
|
|
|
Usage: niv COMMAND
|
2019-01-24 23:58:22 +03:00
|
|
|
|
|
2019-01-29 00:37:13 +03:00
|
|
|
|
Available options:
|
|
|
|
|
-h,--help Show this help text
|
2019-01-24 23:58:22 +03:00
|
|
|
|
|
2019-01-29 00:37:13 +03:00
|
|
|
|
Available commands:
|
|
|
|
|
init Initialize a Nix project. Existing files won't be
|
|
|
|
|
modified.
|
|
|
|
|
add Add dependency
|
2019-01-31 01:56:35 +03:00
|
|
|
|
show
|
2019-01-29 00:37:13 +03:00
|
|
|
|
update Update dependencies
|
2019-06-15 17:17:21 +03:00
|
|
|
|
modify Modify dependency
|
2019-01-29 00:37:13 +03:00
|
|
|
|
drop Drop dependency
|
2019-01-31 01:56:35 +03:00
|
|
|
|
|
2019-01-29 00:37:13 +03:00
|
|
|
|
```
|
2019-01-17 23:59:01 +03:00
|
|
|
|
|
2019-02-11 22:33:10 +03:00
|
|
|
|
#### Add
|
2019-01-17 23:59:01 +03:00
|
|
|
|
|
|
|
|
|
```
|
2019-01-29 00:37:13 +03:00
|
|
|
|
Examples:
|
2019-01-17 23:59:01 +03:00
|
|
|
|
|
2019-01-29 00:37:13 +03:00
|
|
|
|
niv add stedolan/jq
|
2019-02-22 18:50:18 +03:00
|
|
|
|
niv add NixOS/nixpkgs-channels -n nixpkgs -b nixos-18.09
|
2019-01-29 00:37:13 +03:00
|
|
|
|
niv add my-package -v alpha-0.1 -t http://example.com/archive/<version>.zip
|
2019-01-17 23:59:01 +03:00
|
|
|
|
|
2019-01-31 22:44:10 +03:00
|
|
|
|
Usage: niv add [-n|--name NAME] PACKAGE ([-a|--attribute KEY=VAL] |
|
|
|
|
|
[-b|--branch BRANCH] | [-o|--owner OWNER] | [-r|--repo REPO] |
|
2019-03-01 00:22:21 +03:00
|
|
|
|
[-v|--version VERSION] | [-t|--template URL] | [-T|--type TYPE])
|
2019-01-29 00:37:13 +03:00
|
|
|
|
Add dependency
|
2019-01-17 23:59:01 +03:00
|
|
|
|
|
2019-01-29 00:37:13 +03:00
|
|
|
|
Available options:
|
2019-01-31 22:44:10 +03:00
|
|
|
|
-n,--name NAME Set the package name to <NAME>
|
|
|
|
|
-a,--attribute KEY=VAL Set the package spec attribute <KEY> to <VAL>
|
|
|
|
|
-b,--branch BRANCH Equivalent to --attribute branch=<BRANCH>
|
|
|
|
|
-o,--owner OWNER Equivalent to --attribute owner=<OWNER>
|
|
|
|
|
-r,--repo REPO Equivalent to --attribute repo=<REPO>
|
|
|
|
|
-v,--version VERSION Equivalent to --attribute version=<VERSION>
|
2019-01-31 01:56:35 +03:00
|
|
|
|
-t,--template URL Used during 'update' when building URL. Occurrences
|
|
|
|
|
of <foo> are replaced with attribute 'foo'.
|
2019-03-01 00:22:21 +03:00
|
|
|
|
-T,--type TYPE The type of the URL target. The value can be either
|
|
|
|
|
'file' or 'tarball'. If not set, the value is
|
|
|
|
|
inferred from the suffix of the URL.
|
2019-01-29 00:37:13 +03:00
|
|
|
|
-h,--help Show this help text
|
2019-01-31 01:56:35 +03:00
|
|
|
|
|
2019-01-17 23:59:01 +03:00
|
|
|
|
```
|
|
|
|
|
|
2019-02-11 22:33:10 +03:00
|
|
|
|
#### Update
|
2019-01-27 01:39:38 +03:00
|
|
|
|
|
2019-01-29 00:37:13 +03:00
|
|
|
|
```
|
|
|
|
|
Examples:
|
2019-01-23 23:55:26 +03:00
|
|
|
|
|
2019-01-29 00:37:13 +03:00
|
|
|
|
niv update
|
|
|
|
|
niv update nixpkgs
|
|
|
|
|
niv update my-package -v beta-0.2
|
2019-01-23 23:55:26 +03:00
|
|
|
|
|
2019-01-31 22:44:10 +03:00
|
|
|
|
Usage: niv update [PACKAGE] ([-a|--attribute KEY=VAL] | [-b|--branch BRANCH] |
|
|
|
|
|
[-o|--owner OWNER] | [-r|--repo REPO] | [-v|--version VERSION]
|
2019-03-01 00:22:21 +03:00
|
|
|
|
| [-t|--template URL] | [-T|--type TYPE])
|
2019-01-29 00:37:13 +03:00
|
|
|
|
Update dependencies
|
2019-01-23 23:55:26 +03:00
|
|
|
|
|
2019-01-29 00:37:13 +03:00
|
|
|
|
Available options:
|
2019-01-31 22:44:10 +03:00
|
|
|
|
-a,--attribute KEY=VAL Set the package spec attribute <KEY> to <VAL>
|
|
|
|
|
-b,--branch BRANCH Equivalent to --attribute branch=<BRANCH>
|
|
|
|
|
-o,--owner OWNER Equivalent to --attribute owner=<OWNER>
|
|
|
|
|
-r,--repo REPO Equivalent to --attribute repo=<REPO>
|
|
|
|
|
-v,--version VERSION Equivalent to --attribute version=<VERSION>
|
2019-01-31 01:56:35 +03:00
|
|
|
|
-t,--template URL Used during 'update' when building URL. Occurrences
|
|
|
|
|
of <foo> are replaced with attribute 'foo'.
|
2019-03-01 00:22:21 +03:00
|
|
|
|
-T,--type TYPE The type of the URL target. The value can be either
|
|
|
|
|
'file' or 'tarball'. If not set, the value is
|
|
|
|
|
inferred from the suffix of the URL.
|
2019-01-29 00:37:13 +03:00
|
|
|
|
-h,--help Show this help text
|
2019-01-31 01:56:35 +03:00
|
|
|
|
|
2019-01-29 00:37:13 +03:00
|
|
|
|
```
|
2019-01-23 23:55:26 +03:00
|
|
|
|
|
2019-02-11 22:33:10 +03:00
|
|
|
|
#### Drop
|
2019-01-27 01:39:38 +03:00
|
|
|
|
|
2019-01-29 00:37:13 +03:00
|
|
|
|
```
|
|
|
|
|
Examples:
|
2019-01-27 01:39:38 +03:00
|
|
|
|
|
2019-01-29 00:37:13 +03:00
|
|
|
|
niv drop jq
|
2019-02-08 21:07:05 +03:00
|
|
|
|
niv drop my-package version
|
2019-01-27 01:39:38 +03:00
|
|
|
|
|
2019-02-08 21:07:05 +03:00
|
|
|
|
Usage: niv drop PACKAGE [ATTRIBUTE]
|
2019-01-29 00:37:13 +03:00
|
|
|
|
Drop dependency
|
2019-01-23 23:55:26 +03:00
|
|
|
|
|
2019-01-29 00:37:13 +03:00
|
|
|
|
Available options:
|
|
|
|
|
-h,--help Show this help text
|
2019-01-31 01:56:35 +03:00
|
|
|
|
|
2019-01-29 00:37:13 +03:00
|
|
|
|
```
|
2019-01-17 23:59:01 +03:00
|
|
|
|
|
2019-02-11 22:33:10 +03:00
|
|
|
|
#### Init
|
2019-02-08 21:29:48 +03:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
Usage: niv init
|
|
|
|
|
Initialize a Nix project. Existing files won't be modified.
|
|
|
|
|
|
|
|
|
|
Available options:
|
|
|
|
|
-h,--help Show this help text
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
2019-02-11 22:33:10 +03:00
|
|
|
|
#### show
|
2019-02-08 21:29:48 +03:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
Usage: niv show
|
|
|
|
|
|
|
|
|
|
Available options:
|
|
|
|
|
-h,--help Show this help text
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
2019-02-13 12:26:16 +03:00
|
|
|
|
## Related
|
|
|
|
|
|
|
|
|
|
* [nix-flakes]: `niv` support a subset of the Nix flakes. In particular it does
|
|
|
|
|
not perform any kind of dependency resolution.
|
|
|
|
|
* [nix-path]: `niv` and `nix-path` share a similar goal and ideas tend to flow
|
|
|
|
|
back and forth freely.
|
|
|
|
|
|
2019-01-18 00:01:09 +03:00
|
|
|
|
[Nix]: https://nixos.org/nix/
|
2019-02-11 22:33:10 +03:00
|
|
|
|
[jq]: https://stedolan.github.io/jq/
|
|
|
|
|
[GHC]: https://www.haskell.org/ghc/
|
2019-02-13 12:26:16 +03:00
|
|
|
|
[nix-flakes]: https://gist.github.com/edolstra/40da6e3a4d4ee8fd019395365e0772e7
|
|
|
|
|
[nix-path]: https://github.com/zimbatm/nix-path
|