Pkgs.caffe doesn't show up when added to devShell buildInputs

By executing nix develop with the code below, cowsay works but caffe doesn’t show up on my terminal.
Doing nix shell nixpkgs#caffe directly works.
What’s happening?

{
  description = "My environment";
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/";
    flake-utils. url = "github:numtide/flake-utils";
  };

  outputs = input@{ self, nixpkgs, flake-utils }:
    flake-utils.lib.eachSystem [ "x86_64-linux" "x86_64-darwin" ] (system:
      let
        pkgs = import nixpkgs {
          system = system;
          config.allowUnfree = true;
        };
      in {
        devShell = pkgs.mkShell {
          buildInputs = [
            pkgs.caffe
            pkgs.cowsay
          ];
        };
      }
    );
}

nix develop assumes that you’re trying to create an environment to build a package. Listing those packages in nativeBuildInputs will make the bin output also available. cowsay works, because it only has an out output, so it will default to that which also contains the executable underl bin/.

In debian terms, nix assumed you wanted caffe-dev because buildInputs usually contains headers and libraries (usually this is in a *-lib output in practice) usually needed for C compilation. But you wanted caffe-bin instead, and in nix, we declare hostPlatform compatible executables in nativeBuildInputs.

Another option would have been to do lib.getBin <pkg>, but then libraries likely wouldn’t be available.

2 Likes

Putting pkgs.caffe in nativeBuildInputs doesn’t show caffe in my terminal.
Is this working as intended?

This works! For future reference, working code is as follows.

{
  description = "My environment";
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/";
    flake-utils. url = "github:numtide/flake-utils";
  };

  outputs = input@{ self, nixpkgs, flake-utils }:
    flake-utils.lib.eachSystem [ "x86_64-linux" "x86_64-darwin" ] (system:
      let
        pkgs = import nixpkgs {
          system = system;
          config.allowUnfree = true;
        };
      in {
        inherit pkgs;
        devShell = pkgs.mkShell {
          buildInputs = [
            pkgs.cowsay
          ];
          nativeBuildInputs = [
            (pkgs.lib.getBin pkgs.caffe)
          ];
        };
      }
    );
}