Attribute buildGoModule missing at modules.nix

Highly respected community,

I’m trying to build Go module for use inside of NixOS. I’m using buildGoModule to build the sources, fetchgit to get sources from git repository and nixpkgs.overlays to get into the pkgs set.

Here’s a Nix Expression Language code snippet, which I’m using to build package inside NixOS:

{ pkgs, lib, fetchgit, buildGoModule, ... }: {
  nixpkgs.overlays = [
    (self: super: {
      alps = buildGoModule rec {
        pname = "alps";
        version = "v1.0.0"; # latest available tag at the moment

        src = fetchgit {
          url = "https://git.selfprivacy.org/ilchub/selfprivacy-alps";
          rev = "dc2109ca2fdabfbda5d924faa4947f5694d5d758";
          sha256 = null;
        };

        vendorSha256 = null;

        subPackages = [ "." ];

        deleteVendor = true;
        runVend = false;

        meta = with lib; {
          description =
            "Webmail application for the dovecot/postfix mailserver";
          homepage = "https://git.selfprivacy.org/ilchub/selfprivacy-alps";
          license = licenses.mit;
        };
      };
    })
  ];

  systemd.services = {
    alps = {
      path = with pkgs; [ alps ];
      serviceConfig = {
        ExecStart =
          "${pkgs.alps}/bin/alps -theme alps imaps://example.com:993 smtps://example.com:465";
      };
    };
  };
}

But when I’m performing nixos-rebuild switch, previously including file using: imports = [ alps.nix ];, rebuild fails with the following error:

error: attribute 'buildGoModule' missing, at /nix/var/nix/profiles/per-user/root/channels/nixos/lib/modules.nix:262:28
(use '--show-trace' to show detailed location information)

Could someone please suggest, what could be the reason of such behavior?

Thanks in advance.

You are mixing up a NixOS modules and a package definition.

What you probably intended is putting your package definition in its own file (e.g. alps.nix):

{ lib, fetchgit, buildGoModule, ... }:

buildGoModule rec {
  # ...
}

And call it in your overlay with callPackage:

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

  systemd.services = {
    # ...
  };
}