-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
nix-shell should support mixing -p with a filename #4230
Comments
Although it communicates the idea qutie well, the I agree it would be nice to support replacing |
Huh I thought we could write an expression like |
I marked this as stale due to inactivity. → More info |
Still valid. |
I marked this as stale due to inactivity. → More info |
Describe the bug
nix-shell
can take a filename to source its expression from, or it can take a-p
flag to declare packages to use, but it cannot mix the two. This is really unfortunate because it means I can't use a file that declares a customized/pinned version of nixpkgs and pull individual packages from that with-p
. I have to instead construct an expression using-E
, which is annoying and not something I want to teach my coworkers how to do. I can't use the-I nixpkgs=somePath
option either as I have a file that vends nixpkgs rather than a nixpkgs checkout.What I'd really like to do is to be able to write
But today, if I do this, it tries to interpret
pinned.nix
as a package.There's two issues here. The first is that the
-p
flag declares "all arguments not otherwise associated with a flag are to be interpreted as packages, regardless of their location on the command line", which is rather confusing as it makesnix-shell foo -p bar
behave likenix-shell -p foo bar
, and the second is that the package form hard-codesimport <nixpkgs>
.Suggested resolution
I think two things should be done:
nix-shell foo -p bar
likenix-shell -p foo bar
. I realize this is technically a backwards-incompatible change, although thenix-shell
documentation indicates that the usage is-p packages...
.nix-shell
prior to the-p
flag, replaceimport <nixpkgs> {}
with something like(let expr = import $path; in if builtins.isFunction expr then expr {} else expr)
. Ideally any--arg
or--argstr
flags would be supported here as well. If multiple filenames are given tonix-shell
along with the-p
flag then they could either all be imported and merged together, or just throw an error.A less invasive change would be to define a new flag I can use to replace the
import <nixpkgs> {}
with, such thatnix-shell foo -p bar
still retains the current behavior (though as I stated before that behavior is confusing). Or this could be hacked further by replacing theimport <nixpkgs> {}
with something like(let customPath = builtins.tryEval (toString <nix-shell-pkgs>); expr = import (if customPath.success then customPath.value else <nixpkgs>); in if builtins.isFunction expr then expr {} else expr)
. This way I could runnix-shell -I nix-shell-pkgs=pinned.nix -p bash jq
and it would pull from my custom file instead. I don't see any clear benefit to this over defining a new flag though, and the new flag would be easier to document.The text was updated successfully, but these errors were encountered: