Skip to content
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

Use inputs from current flake #5

Open
TLATER opened this issue Aug 1, 2022 · 6 comments
Open

Use inputs from current flake #5

TLATER opened this issue Aug 1, 2022 · 6 comments

Comments

@TLATER
Copy link

TLATER commented Aug 1, 2022

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?

@clhodapp
Copy link
Owner

clhodapp commented Aug 2, 2022

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.

@clhodapp
Copy link
Owner

clhodapp commented Aug 2, 2022

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.

@clhodapp
Copy link
Owner

clhodapp commented Aug 2, 2022

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

@TLATER
Copy link
Author

TLATER commented Aug 2, 2022

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.

@clhodapp
Copy link
Owner

clhodapp commented Aug 2, 2022

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.

@clhodapp
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants