nix build fails to find Cargo.lock #822

Open
opened 2025-05-08 15:16:52 +00:00 by lafleur · 1 comment

I use the nix #oci-image build target because it lets me build the static release binary using less disk space than using a docker Ubuntu image, and with more chances of success than directly asking cargo to build a static binary (which was always a little tricky for me).

But, having rebased on the main branch, the nix build fails to find Cargo.lock - although there is one at the root of the repo.

# Invoked with $ nix build
error:
        while calling the 'derivationStrict' builtin
         at <nix/derivation-internal.nix>:37:12:
           36|
           37|   strict = derivationStrict drvAttrs;
             |            ^
           38|

        while evaluating derivation 'conduwuit-0.5.0-rc.5'
         whose name attribute is located at /media/extra/nix/store/64lxq5kn85vglf3xhbh0zxjj8hin3m42-source/pkgs/stdenv/generic/make-derivation.nix:375:7

        while evaluating attribute 'cargoArtifacts' of derivation 'conduwuit-0.5.0-rc.5'
         at /media/extra/nix/store/46vr0sisgzfa40kfxnrvp8nx8a0b59rv-source/lib/mkCargoDerivation.nix:60:11:
           59| } // {
           60|   inherit cargoArtifacts;
             |           ^
           61|

       (stack trace truncated; use '--show-trace' to show the full, detailed trace)

       error: unable to find Cargo.lock at /nix/store/0ccnxa25whszw7mgbgyzdm4nqc0zwnm8-source. please ensure one of the following:
       - a Cargo.lock exists at the root of the source directory of the derivation,
         it is *not* included in .gitignore, and that it is at least staged with git
         via `git add -N Cargo.lock`
       - set `cargoVendorDir = vendorCargoDeps { cargoLock = ./some/path/to/Cargo.lock; }`
       - set `cargoVendorDir = vendorCargoDeps { src = ./src/containing/cargo/lock/file; }`
       - set `cargoVendorDir = null` to skip vendoring altogether

Build details :

  • nix version: nix (Nix) 2.24.14
  • nixos version: NixOs 24.11
  • system: radxa zero with 2G of RAM (aarch64-linux-gnu)
  • tried with commit d78fc535
  • I'm definitely not a nix wizard, in fact I liked nix because of that "easy static build" feature. I may provide more logs if needed.
I use the nix `#oci-image` build target because it lets me build the static release binary using less disk space than using a docker Ubuntu image, and with more chances of success than directly asking cargo to build a static binary (which was always a little tricky for me). But, having rebased on the main branch, the nix build fails to find `Cargo.lock` - although there _is_ one at the root of the repo. ``` nix # Invoked with $ nix build error: … while calling the 'derivationStrict' builtin at <nix/derivation-internal.nix>:37:12: 36| 37| strict = derivationStrict drvAttrs; | ^ 38| … while evaluating derivation 'conduwuit-0.5.0-rc.5' whose name attribute is located at /media/extra/nix/store/64lxq5kn85vglf3xhbh0zxjj8hin3m42-source/pkgs/stdenv/generic/make-derivation.nix:375:7 … while evaluating attribute 'cargoArtifacts' of derivation 'conduwuit-0.5.0-rc.5' at /media/extra/nix/store/46vr0sisgzfa40kfxnrvp8nx8a0b59rv-source/lib/mkCargoDerivation.nix:60:11: 59| } // { 60| inherit cargoArtifacts; | ^ 61| (stack trace truncated; use '--show-trace' to show the full, detailed trace) error: unable to find Cargo.lock at /nix/store/0ccnxa25whszw7mgbgyzdm4nqc0zwnm8-source. please ensure one of the following: - a Cargo.lock exists at the root of the source directory of the derivation, it is *not* included in .gitignore, and that it is at least staged with git via `git add -N Cargo.lock` - set `cargoVendorDir = vendorCargoDeps { cargoLock = ./some/path/to/Cargo.lock; }` - set `cargoVendorDir = vendorCargoDeps { src = ./src/containing/cargo/lock/file; }` - set `cargoVendorDir = null` to skip vendoring altogether ``` Build details : - nix version: nix (Nix) 2.24.14 - nixos version: NixOs 24.11 - system: radxa zero with 2G of RAM (aarch64-linux-gnu) - tried with commit d78fc535 - I'm definitely not a nix wizard, in fact I liked nix because of that "easy static build" feature. I may provide more logs if needed.
Jade added the
Help wanted
label 2025-05-08 15:22:23 +00:00
Author

It seems the issue was due to the fact that I was calling nix as

nix --store /path/to/my/store

The crane crate apparently tries to fetch from /nix/store/... whereas it should use /path/to/my/store/nix/store/.... See this crane issue for insights. The issue was closed with a fixup but conduwuit's flake seems to bring it up again.

As a workaround, I added

cargoVendorDir = craneLib.vendorCargoDeps {
  cargoLock = ../../../Cargo.lock;
};

in commonAttrs in /nix/pkgs/main/default.nix.

I don't know what to do with this now. Is this workaround a real fix ? It possibly wouldn't harm to point to Cargo.lock explicitly. I could propose a MR with a proper comment to document what it addresses. I'm just really too fresh to nix to tell.

I'll wait for some input before closing this issue.

It seems the issue was due to the fact that I was calling nix as ``` nix nix --store /path/to/my/store ``` The `crane` crate apparently tries to fetch from `/nix/store/...` whereas it should use `/path/to/my/store/nix/store/...`. See [this crane issue](https://github.com/ipetkov/crane/issues/446) for insights. The issue was closed with a fixup but conduwuit's flake seems to bring it up again. As a workaround, I added ``` nix cargoVendorDir = craneLib.vendorCargoDeps { cargoLock = ../../../Cargo.lock; }; ``` in `commonAttrs` in `/nix/pkgs/main/default.nix`. I don't know what to do with this now. Is this workaround a real fix ? It possibly wouldn't harm to point to `Cargo.lock` explicitly. I could propose a MR with a proper comment to document what it addresses. I'm just really too fresh to nix to tell. I'll wait for some input before closing this issue.
nex added the
Meta/Packaging
label 2025-05-09 21:30:59 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: continuwuation/continuwuity#822
No description provided.