Write an example of using niv and nix-shell together
Hi, just found myself niv tool by https://github.com/balsoft/nixos-config, you created really nice and useful software. But I faced some problems just at the start (maybe there is some problem in my system):
niv init
...
niv add stedolan/jq
...
niv show
nixpkgs
homepage: https://github.com/NixOS/nixpkgs
url: https://github.com/NixOS/nixpkgs-channels/archive/a3070689aef665ba1f5cc7903a205d3eff082ce9.tar.gz
owner: NixOS
branch: nixos-19.09
url_template: https://github.com/<owner>/<repo>/archive/<rev>.tar.gz
repo: nixpkgs-channels
type: tarball
sha256: 1p9pg0y61my6gn82nm0n6n3vhv3lhxinwdb41a7ygp5ix2665q5q
description: A read-only mirror of NixOS/nixpkgs tracking the released channels. Send issues and PRs to
rev: a3070689aef665ba1f5cc7903a205d3eff082ce9
jq
homepage: http://stedolan.github.io/jq/
url: https://github.com/stedolan/jq/archive/e7d37983c42e3783cebe3346d65b9b887e3bdbc8.tar.gz
owner: stedolan
branch: master
url_template: https://github.com/<owner>/<repo>/archive/<rev>.tar.gz
repo: jq
type: tarball
sha256: 0va15r0pkrb8p578581q4apmb07grwyra69frw747gqn2lsw5cwj
description: Command-line JSON processor
rev: e7d37983c42e3783cebe3346d65b9b887e3bdbc8
niv
homepage: https://github.com/nmattia/niv
url: https://github.com/nmattia/niv/archive/abd0de3269fd712955d27b70e32921841c7b8bb7.tar.gz
owner: nmattia
branch: master
url_template: https://github.com/<owner>/<repo>/archive/<rev>.tar.gz
repo: niv
type: tarball
sha256: 0b38n1ad00s1qqyw3ml3pypf8i1pw4aqw0bpa02qq9iv7sp3x0gz
description: Easy dependency management for Nix projects
rev: abd0de3269fd712955d27b70e32921841c7b8bb7
cat default.nix
{ sources ? import ./nix/sources.nix }: # import the sources
with
{ overlay = _: pkgs:
{ niv = import sources.niv {}; # use the sources :)
};
};
import sources.nixpkgs # and use them again!
{ overlays = [ overlay ] ; config = {}; }
nix-shell
unpacking 'https://github.com/NixOS/nixpkgs-channels/archive/a3070689aef665ba1f5cc7903a205d3eff082ce9.tar.gz'...
error: Please be informed that this pseudo-package is not the only part of
Nixpkgs that fails to evaluate. You should not evaluate entire Nixpkgs
without some special measures to handle failing packages, like those taken
by Hydra.
niv
niv - dependency manager for Nix projects
version: 0.2.9
nixos-version
19.09.1764.2d9454702e5 (Loris)
The reason is that, by default, nix-shell creates a shell for the derivation that default.nix evaluates to. In your case, default.nix evaluates to the whole of nixpkgs. You could specify which package you want to build:
$ nix-shell -I nixpkgs=. -p <some-package>
or create a shell.nix (which will be used by nix-shell by default instead of default.nix):
# shell.nix
let pkgs = import ./default.nix {}; in pkgs.hello
Let me know if you have more questions!
Thanks for the clarification. It will be nice if readme was updated with this example, I think it would be really helpful for beginners like me.
As I see the only option is to specify package? What if user wants to run a nix-shell just to play with dependencies? I can't say that selecting some package to build is ideologically comfortable, maybe need to create some way how to simply get nix-shell to play with?
@novoxudonoser You get all the usual capabilities of shell.nix. For example, if you just want a bunch of packages in your environment:
let
sources = import ./nix/sources.nix;
pkgs = import sources.nixpkgs {};
my-pinned-package = import sources.my-pinned-package {};
in
pkgs.mkShell {
buildInputs = [
pkgs.hello pkgs.python3 my-pinned-package
];
}