Nix: `nix run` doesn't evaluate expressions like `nix-shell -p`

Created on 3 Feb 2018  路  3Comments  路  Source: NixOS/nix

$ nix run "nixpkgs.haskellPackages.ghcWithPackages (p: [ p.lens] )" -c "ghci"
error: don't know what to do with argument 'nixpkgs.haskellPackages.ghcWithPackages (p: [ p.lens] )'
Try 'nix --help' for more information.

$ nix-shell -p "haskellPackages.ghcWithPackages (p: [ p.lens] )" --run "ghci"
GHCi, version 8.0.2: http://www.haskell.org/ghc/  :? for help
Prelude>

Is this not a use case that the new nix run is intended to support?

Most helpful comment

Great, this also seems to work:

$ nix run "(import <nixpkgs> {}).haskellPackages.ghcWithPackages (p: [ p.lens ])"

I would like it if this change in behaviour could be documented somewhere.

All 3 comments

The various nix subcommands generally want these things to be wrapped with paren's if they're expressions, so something like this works:

$ nix run "((import <nixpkgs> {}).haskellPackages.ghcWithPackages (p: [ p.lens] ))" -c "ghci"

Great, this also seems to work:

$ nix run "(import <nixpkgs> {}).haskellPackages.ghcWithPackages (p: [ p.lens ])"

I would like it if this change in behaviour could be documented somewhere.

I'm not sure the requirement for parentheses is intentional but maybe necessary as part of other things?

It's a minor nuisance but might be needed to differentiate expressions from attributes?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ericsagnes picture ericsagnes  路  3Comments

copumpkin picture copumpkin  路  3Comments

ihsanturk picture ihsanturk  路  3Comments

Infinisil picture Infinisil  路  3Comments

ericsagnes picture ericsagnes  路  4Comments