How to add diesel-cli into a dev shell?

I am trying to create a dev shell that provides diesel-cli. However I am getting the error Dependency is not of a valid type: element 1 of nativeBuildInputs for nix-shell. The complete flake.nix is below, here is a shortened version:

{
  inputs = ...
  outputs = {self, nixpkgs, flake-utils, rust-overlay, crane}:
    flake-utils.lib.eachDefaultSystem
      (system:
        let
          # here I am configuring diesel-cli
          developmentTools = with pkgs; [diesel-cli.override {
            sqliteSupport = false; mysqlSupport = false;
          }];
        in
        with pkgs;
        {
          devShells.default = mkShell {
            # this should add diesel-cli to the shell
            packages = developmentTools;
          };
        }
      );
}
flake.nix
{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    flake-utils.url = "github:numtide/flake-utils";
    rust-overlay = {
      url = "github:oxalica/rust-overlay";
      inputs = {
        nixpkgs.follows = "nixpkgs";
        flake-utils.follows = "flake-utils";
      };
    };
    crane = {
      url = "github:ipetkov/crane";
      inputs = {
        nixpkgs.follows = "nixpkgs";
        rust-overlay.follows = "rust-overlay";
        flake-utils.follows = "flake-utils";
      };
    };
  };
  outputs = {self, nixpkgs, flake-utils, rust-overlay, crane}:
    flake-utils.lib.eachDefaultSystem
      (system:
        let
          overlays = [(import rust-overlay)];
          pkgs = import nixpkgs {
            inherit system overlays;
          };
          rustToolchain = pkgs.pkgsBuildHost.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
          craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain;
          src = craneLib.cleanCargoSource ./.;
          nativeBuildInputs = with pkgs; [rustToolchain pkg-config];
          buildInputs = with pkgs; [rustToolchain openssl];
          # here I am configuring diesel-cli
          developmentTools = with pkgs; [diesel-cli.override {sqliteSupport = false; mysqlSupport = false;}];
          commonArgs = {
            inherit src buildInputs nativeBuildInputs;
          };
          cargoArtifacts = craneLib.buildDepsOnly commonArgs;
          bin = craneLib.buildPackage(commonArgs // {inherit cargoArtifacts;});
          dockerImage = pkgs.dockerTools.streamLayeredImage {
            name = "rvoc-backend";
            tag = "latest";
            contents = [bin pkgs.cacert];
            config = {
              Cmd = ["${bin}/bin/rvoc-backend"];
            };
          };
        in
        with pkgs;
        {
          packages = {
            inherit bin dockerImage;
            default = bin;
          };
          devShells.default = mkShell {
            inputsFrom = [bin];
            buildInputs = with pkgs; [dive];
            # this should add diesel-cli to the shell
            packages = developmentTools;
          };
        }
      );
}

How do I get this to build, such that the command diesel that is provided by diesel-cli will be available in the dev shell?

Without looking at the details of your flake, I think you should add diesel-cli to nativeBuildInputs. The following flake works for me:

{
  inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; };

  outputs = { self, nixpkgs, ... }:
    let
      system = "x86_64-linux";
      pkgs = import nixpkgs { inherit system; };
      dc = pkgs.diesel-cli.override {
        sqliteSupport = false;
        mysqlSupport = false;
      };
    in {
      devShells.${system}.default = nixpkgs.legacyPackages.${system}.mkShell {
        nativeBuildInputs = [ dc ];
      };
    };
}
1 Like

For mkShell, packages gets merged into nativeBuildInputs, so either one should be fine here.

1 Like

Thanks to the answers both of you. It was very helpful to see a working example! I now figured out my problem. I forgot parentheses in the developmentTools list. So the correct lines would be:

          # here I am configuring diesel-cli
          developmentTools = with pkgs; [(diesel-cli.override {
            sqliteSupport = false; mysqlSupport = false;
          })];

Without the parentheses, developmentTools becomes a list of two items, the first is diesel-cli.override, and the second is {sqliteSupport = falseM mysqlSupport = false;}, but it never gets evaluated as a function call.

1 Like