How to pass program parameter for nix-shell script

i want to write a simple clojure script, but it seem i can’t pass the -Sdeps parameter.
so what’s the way to do it?

#! /usr/bin/env nix-shell
#! nix-shell -i clj -p clojure -Sdeps "$(cat ../deps.edn)"
#! nix-shell -I nixpkgs=channel:nixos-19.09
(println "hello world")

haskell script is the same, if someone is more familar

[nix-shell:~/my-work/WhereHows-dev/contrib/metadata-etl]$ ./bin/test.hs
error: unexpected argument '-ilibrary/extension'
Try 'nix-shell --help' for more information.

[nix-shell:~/my-work/WhereHows-dev/contrib/metadata-etl]$ cat ./bin/test.hs
#! /usr/bin/env nix-shell
#! nix-shell ../deps.nix -i runghc -- -ilibrary/extension

import Oracle
main = do 
  putStrLn oracle

[nix-shell:~/my-work/WhereHows-dev/contrib/metadata-etl]$ cat deps.nix 
with import <nixos-19.09> {} ;
let 
  haskellPackages = pkgs.haskellPackages.override {
    overrides = self: super: with pkgs.haskell.lib; {
      queryparser = doJailbreak(self.callCabal2nix "queryparser"
        # (fetchFromGitHub {
        #   owner = "uber" ;
        #   repo = "queryparser" ;
        #   rev = "6015e8f273f4498326fec0315ac5580d7036f8a4" ;
        #   sha256 = "05pnifm5awyqxi6330v791b1cvw26xbcn2r20pqakvl9d3xyaxa4" ;
        # }) 
        ./library/queryparser
      {}) ;
      queryparser-hive = doJailbreak(self.callCabal2nix "queryparser-hive" ./library/queryparser/dialects/hive {}) ;
    } ;
  };
in 
mkShell {
  buildInputs = [
    (haskellPackages.ghcWithPackages ( p: 
      [ p.bytestring p.text p.string-conversions
        p.aeson p.aeson-qq p.aeson-pretty 
        p.lens p.conduit
        p.hssqlppp p.queryparser p.queryparser-hive ]
    ))
  ];
}

You can just pass the parameters in the -i argument:

#!/usr/bin/env nix-shell
#!nix-shell -i "runghc -v" -p ghc

module Main where

main = putStrLn "hello world"

Here I pass the -v flag to the runghc interpreter.

1 Like

@cdepillabout
What is the difference with nix-shell --command "myExecutable --myParameter" ?

I don’t understand the nix-shell --help remark that -i is only applicable in !# script.

@stphrolland The real difference between --command and -i is how nix-shell treats it. --command is for using nix-shell on the command line to run commands, and -i is for using nix-shell in hash-bang scripts.

The gory details are in the code:

https://github.com/NixOS/nix/blob/8b09105db3869284ee7892f82155dda79f98d6e6/src/nix-build/nix-build.cc#L194-L219