Undefined variable 'fetchFromGitHub'

I am trying to package eww for a polybar written in rust. I started with the following code:

{ config, pkgs, lib, rustPlatform, fetchFromGitHub, ... }:

rustPlatform.buildRustPackage rec {
  pname = "eww";
  version = "4f59424e0e82eb7ce76badb266974dd3e7ea6d8c";

  src = fetchFromGitHub {
    owner = "elkowar";
    repo = pname;
    rev = version;
    sha256 = "1hqps7l5qrjh9f914r5i6kmcz6f1yb951nv4lby0cjnp5l253kps";
  };

  cargoSha256 = "1hqps7l5qrjh9f914r5i6kmcz6f1yb951nv4lby0cjnp5l253kps";

  meta = with lib; {
    description = "ElKowar's wacky widgets";
    homepage = "https://github.com/elkowar/eww";
    license = licenses.mit;
    maintainers = [];
  };
}

But I kept on getting the following error:

error: undefined variable 'fetchFromGitHub' at /etc/nixos/eww.nix:7:9
(use '--show-trace' to show detailed location information)

Why is it not working? I tried builtins.fetchFromGitHub as well, but still I got the same error.

The function needs to actually be given the fetchFromGitHub argument. This is done using pkgs.callPackage in nixpkgs, like so:

{ pkgs }:

{
    eww = pkgs.callPackage ./eww.nix { };
}

callPackage is a function that automagically figures out which arguments your function wants, and then provides them from its own set. This pill explains it well: Nix Pills | Nix & NixOS

Of course, you need pkgs for that, but luckily you should have that already if building a nixos configuration :slight_smile:

The alternative is to call those arguments directly from pkgs instead, because your function will almost surely be given pkgs if you use import instead of calling it, but that’s not how nix derivations are typically written.

2 Likes

@TLATER thank you so much and it worked. I think I have actually stumbled on this issue previously, fixed it and totally forgot.