Adding build-specific Cargo commands to a Rust devshell

Hey folks,

I’ve been building my recent Rust project in Nix devshells, and the one bit about the process I didn’t like was manually pulling in third-party unpackaged Cargo binaries via cargo install. I tried automating that using the below devshell, but it doesn’t seem to work. Specifically:

  • I’d expect a dx command in my path but I don’t have one.
  • If I do nix build .#dioxus-cli I get an empty resultbin directory and nothing else.

Is there anything obviously wrong with this flake definition? I set things up so nix build .#dioxus-cli works but that’s only for testing–eventually I want to remove that once things are working.

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11";
    nixpkgsUnstable.url = "github:NixOS/nixpkgs/nixos-unstable";
    utils.url = "github:numtide/flake-utils";
    naersk.url = "github:nix-community/naersk/master";
  };

  outputs =
    {
      self,
      nixpkgs,
      nixpkgsUnstable,
      utils,
      naersk,
    }:
    utils.lib.eachDefaultSystem (
      system:
      let
        pkgs = import nixpkgs { inherit system; };
        pkgsUnstable = import nixpkgsUnstable { inherit system; };
        naersk' = pkgs.callPackage naersk { };
        dioxus-cli = naersk'.buildPackage {
          name = "dioxus-cli";
          src = pkgs.fetchFromGitHub {
            owner = "dioxuslabs";
            repo = "dioxus";
            rev = "v0.6.3";
            hash = "sha256-iA9GDN1hE6KuKINizHZGhXADVZ6xYxl4bbEGqSsl42g=";
          };
        };
      in
      {
        packages.dioxus-cli = dioxus-cli;
        devShell =
          with pkgs;
          mkShell.override { stdenv = pkgs.clangStdenv; } {
            nativeBuildInputs = [
              cargo
              rustc
              rustfmt
              rustPackages.clippy
              cargo-watch
              dioxus-cli
              llvmPackages.bintools
              pkg-config
              pkgsUnstable.overturemaps
              duckdb
              pre-commit
              overmind
              redis
              minio
            ];
            buildInputs = [
              webkitgtk_4_1
              gtk3
              xdotool.out
              openssl
            ];
            shellHook = ''
              # pre-commit install
            '';
            RUST_SRC_PATH = rustPlatform.rustLibSrc;
          };
      }
    );
}

Thanks.

Sounds like you have store corruption, you should do a store repair.
Building the package should result in result/bin/dx.

Agreed it should but it isn’t. :slight_smile: I did try nix store repair from the directory alongside the flake and nothing changed. Should I have run something different?

Thanks for the suggestion.

Thanks. I ran that and it didn’t visibly report any errors–I’m assuming it’d be loud if there were any issues, even if it fixed them?

Either way, I’m still getting an empty result/bin. Are you saying you get a result/bin/dx when building this? Sorry to be pedantic, just trying to figure out if you’re saying this actually works for you. :slight_smile:

Thanks again.

$ tree $(nix build github:nixos/nixpkgs/c8cd81426f45942bb2906d5ed2fe21d2f19d95b7#dioxus-cli --print-out-paths --no-link)
/nix/store/k9w2by51jv89rryd8w6nspxvr62s5f74-dioxus-cli-0.6.3
└── bin
    └── dx

2 directories, 1 file

c8cd81426f45942bb2906d5ed2fe21d2f19d95b7 is the most current commit on the nixos-unstable branch.

Also tested on stable:

$ tree $(nix build github:nixos/nixpkgs/nixos-24.11#dioxus-cli --print-out-paths --no-link)
/nix/store/aj23lhjykmq82hh2p65kmx6m7d658kjl-dioxus-cli-0.5.7
└── bin
    └── dx

2 directories, 1 file

Ah okay, I missed the fact that you tried to build your own dioxus-cli for some reason - ignore my prior replies. I don’t use naersk nor know how it works.

Thanks for the commands–turns out I’m doing it wrong.

nix build github:nixos/nixpkgs/nixos-24.11#dioxus-cli works as expected and result is correctly populated.

nix build .#dioxus-cli is what I ran to test, and that’s what gave me the empty directories.

Why do I need to specify a NixOS version in this case? I see so many examples where folks aren’t and don’t get the difference between what they’re doing and what I am.

You made your own unrelated package dioxus-cli, that has nothing to do with nixpkgs.
I only mentioned the nixpkgs version because it’s already packaged there and works.