nix-community / naersk

Build Rust projects in Nix - no configuration, no code generation, no IFD, sandbox friendly.
MIT License
741 stars 88 forks source link

Build one crate in workspace? #154

Open leo60228 opened 3 years ago

leo60228 commented 3 years ago

I've tried both:

naersk.buildPackage {
  root = ./workspace;
  cargoOptions = x: x ++ [ "-p" "crate" ];
}

and

naersk.buildPackage {
  src = ./workspace;
  root = ./workspace/crate;
}

The former doesn't work because the argument is in the wrong location, and the latter doesn't work because it's looking for Cargo.lock in the wrong location.

ghost commented 3 years ago
  cargoBuildOptions = x: x ++ [ "-p" "crate" ];
  cargoTestOptions = x: x ++ [ "-p" "crate" ];

worked for me.

leo60228 commented 3 years ago

I figured that out but forgot to update the issue. I think it's probably worth having its own argument, though.

paulyoung commented 3 years ago

Thanks for the advice. That worked for me.

Since people here are also using workspaces, has anyone gotten this to work? https://github.com/nmattia/naersk/issues/177

alarsyo commented 2 years ago

I feel like this is what the targets option is supposed to do, but it doesn't work. Setting cargoBuildOptions does the trick indeed

winston0410 commented 2 years ago

@petabyteboy 's trick works for building the derivation, but I am getting another error when I tried to deploy the derivation from another flake.

I have derivation like this:

        defaultPackage = naersk-lib.buildPackage {
          root = ../.;
          cargoBuildOptions = x: x ++ [ "-p" "jyutping-microservice" ];
          cargoTestOptions = x: x ++ [ "-p" "jyutping-microservice" ];
        };

and this derivation is used in the member crate(so that I have to use ../. to reference the workspace)

And I am getting this error when I tried to deploy it with a flake:

error: access to path '/nix/store/Cargo.toml' is forbidden in restricted mode

How should I go about that? any solution on this right now?

leo60228 commented 2 years ago

Flakes can't reference files outside of the flake. I think to handle this correctly you should either move the flake to the root of the workspace or split the flake into its own repo. As a hacky solution, I think you could reference the entire workspace as an input to the flake.

aaronArinder commented 3 weeks ago
Screenshot 2024-10-23 at 2 08 10 PM

ty ghost and @leo60228!