Use inputs from current flake
TLATER opened this issue · 6 comments
Hi, I started using this to write a script for some repository mangling that I might need to do without being able to use the devShell
in my flake. Obviously I'd like to use the nixpkgs version specified in my flake.lock
- any chance --override-from <some command to resolve the current flake's path>
could be supported somehow?
I frequently write scripts that bind #!registry self .
(or even #!registry nixpkgs .
if I happen to be re-exporting nixpkgs with overlays on legacyPackages
like I often do). There's no conceptual reason why you couldn't do that and then use e.g. #!package self#devShells.x86_64-linux.default
to have the rest of your script run in the context of your dev shell. Having to mention x86_64-linux
is a little gross but you really only need do that if you aren't exporting the stuff you need under packages
or legacyPackages
.
Oh btw: the above works way better if you are on a new enough version of nix
that it has the "search up" functionality to find flake.nix
because the scripts will then work anywhere inside of your flake.
Another fun pattern is to do the above with a bin
directory at the top of your flake and then add the bin
to your path with direnv
Hrm, that does require re-exporting nixpkgs, which I'm not very fond of. It might ultimately be better to set this script up so it can be invoked with nix run
, but I liked the idea of not exporting some local repository management scripts.
Your call on whether this is worth thinking through sed
again, of course ;) Hopefully nix shell
eventually learns to support this use case.
I think I'd be willing to do any needed work on the sed
side if I had a better notion of how to alter the underlying nix shell
command to make the current flake inputs available to reference for installables.
Now that nix
searches "up" from the current directory to find flake.nix
, it might be possible to have a flag which causes us to run nix flake metadata --json
and parse the inputs from that.