Skip to content

nix-shell mangles options sent to nix-store #244

Closed

Description

@ttuegel

man nix-shell says:

All options not listed here are passed to nix-store --realise, except for --arg and --attr / -A which are passed to nix-instantiate.

In fact, nix-shell tries to use everything as a path that doesn't begin with --. Observe:

$ nix-shell --add-root ./result --indirect
error: getting status of `./result': No such file or directory

(I've elided the full path to ./ above for clarity.)
OK, so with Nix 1.6, I would work around this by putting quotes around "--add-root ./result". Let's try that:

$ nix-shell "--add-root ./result" --indirect
error: unknown flag `--add-root result'
Try `nix-store --help' for more information.
/run/current-system/sw/bin/nix-shell: failed to build all dependencies

Alright, that's no good with Nix 1.7. The problem to begin with was that nix-shell thought result was the path to a Nix expression, and not an option for nix-store. So, I'll give it the path to an expression explicitly:

$ nix-shell default.nix --add-root ./result --indirect
error: path `./--indirect' is not a valid garbage collector root; it's not in the directory `/nix/var/nix/gcroots'
/run/current-system/sw/bin/nix-shell: failed to build all dependencies

What? Oh, ./result isn't being passed to nix-store after --add-root, even though nix-shell isn't using it as a path.

I need a way to pass arguments to nix-store through nix-shell. I suggest either or both of the following

  1. Have nix-shell take only the first path on the command line as the path to a Nix expression. Leave the rest of the command line alone. Then, my third command above would work.
  2. Use -- alone to terminate option parsing by nix-shell and pass everything thereafter directly to nix-store. Then I could use, e.g.,
nix-shell -- --add-root ./result --indirect

Activity

  1. changed the title [-]nix-shell mangles options sent to nix-build[/-] [+]nix-shell mangles options sent to nix-store[/+] on Apr 18, 2014
  2. added a commit that references this issue on Nov 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions