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")
1 Like

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> {} ;
  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" ;
        # }) 
      {}) ;
      queryparser-hive = doJailbreak(self.callCabal2nix "queryparser-hive" ./library/queryparser/dialects/hive {}) ;
    } ;
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.


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.

1 Like

@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:

1 Like

Is it possible to pass the arguments from CLI into nix-shell -i ?

Maybe like (I tried this $@ solution but it not working) :

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

module Main where

main = putStrLn "hello world"

and run it with (suppose the above file name is script.nix)

./script.nix -v
Hosted by Flying Circus.