nix-community / crate2nix

rebuild only changed crates in CI with crate2nix and nix
https://nix-community.github.io/crate2nix/
Apache License 2.0
383 stars 89 forks source link

Cargo.nix includes references to ./crate2nix-sources with cargo workspaces #316

Open flokli opened 11 months ago

flokli commented 11 months ago

This is a continuation of https://github.com/nix-community/crate2nix/issues/291 - I finally ran into the issue I had, and it only shows up with some crates.

The crate2nix source add git https://… --rev $rev; crate2nix generate to package an external project mostly works. However, in some cases I can not just .gitignore crate2nix-sources.nix and the crate2nix-sources symlink, as Cargo.nix refers to sources from that symlink:

❯ crate2nix source add git https://github.com/n0-computer/iroh --rev 62ac4d8bb57329bc65cf126fabace882066ddb8a
Prefetching https://github.com/n0-computer/iroh#62ac4d8bb57329bc65cf126fabace882066ddb8a: done.
Added new source: https://github.com/n0-computer/iroh#62ac4d8bb57329bc65cf126fabace882066ddb8a via git: 0f2iyj6r3ymrgdy2vqv2dqixqaqprspyr042sqwibzha18phkxwk
❯ crate2nix generate
Fetching sources.
Generated ./crate2nix-sources.nix successfully.
Fetching sources via ./crate2nix-sources.nix fetchedSources: done.
warning: Could not find configured source for workspace member "/tmp/example/crate2nix-sources/iroh/iroh-base"
warning: Could not find configured source for workspace member "/tmp/example/crate2nix-sources/iroh/iroh-bytes"
warning: Could not find configured source for workspace member "/tmp/example/crate2nix-sources/iroh/iroh-gossip"
warning: Could not find configured source for workspace member "/tmp/example/crate2nix-sources/iroh/iroh-metrics"
warning: Could not find configured source for workspace member "/tmp/example/crate2nix-sources/iroh/iroh-net"
warning: Could not find configured source for workspace member "/tmp/example/crate2nix-sources/iroh/iroh-net/bench"
warning: Could not find configured source for workspace member "/tmp/example/crate2nix-sources/iroh/iroh-sync"
warning: Could not find configured source for workspace member "/tmp/example/crate2nix-sources/iroh/iroh-test"
Generated ./Cargo.nix successfully.
❯ ag crate2nix-sources Cargo.nix
6986:          then lib.cleanSourceWith { filter = sourceFilter;  src = ./crate2nix-sources/iroh/iroh-base; }
6987:          else ./crate2nix-sources/iroh/iroh-base;
7119:          then lib.cleanSourceWith { filter = sourceFilter;  src = ./crate2nix-sources/iroh/iroh-bytes; }
7120:          else ./crate2nix-sources/iroh/iroh-bytes;
7294:          then lib.cleanSourceWith { filter = sourceFilter;  src = ./crate2nix-sources/iroh/iroh-gossip; }
7295:          else ./crate2nix-sources/iroh/iroh-gossip;
7498:          then lib.cleanSourceWith { filter = sourceFilter;  src = ./crate2nix-sources/iroh/iroh-metrics; }
7499:          else ./crate2nix-sources/iroh/iroh-metrics;
7595:          then lib.cleanSourceWith { filter = sourceFilter;  src = ./crate2nix-sources/iroh/iroh-net; }
7596:          else ./crate2nix-sources/iroh/iroh-net;
8010:          then lib.cleanSourceWith { filter = sourceFilter;  src = ./crate2nix-sources/iroh/iroh-net/bench; }
8011:          else ./crate2nix-sources/iroh/iroh-net/bench;
8074:          then lib.cleanSourceWith { filter = sourceFilter;  src = ./crate2nix-sources/iroh/iroh-sync; }
8075:          else ./crate2nix-sources/iroh/iroh-sync;
8270:          then lib.cleanSourceWith { filter = sourceFilter;  src = ./crate2nix-sources/iroh/iroh-test; }
8271:          else ./crate2nix-sources/iroh/iroh-test;

This is with crate2nix master, 252ca6b353700650b8deaf76079708b833c11e54.

flokli commented 11 months ago

This seems to be the sources for the workspace members of a workspace crate themselves.

https://github.com/ClementTsang/bottom is single-crate, and doesn't provoke this issue.

I assume we need to express the fetching for workspaces inside the Cargo.nix as well, similar to how it's done with non-workspaces:

      "bottom" = rec {
        crateName = "bottom";
        version = "0.9.6";
        edition = "2021";
        crateBin = [
          {
            name = "btm";
            path = "src/bin/main.rs";
            requiredFeatures = [ ];
          }
        ];
        workspace_member = null;
        src = pkgs.fetchgit {
          url = "https://github.com/ClementTsang/bottom";
          rev = "712a0036811d1ec1f676b2ba76fff4bf5cc5fa97";
          sha256 = "1p12lay9haj4210am2f6d9mj0f7srmg7sm8pljns92a7xnrsp7zn";
        };
        authors = [
          "Clement Tsang <cjhtsang@uwaterloo.ca>"
        ];
        # ...
      }