radicle-dev / radicle-link

The second iteration of the Radicle code collaboration protocol.
Other
421 stars 39 forks source link

error: attribute 'lib' missing, at /nix/store/gqargdzl2sbxsw8sxfzpmicxalpqr4s3-source/rust-overlay.nix:315:30 #733

Open adaszko opened 2 years ago

adaszko commented 2 years ago

There's a build issue on latest NixOS (21.05):

% nix-shell

error: attribute 'lib' missing, at /nix/store/gqargdzl2sbxsw8sxfzpmicxalpqr4s3-source/rust-overlay.nix:315:30
(use '--show-trace' to show detailed location information)
% nixos-version
21.05.804.5de44c15758 (Okapi)

It's caused by the Mozilla Rust overlay using deprecated nixpkgs "API": https://github.com/mozilla/nixpkgs-mozilla/pull/250

Until the upstream Mozilla overlay PR gets merged, a workaround can be used:

% git diff
diff --git i/default.nix w/default.nix
index a1bfb4e..c8397eb 100644
--- i/default.nix
+++ w/default.nix
@@ -2,7 +2,7 @@
 # and Mozilla's nix overlay README
 # https://www.scala-native.org/en/latest/user/setup.html
 let
-  moz_overlay = import (builtins.fetchTarball https://github.com/mozilla/nixpkgs-mozilla/archive/4521bc61c2332f41e18664812a808294c8c78580.tar.gz);
+  moz_overlay = import (builtins.fetchTarball https://github.com/andersk/nixpkgs-mozilla/archive/3499e085fb6ae1a846bcf425fa9c98a3b77480da.tar.gz);
   pkgs = import <nixpkgs> { overlays = [ moz_overlay ]; };
 in
   with pkgs;
FintanH commented 2 years ago

Thanks for flagging! Recently I've been experimenting with using the following shell.nix:

let
  nixpkgs = import <nixpkgs> {};
  rtc = (nixpkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain);
  rust = rtc.override {
    extensions = [ "rust-src" "rust-analysis" ];
  };
in
  with nixpkgs;
  mkShell {
    name = "rust";
    buildInputs = [
        cargo-deny
        cargo-expand
        cargo-watch
        openssl
        pkgconfig
        ripgrep
        rust
    ];
  }

Using rust-overlay. It might be an idea to commit the shell.nix file and others can use that, how does that sound to you?

adaszko commented 2 years ago
let
  nixpkgs = import <nixpkgs> {};
  rtc = (nixpkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain);
  rust = rtc.override {
    extensions = [ "rust-src" "rust-analysis" ];
  };
in
  with nixpkgs;
  mkShell {
    name = "rust";
    buildInputs = [
        cargo-deny
        cargo-expand
        cargo-watch
        openssl
        pkgconfig
        ripgrep
        rust
    ];
  }

I'm getting

% nix-shell shell.nix
error: attribute 'rust-bin' missing, at /home/adaszko/repos/radicle-link/shell.nix:3:10

on my machine.

This OTOH works for me:

let
  mozilla_overlay = import (builtins.fetchTarball {
    # url = "https://github.com/mozilla/nixpkgs-mozilla/archive/master.tar.gz";
    url = "https://github.com/mozilla/andersk/archive/3499e085fb6ae1a846bcf425fa9c98a3b77480da.tar.gz";
    sha256 = "1fd9n6p8vjlb5vqka2fzxrf1xb7lif5ibjvx8h1fk5w3yqkds2lg";
  });

  nixpkgs = import <nixpkgs> { overlays = [ mozilla_overlay ]; };
  myrust = ((nixpkgs.rustChannelOf { rustToolchain = ./rust-toolchain; }).rust.override { extensions = [ "rust-src" "rust-analysis" "rustfmt-preview" ];});
in
  with nixpkgs;
  mkShell {
    buildInputs = [
      # to use the latest nightly:
      # nixpkgs.latest.rustChannels.nightly.rust
      # to use a specific nighly:
      # (nixpkgs.rustChannelOf { date = "2018-04-11"; channel = "nightly"; }).rust
      # to use the project's rust-toolchain file:
      # (nixpkgs.rustChannelOf { rustToolchain = ./rust-toolchain; }).rust

      myrust
      cargo-deny
      cargo-expand
      cargo-watch
      openssl
      pkgconfig
      ripgrep
    ];
  }

Note that it pins the overlay to a specific version to avoid some "spontaneous" breakages.

adaszko commented 2 years ago

Somewhat related: Is it even needed to run rustc nightly instead of stable? Is there some feature not available on stable that's being used?

FintanH commented 2 years ago

You likely need to add rust-overlay to your overlays config, i.e. create ~/.config/nixpkgs/overlays.nix and add this line:

[ (import (builtins.fetchTarball "https://github.com/oxalica/rust-overlay/archive/master.tar.gz")) ]

If you already have that file, then you should just be able to add it to your list of overlays.

FintanH commented 2 years ago

Somewhat related: Is it even needed to run rustc nightly instead of stable? Is there some feature not available on stable that's being used?

Easily checked by changing the toolchain to stable, and the first compiler error you run into is:

    Checking radicle-std-ext v0.1.0 (/home/haptop/Developer/radicle-link/std-ext)
error[E0554]: `#![feature]` may not be used on the stable release channel
 --> std-ext/src/lib.rs:6:1
  |
6 | #![feature(extend_one)]
  | ^^^^^^^^^^^^^^^^^^^^^^^

I think there may be others, so yes we're relying on nightly for the time being :)

adaszko commented 2 years ago

You likely need to add rust-overlay to your overlays config, i.e. create ~/.config/nixpkgs/overlays.nix and add this line:

[ (import (builtins.fetchTarball "https://github.com/oxalica/rust-overlay/archive/master.tar.gz")) ]

If you already have that file, then you should just be able to add it to your list of overlays.

Hmm, from a point of view of someone completely new to the project, that's an additional step that needs to be performed. It can be avoided by specifying the overlay config within shell.nix (and thus also avoid the surprising error above). Is there some advantage to having the configuration done per-machine (i.e. in ~/.config/nixpkgs/overlays.nix)?

FintanH commented 2 years ago

For me, it's easier and is one of the recommended ways here: https://github.com/oxalica/rust-overlay#use-as-a-classic-nix-overlay.

But if you have a better setup then I'd be willing to look over a PR and try it out :) My Nix-fu isn't the best, so I use what I can to get by :smile:

adaszko commented 2 years ago

For me, it's easier and is one of the recommended ways here: https://github.com/oxalica/rust-overlay#use-as-a-classic-nix-overlay.

But if you have a better setup then I'd be willing to look over a PR and try it out :) My Nix-fu isn't the best, so I use what I can to get by 😄

Same here, Sir 😄 Looks like oxalica's overlay claims to improve upon Mozilla's. I have only used Mozilla's so far so would have to play with it first to make my mind about it :)

FintanH commented 2 years ago

Ahaha very good :smile: Welcome to the club! I used Mozilla's for a while but then it started breaking a lot for me so I abandoned it for rust-overlay and haven't had problems since :raised_hands: