Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use string interpolation to generate Cargo.lock path #351

Open
wants to merge 2 commits into
base: release-0.11.0
Choose a base branch
from

Conversation

Zabot
Copy link

@Zabot Zabot commented Mar 18, 2024

When specifying a custom workspaceSrc

pkgs.rustBuilder.makePackageSet {
  ...
  workspaceSrc = nix-filter {
    root = ./.;
    include = [
      "crates"
      ./Cargo.toml
      ./Cargo.lock
    ];
  };
}

nix build will fail with the following error

at /nix/store/yr2fm9jbvcvy4p55b6d1s4s5bx9pnhnz-source/Cargo.nix:40:21:

   39|   workspaceSrc = if args.workspaceSrc == null then ./. else args.workspaceSrc;
   40|   currentLockHash = builtins.hashFile "sha256" (workspaceSrc + /Cargo.lock);
     |                     ^
   41|   lockHashIgnored = if ignoreLockHash

error: access to absolute path '/Cargo.lock' is forbidden in pure eval mode (use '--impure' to override)

If you do build with --impure, the build later fails at the same place, this time failing to find the directory

at /nix/store/x2ysy1n9p12jrfk1s5kaxjkwm9q22kgl-source/Cargo.nix:40:21:

   39|   workspaceSrc = if args.workspaceSrc == null then ./. else args.workspaceSrc;
   40|   currentLockHash = builtins.hashFile "sha256" (workspaceSrc + /Cargo.lock);
     |                     ^
   41|   lockHashIgnored = if ignoreLockHash

error: getting status of '/Cargo.lock': No such file or directory

Both of these errors are because nix attempts to resolve the /Cargo.lock path used to lookup the lockfile as an absolute path on the file system, and fails. Instead we should use string interpolation to append the /Cargo.lock path to whatever path was passed in through the workspaceSrc.

I'm not quite sure why this isn't an issue when the workspaceSrc is not set. It seems like its related to how nix tries to evaluate the expression though, perhaps because the left hand side is unambiguously a path the right side is simply concatenated instead of being resolved first.

@@ -28,7 +28,7 @@ args@{
let
nixifiedLockHash = "{{ cargo_lock_hash }}";
workspaceSrc = if args.workspaceSrc == null then ./. else args.workspaceSrc;
currentLockHash = builtins.hashFile "sha256" (workspaceSrc + /Cargo.lock);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I just reviewed a duplicate change for this, but either way this change will be intergrated. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants