nix-community / crate2nix

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

using crate2nix with nixpkgs and flake: `error: attribute 'currentSystem' missing` #210

Closed happysalada closed 2 years ago

happysalada commented 2 years ago

After adding a package in nixpkgs with crate2nix, I'm experiencing some problems using it with flakes.

When I try to add it, I get the following stacktrace

at /nix/store/dxdvm5d0bmxhldkvmxl24xbac9xhq4x7-source/pkgs/top-level/impure.nix:15:1:

           14|
           15| { # We put legacy `system` into `localSystem`, if `localSystem` was not passed.
             | ^
           16|   # If neither is passed, assume we are building packages on the current

       … from call site

       at /nix/store/dxdvm5d0bmxhldkvmxl24xbac9xhq4x7-source/pkgs/servers/search/meilisearch/Cargo.nix:7:1

            6| { nixpkgs ? <nixpkgs>
            7| , pkgs ? import nixpkgs { config = {}; }
             |          ^
            8| , lib ? pkgs.lib

       … while evaluating 'buildRustCrateWithFeatures'

it looks like in the call to import nixpkgs, the system attribute is not passed. I'm wondering how to best solve this issue. currently trying a few things.

You can test this in nixpkgs master by running nix build .#meilisearch -L it will give you the whole stackstrace.

yusdacra commented 2 years ago

You need to pass in the pkgs to Cargo.nix while you are importing it in default.nix in the same folder. So adding pkgs to the arguments and inherit pkgs; in import Cargo.nix { ... } works fine.

happysalada commented 2 years ago

Thanks a lot of the help on this! I tried modifying the system attribute inside the import, but the best thing was indeed to pass pkgs directly. I tried removing the nixpkgs = ... line as well since it didn't seem needed.