dream2nix icon indicating copy to clipboard operation
dream2nix copied to clipboard

rust: failing to vendor dependency of sub-directory

Open DavHau opened this issue 2 years ago • 4 comments

The rust project nitrokey-3-firmware seemed to be troublesome to package with current nixpkgs tooling during summer of nix due to an issue with parsing and fetching the git revision correctly.

I just tried with dream2nix and it fails with an other error. Vendoring the dependency of a sub directory seems to fail. flake.nix:

{
  inputs.dream2nix.url = "github:nix-community/dream2nix";
  inputs.src.url = "github:Nitrokey/nitrokey-3-firmware";
  inputs.src.flake = false;
  outputs = inp:
    inp.dream2nix.lib.makeFlakeOutputs {
      systemsFromFile = ./nix_systems;
      config.projectRoot = ./.;
      source = inp.src;
    };
}

error:

runner> error: failed to get `fm11nc08` as a dependency of package `runner v1.0.4 (/build/lpc55)`

@sbruder created a minimal reproducibel example of the problem here: https://github.com/sbruder/nix-cargo-two-unpinned-dependencies/blob/master/Cargo.lock This as well fails with dream2nix, but this time with another error than the flake above:

nix-cargo-two-unpinned-dependencies>     Updating git repository `https://github.com/rust-lang/libc`
nix-cargo-two-unpinned-dependencies> error: failed to get `libc` as a dependency of package `subproject v0.1.0 (/build/2340gklvaqqbmibp3z875282cmi8bj55-source/subproject)`
nix-cargo-two-unpinned-dependencies>     ... which satisfies path dependency `subproject` (locked to 0.1.0) of package `nix-cargo-two-unpinned-dependencies v0.1.0 (/build/2340gklvaqqbmibp3z875282cmi8bj55-source)`

@yusdacra

DavHau avatar Aug 01 '22 08:08 DavHau

I made https://github.com/nix-community/dream2nix/pull/223 which gets rid of that error, but I still get an error related to a vendored dependency, i'll look into it later.

yusdacra avatar Aug 01 '22 21:08 yusdacra

I got further since the duplicate version issue is resolved now:

{
  inputs.dream2nix.url = "github:nix-community/dream2nix/fix/rust-issues";
  inputs.src.url = "github:Nitrokey/nitrokey-3-firmware";
  inputs.src.flake = false;
  outputs = inp:
    let pkgs = inp.dream2nix.inputs.nixpkgs.legacyPackages.x86_64-linux; in
    inp.dream2nix.lib.makeFlakeOutputs {
      systemsFromFile = ./nix_systems;
      config.projectRoot = ./.;
      source = inp.src;
      packageOverrides = {
        runner.add-deps = {
          stdenv = pkgs.stdenvClang;
          nativeBuildInputs = old: old ++ (with pkgs; [libllvm libclang.lib]);
          LIBCLANG_PATH = "${pkgs.libclang.lib}/lib";
        };
      };
    };
}

and run nix build .#runner:

error: builder for '/nix/store/i5igc61rnwffzfm4zhy2mynvnzw219hg-runner-1.1.0.drv' failed with exit code 101;
       last 10 log lines:
       >   exit status: 0
       >   cargo:rustc-link-lib=static=lfs-sys
       >   cargo:rustc-link-search=native=/build/lpc55/target/x86_64-unknown-linux-gnu/release/build/littlefs2-sys-c8843d5c7cd9bba1/out
       >
       >   --- stderr
       >   littlefs/lfs.h:10:10: fatal error: 'stdint.h' file not found
       >   littlefs/lfs.h:10:10: fatal error: 'stdint.h' file not found, err: true
       >   thread 'main' panicked at 'Unable to generate bindings: ()', /build/lpc55/../nix-vendor/littlefs2-sys-0.1.6/build.rs:33:10
       >   note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
       > warning: build failed, waiting for other jobs to finish...

yusdacra avatar Aug 10 '22 16:08 yusdacra

I also hit this problem while trying to build it with rustPlatform.buildRustPackage and managed to solve it by adding clang to nativeBuildInputs. I don’t know why that is needed, but it solves the issue.

After adding this, the build fails with a different error message, because it needs one board selected as crate feature.

sbruder avatar Aug 10 '22 18:08 sbruder

Yes, I was able to select a feature by passing cargoBuildFeatures = ["board-solo2"], but it does not build anyhow because it needs a custom target (?). I'm not sure how to test further without getting it to build and tinkering, but this specific issue seems to be fixed (after #223 is merged). Latest flake.nix if anyone's interested:

{
  inputs.dream2nix.url = "github:nix-community/dream2nix/fix/rust-issues";
  inputs.src.url = "github:Nitrokey/nitrokey-3-firmware";
  inputs.src.flake = false;
  outputs = inp:
    let pkgs = inp.dream2nix.inputs.nixpkgs.legacyPackages.x86_64-linux; in
    inp.dream2nix.lib.makeFlakeOutputs {
      systemsFromFile = ./nix_systems;
      config.projectRoot = ./.;
      source = inp.src;
      packageOverrides = {
        runner.add-deps = {
          doCheck = false;
          cargoBuildFeatures = ["board-solo2"];
          nativeBuildInputs = old: old ++ [pkgs.clang];
          LIBCLANG_PATH = "${pkgs.libclang.lib}/lib";
        };
      };
    };
}

yusdacra avatar Aug 10 '22 18:08 yusdacra

This specific issue is solved, so I'll close this and someone can open another issue if there are any other issues that pertain to dream2nix

yusdacra avatar Sep 02 '22 03:09 yusdacra