Failed to fetch `https://github.com/rust-lang/crates.io-index`

I was trying to create derivation for regolith-powerd and this error popped up in which there is an extra ` after the link from where it is fetching crates.

    Updating crates.io index
warning: spurious network error (2 tries remaining): [6] Couldn't resolve host name (Could not resolve host: github.com); class=Net (12)
warning: spurious network error (1 tries remaining): [6] Couldn't resolve host name (Could not resolve host: github.com); class=Net (12)
error: Unable to update registry `crates-io`

Caused by:
  failed to fetch `https://github.com/rust-lang/crates.io-index`

Caused by:
  network failure seems to have happened
  if a proxy or similar is necessary `net.git-fetch-with-cli` may help here
  https://doc.rust-lang.org/cargo/reference/config.html#netgit-fetch-with-cli

Derivation expresssion -

{ pkgs ? import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/06278c77b5d162e62df170fec307e83f1812d94b.tar.gz") {}}:

pkgs.stdenv.mkDerivation {
  pname = "regolith-powerd";
  version = "v0.1";

  src = pkgs.fetchFromGitHub {
    owner = "regolith-linux";
    repo = "regolith-powerd";
    rev = "master";
    sha256 = "uXTGzbV0ASCq7s5L+su6j0Ol0P1cIVj0QnNVxH6ljXM=";
  };

buildInputs = with pkgs; [
   gnumake
    cargo
    rustc
    gcc
    clang
    pkg-config
    glib
  ];
  
 installPhase = ''
    mkdir -p $out/bin
    mkdir -p $out/share
    cp -r target/release/regolith-powerd $out/bin  
  '';
}

image

Can anyone tell me if I am doing something the wrong way?

Networking is disabled inside the Nix build sandbox, the Nixpkgs manual has a section on building Rust packages.

You should consider using a commit hash in rev (latest one is 5693fb4dd16433046fd45609871704cf906dd222 at the time of writing this) or one of the tags instead, otherwise when the repository gets new changes Nix will refuse to build because the sha256 won’t match.

2 Likes

I haven’t tried it, but this builds:

{
  lib,
  rustPlatform,
  fetchFromGitHub,
  pkg-config,
  glib,
}:

rustPlatform.buildRustPackage {
  pname = "regolith-powerd";
  version = "3.1";

  src = fetchFromGitHub {
    owner = "regolith-linux";
    repo = "regolith-powerd";
    rev = "r3_1";
    hash = "sha256-uXTGzbV0ASCq7s5L+su6j0Ol0P1cIVj0QnNVxH6ljXM=";
  };

  cargoHash = "sha256-IrB+ktEQTdtO7EdY3oGNXTyebHJm12caDWfayogp4VM=";

  nativeBuildInputs = [ pkg-config ];

  buildInputs = [ glib ];

  meta = {
    mainProgram = "regolith-powerd";
    description = "Daemon to sync gsd power settings with Regolith on Wayland. Provides idle state functionality and sets power button action";
    homepage = "https://github.com/regolith-linux/regolith-powerd";
    license = lib.licenses.gpl3Plus;
  };
}
1 Like

@FedericoSchonborn Thanks.