Getting a shell from a flake with buildRustPackage

I’m trying to write a flake.nix for a rust package I’m writing. The following builds fine, but it fails to set up a dev shell

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs";
    flake-utils.url = "github:numtide/flake-utils";

  outputs = { self, nixpkgs, flake-utils }:
    flake-utils.lib.eachDefaultSystem (system:
      with nixpkgs.legacyPackages.${system}; { = rustPlatform.buildRustPackage {
          name = "foo";
          version = "0.1";

          src = lib.cleanSource ./.;

          cargoSha256 =

        defaultPackage = self.packages.${system}.foo;

        devShell = mkShell {
          inputsFrom = builtins.attrValues self.packages.${system};

          # I'm never quite sure which one to use, but in this case neither
          # result in a proper dev shell
          buildInputs = [ cargo ];
          nativeBuildInputs = [ cargo ];

After running nix shell I expect to find cargo in my path, but it’s not there

$ nix shell

$ ps
    PID TTY          TIME CMD
  75875 pts/1    00:00:02 zsh
 109027 pts/1    00:00:00 zsh
 109338 pts/1    00:00:00 ps

$ whereis cargo

Any suggestions on how to make the devShell expression work?

Try nix develop. It might be confusing because nix shell is not like nix-shell because its goal is to provide only the installable itself (man page):

nix shell runs a command in an environment in which the $PATH variable provides the specified installables.


Hi @magthe! Another solution is to put use flake in your .envrc.

1 Like