Deps.nix for haskell script

i have no idea how to configure haskell script dependency from deps.nix.

[op@my-200 hs-etl]$ cat deps.nix
with import <nixos-19.09> {} ;
haskellPackages.ghcWithPackages (p: [p.lens])
[op@my-200 hs-etl]$ cat dataset_lineage.hs
#! /usr/bin/env nix-shell
#! nix-shell deps.nix -i runghc

import Control.Lens
main = do
  putStrLn $ ("hello","world")^._2

the related log is:

[op@my-200 hs-etl]$ ./dataset_lineage.hs 

dataset_lineage.hs:4:1: error:
    Could not find module `Control.Lens'
    Use -v to see a list of the files searched for.
4 | import Control.Lens

Try adding --pure to #! nix-shell deps.nix -i runghc and you should see something like that:

/tmp/nix-shell-29304-0/rc: line 1: exec: runghc: not found

The issue is that nix-shell loads the dependencies of the main derivation and not the derivation itself. It just happened that you had runghc on the PATH.

To fix this, wrap the derivation in a mkShell invocation like this:

with import <nixpkgs> {} ;
mkShell {
  buildInputs = [
    (haskellPackages.ghcWithPackages (p: [p.lens]))
$ ./dataset_lineage.hs