How to use `flake.lock` with `nix shell`?

Hello!

I have been struggling to find much documentation on this.

In the past, I have made extensive use of nix-shell shebangs like this:

#!/usr/bin/env nix-shell
#!nix-shell -I nixpkgs=[url]
#!nix-shell -i bash -p bash [deps]

I have several linting/release scripts following this pattern in a project which uses Flakes, and I would like to migrate them to nix shell.

Specifically, I would like these scripts to use the pinned version of Nixpkgs from the project’s flake.lock.

I tried --inputs-from ., but it didn’t work in combination with --no-use-registry, so I assume I must be doing this wrong.

Is there something I can use to

  1. Only allow pinned dependencies
  2. From a flake.{nix,lock} in the same directory?

nix - Nix 2.34.7 Reference Manual explains the shebang syntax. You may be able to finagle something overwrought, but I’d set devShells.<arch>.default in your flake.nix, and use nix develop instead.

1 Like