1

I'm starting to learn how to use nix-shell in order for me to have reproductibles envs for dev and devops operations.

I'm trying to have a shell.nix file with pinned packages version (kustomize v3.6.1, git X.Y.Z etc.), but I can't make it work. Basically, what I would like is being able to pin tools versions instead of nixpkgs version.

I followed niv Getting Started instructions on their repo to:

  1. Create a new project using niv init -> this worked well
  2. Add a new package using niv add stedolan/jq -> this seemed to work well too, as the sources.json got updated.

Then I edited my shell.nix as follows:

let
  sources = import ./nix/sources.nix;
  pkgs = import sources.nixpkgs { };
  jq = import sources.jq { };
in

pkgs.mkShell {
    buildInputs = [
        pkgs.vim
        pkgs.niv
        jq
    ];
}

But everytime I try to run nix-shell, I have the following error message:

error: opening file '/nix/store/lz1m9sv79l0d0lkjm2acnxyx1avnzahk-jq-src/default.nix': No such file or directory
(use '--show-trace' to show detailed location information)

I tried digging into the docs of both Nix and Niv, reading blog posts etc. but to be honest I'm feeling like I'm learning how to draw an owl.

Any idea how I can solve this? Thanks a lot!

Some more infos:

$ nix-shell --version
nix-shell (Nix) 2.13.3
$ niv --version
0.2.22
$ cat /etc/os-release 
PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"
NAME="Debian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
hacb
  • 175
  • 2
  • 10
  • 2
    `stedolan/jq` refers to the github project, not the `jq` package in nixpkgs. And the `stedolan/jq` github repo has no `default.nix` present in the root directory. Hence the error. You likely wanted to refer to `pkgs.jq` instead. – Chris Stryczynski Apr 02 '23 at 19:12
  • @ChrisStryczynski thanks for the explaination! So is there a way for me to have `jq` in a given version and, let's say, `git` in another one without having to import multiple versions of `nixpkgs`? I thought that was the main goal of the `source.json` file, but I guess I'm wrong – hacb Apr 02 '23 at 20:15
  • 1
    It's not clear what you mean by version. git and jq are two different programs. You can refer to two different nixpkgs versions, just add the second one, and refer to it. – Chris Stryczynski Apr 02 '23 at 20:29

0 Answers0