How does one write a shell.nix
file that depends on a flake?
Instead of writing a shell.nix
, consider adding a devShells.default
attribute to your flake.nix
outputs.
Alternatively, you could set a system channel in your flake and have the shell.nix
reference that channel?
I think the main (only?) pattern here is to use builtins.getFlake
.
Here’s a github code search with some examples of what people are doing.
I also used it for the last example in a blog post I wrote last month (just as an example I can speak for; it wasn’t the point of the post and it isn’t explained): avoid trap-clobbering in nix-shell
I have a bunch of shell.nix
files for different projects, and I don’t want to rewrite them all into flakes, so I’d like to be able to use flake outputs from within them.
Also applies to eg home-manager configs.
Thanks, I’ll give that a shot!
alternatively you can write a flake and use flake-compat to provide a shell.nix that will work with nix 2.3 https://github.com/edolstra/flake-compat/
This worked for me:
let
crunkurrent_flake = builtins.getFlake "github:samuela/crunkurrent";
crunkurrent = crunkurrent_flake.packages."${builtins.currentSystem}".default;
in
pkgs.mkShell {
buildInputs = [ crunkurrent ];
...
}