Infinite recursion at /nix/var/nix/profiles/per-user/root/channels/nixos/lib/modules.nix while building Rust crate

I’m trying to provision Rust crate into NixOS. I found a way to do this, in NixPkgs documentation(I’m referring to Nixpkgs 23.11 manual | Nix & NixOS), so I built my .nix config this way:

{ pkgs, rustPlatform, stdenv, fetchFromGitHub, ... }:
rustPlatform.buildRustPackage rec {
  pname = "webhook-server";
  version = "0.1.4";

  src = fetchFromGitHub {
    owner = "Nukesor";
    repo = "webhook-server";
    rev = 0.1.4;
    sha256 = "1iga3320mgi7m853la55xip514a3chqsdi1a1rwv25lr9b1p7vd3";
  };

  cargoSha256 = "17ldqr3asrdcsh4l29m3b5r37r5d0b3npq1lrgjmxb6vlx6a36qh";
  verifyCargoDeps = true;

  meta = with stdenv.lib; {
    description = "Trigger program/script execution on your server via http calls";
    homepage = https://github.com/nukesor/webhook-server;
    license = licenses.mit;
    maintainers = [ maintainers.nukesor ];
    platforms = platforms.all;
  };
}

But when I’m trying to nixos-rebuild switch, I receive this:

error: infinite recursion encountered, at /nix/var/nix/profiles/per-user/root/channels/nixos/lib/modules.nix:217:28
(use '--show-trace' to show detailed location information)

What is the problem and how to avoid it? As far as I investigated, the main reason of infinite recursion appearance is improper usage of nixpkgs.overlays, but there’s no such thing in my case

How and where are you referring your “package”?

Nowhere, yet. I’m just trying to make NixPkgs to build it

How?

Where have you stored that file?

Why do you expect it to be built by a nixos-rebuild?

Ah, I got your point. This config file is named webhook-server.nix, placed in /etc/nixos/ and reffered in /etc/nixos/configuration.nix:

imports = [
    ./hardware-configuration.nix
    ./networking.nix # generated at runtime by nixos-infect
    ./webhook-server.nix
  ];

It’s not a module, you can’t use it that way, it’s a “package”, and the way it’s written, you need to use callPackage on it and put it to your systemPackages.

Could you please provide an example? I tried adding this snippet to configuration.nix

webhook-server = pkgs.callPackage ./webhook-server.nix {
  }

but that’s not syntactically correct

Something like this:

{pkgs, ... }:

let
  webhookServer = pkgs.callPackage ./webhook-server.nix {};
in {
  environment.systemPackages = [ webhookServer ];
}

or (if you prefer to not have a let binding):

{pkgs, ... }:

{
  environment.systemPackages = [ (pkgs.callPackage ./webhook-server.nix {}) ];
}

PS: when you say it is “not syntactically correct”, you really should provide more context and the error message.

Thanks. That worked. I’ve tried similar solution, but mine was without round parenthesis :slight_smile:

How do I invoke this package inside .nix configs?
Tried using ${pkgs.webhook-server}/bin/webhook-server, but that didn’t work

What do you mean by “invoking”?

Anyway, as you havent made webhook-server an overlay or anything else, there won’t be a webhook-server attribute in pkgs.

I rewritten my package configs, using hints, you gave me there: Build GoLang code provided not as Go module

webhook.nix

{ pkgs, ... }:
{
  nixpkgs.overlays = [(self: super: {
    webhook-server = self.callPackage ./webhook-server.nix {};
  })];    
}

webhook-server.nix

{ pkgs, rustPlatform, stdenv, fetchFromGitHub, ... }:
rustPlatform.buildRustPackage rec {
  pname = "webhook-server";
  version = "0.1.4";

  src = fetchFromGitHub {
    owner = "Nukesor";
    repo = "webhook-server";
    rev = "0.1.4";
    sha256 = "1iga3320mgi7m853la55xip514a3chqsdi1a1rwv25lr9b1p7vd3";
  };

  cargoSha256 = "1ykq82pi537qnzx7rj7njh6nmknygz22yd40sljfrayly9yhdran";
  verifyCargoDeps = true;

  meta = with stdenv.lib; {
    description = "Trigger program/script execution on your server via http calls";
    homepage = https://github.com/nukesor/webhook-server;
    license = licenses.mit;
    maintainers = [ maintainers.nukesor ];
    platforms = platforms.all;
  };
}

Crate build process was successful, but it seems that no binary was produced. Am I again doing something wrong?
I was expecting to see webhookserver binary at /nix/store/hmxq76cj8hdfxzcj9an08q3n37nw0ws2-webhook-server-0.1.4/bin, but there were no such thing
There’s only rg binary in there

1 Like

As far as I remember the pname has to match the binary name, though that might be missremembering and confusing different language builders and their internals, I sadly can’t test it today anymore, as I’m only on mobile internet and don’t want to download the rust platform :smiley:

Half of my city is offline…

Half of my city is offline…
I’m sorry to hear that

What is the difference between name and pname?

Tried setting pname to webhookserver, but that’s not worked(((

Okay, I was able to look at it. Even though my city is still under “black out”, I went to the office as I have a certification scheduled this evening and I strictly need steady internet for it…

Even though it is still building, I have learned the following so far…

  1. The sha256 passed to fetchFromGitHub matches the sha256 of the ripgrep sources which have already been in my store, therefore no error. Using pkgs.lib.fakeSha256 I was able to determine 0cndr8r5z64rkgvzkjxz3kf40yi7nq42as6hrfcq9ip02a3wazpz as correct. Thats why I like to pass an additional name attribute to fetch* functions.
  2. The rev needs to be v0.1.4
  3. Of course I had to adjust the cargoSha256 as well.
  4. Non local pathes as in the meta.homepage attribute are deprecated as far as I know, you should a string there.

Okay, this version built something that had a bin/webhook:

{ pkgs, rustPlatform, stdenv, fetchFromGitHub, ... }:
rustPlatform.buildRustPackage rec {
  pname = "webhook-server";
  version = "0.1.4";

  src = fetchFromGitHub {
    owner = "Nukesor";
    repo = "webhook-server";
    rev = "v0.1.4";
    sha256 = "0cndr8r5z64rkgvzkjxz3kf40yi7nq42as6hrfcq9ip02a3wazpz";
  };

  cargoSha256 = "1g2y0xa471b9mbyfgf58dwd75fscybr7acmsc794jzrgcs90m6ma";
  verifyCargoDeps = true;

  meta = with stdenv.lib; {
    description = "Trigger program/script execution on your server via http calls";
    homepage = "https://github.com/nukesor/webhook-server";
    license = licenses.mit;
    maintainers = [ maintainers.nukesor ];
    platforms = platforms.all;
  };
}

Sadly it doesn’t seem to have a --version flag :smiley::

./result/bin/webhookserver --version
15:20:13 [INFO] Init settings file
15:20:13 [INFO] Parsing config files
15:20:13 [INFO] Checking path: "/etc/webhook_server.yml"
15:20:13 [INFO] Checking path: "/home/demo/.config/webhook_server.yml"
15:20:13 [INFO] Checking path: "./webhook_server.yml"
Error: missing field `webhooks`
1 Like

Thanks. That works :partying_face: