IssueRaiser

Flakes UX: make it easy to evaluate an arbitrary expression in a context of a flake

This is a design discussion issue, so feel free to give as much feedback and criticism as you like. ## Preamble In ye olde days of `nix-shell`, it was possible to easily evaluate expressions in the context of `nixpkgs`. Something like this: ``` nix-shell -p 'python3.withPackages (ps: with ps; [ numpy scipy ])' ``` Drops you into a shell in which there's a `python3` executable with numpy and scipy available. This is really useful for ad-hoc scripting. You could also do something like ``` nix-shell -p 'hello.overrideAttrs (_: { src = ./.; })' ``` It was also possible to add `alias p='nix-shell -p'` to save some typing. The flexibility is endless -- and all just a few keystrokes away! ## Current situation It is possible to do something similar with new, flaky interface: ``` nix shell --impure --expr 'with builtins.getFlake "nixpkgs"; with legacyPackages.${builtins.currentPlatform}; python3.withPackages (ps: with ps; [ numpy scipy ])' ``` However, this is a chore to do, and I'd much rather just run `pip install numpy scipy` and deal with all the usual stateful package management issues than type this monstrosity every time I need to try a python package. ## Proposal Add a way to easily evaluate expressions "in the context of" a flake, meaning with the top-level attributes and `{packages,legacyPackages}.${currentPlatform}` of that flake available in scope. ### Possible implementations I came up with three different ideas, all of which have some advantages and drawbacks

Posted by balsoft on Nov 15, 2021, 3:16 PM

Tags

Related issues

Raise real-world problems, find people facing the same issue, and discuss solutions.3,000 issues0 comments

ux (Other)

Flakes UX: make it easy to evaluate an arbitrary expression in a context of a flake

balsoftNov 15, 2021, 3:16 PM

This is a design discussion issue, so feel free to give as much feedback and criticism as you like. ## Preamble In ye olde days of `nix-shell`, it was possible to easily evaluate expressions in the context of `nixpkgs`. Something like this: ``` nix-shell -p 'python3.withPackages (ps: with ps; [ numpy scipy ])' ``` Drops you into a shell in which there's a `python3` executable with numpy and scipy available. This is really useful for ad-hoc scripting. You could also do something like ``` nix-shell -p 'hello.overrideAttrs (_: { src = ./.; })' ``` It was also possible to add `alias p='nix-shell -p'` to save some typing. The flexibility is endless -- and all just a few keystrokes away! ## Current situation It is possible to do something similar with new, flaky interface: ``` nix shell --impure --expr 'with builtins.getFlake "nixpkgs"; with legacyPackages.${builtins.currentPlatform}; python3.withPackages (ps: with ps; [ numpy scipy ])' ``` However, this is a chore to do, and I'd much rather just run `pip install numpy scipy` and deal with all the usual stateful package management issues than type this monstrosity every time I need to try a python package. ## Proposal Add a way to easily evaluate expressions "in the context of" a flake, meaning with the top-level attributes and `{packages,legacyPackages}.${currentPlatform}` of that flake available in scope. ### Possible implementations I came up with three different ideas, all of which have some advantages and drawbacks

Comments (0)

No comments yet. Start the discussion.

Comment on this issue