2

I can start nix-shell with a package from a particular revision, e.g.

nix-shell -p ktlint -I nixpkgs=https://github.com/NixOS/nixpkgs/archive/141439f6f11537ee349a58aaf97a5a5fc072365c.tar.gz
nix-shell -p jq -I nixpkgs=https://github.com/NixOS/nixpkgs/archive/7d7622909a38a46415dd146ec046fdc0f3309f44.tar.gz

Can I start nix-shell with two packages, but from different revisions, in one command? For example, if I wanted both ktlint and jq from the specific revisions above?

Matt R
  • 9,892
  • 10
  • 50
  • 83
  • 1
    FWIW -- personally, I would have asked this one at [unix.se]. Questions about Nix-the-language are definitely best suited to SO, but questions about the associated command-line tooling is iffier. – Charles Duffy Sep 23 '22 at 16:52
  • @CharlesDuffy thanks for the helpful answer, and you're undoubtedly right - I've been learning about Nix as a potential development environment tool, but this question is not super specific to programming. – Matt R Sep 23 '22 at 17:51

1 Answers1

2

Setting NIX_PATH=nixpkgs=... is just syntactic sugar enabling references like <nixpkgs> to work; but one doesn't need to use import <nixpkgs> exclusively -- one can also import directly from an explicit path.

nix-shell -E '
let
  pkgsA = (import (builtins.fetchTarball https://github.com/NixOS/nixpkgs/archive/141439f6f11537ee349a58aaf97a5a5fc072365c.tar.gz) {});
  pkgsB = (import (builtins.fetchTarball https://github.com/NixOS/nixpkgs/archive/7d7622909a38a46415dd146ec046fdc0f3309f44.tar.gz) {});
in
pkgsA.mkShell {
  buildInputs = [
    pkgsA.ktlint
    pkgsB.jq
  ];
}'
Charles Duffy
  • 280,126
  • 43
  • 390
  • 441