Skip to content

gotest doesn't work for projects with dependencies #582

@winterqt

Description

@winterqt

As with the Rust situation, gotest fails in pre-commit drvs because it can't grab dependencies.

Workaround:

{ config, ... }:

let
  deps = (pkgs.buildGoModule {
    name = "go-deps";
    src = config.rootSrc;
    vendorHash = "...";
  }).goModules;

  goSetupHook = pkgs.makeSetupHook {
    name = "go-setup-hook";
    substitutions = {
      shell = lib.getExe pkgs.bash;
      inherit deps;
    };
  } (pkgs.writeScript "go-setup-hook.sh" ''
    #!@shell@

    goSetupPostUnpackHook() {
      echo "copying go deps"
      cp -r --reflink=auto @deps@ "$sourceRoot/vendor"
    }

    postUnpackHooks+=(goSetupPostUnpackHook)
  '');
in
{
  hooks.gotest.enable = true;
  hooks.gotest.package = pkgs.go; # not strictly required, but good to keep the deps FOD Go ver in sync with this one
  hooks.gotest.extraPackages = [ goSetupHook ];

We can easily fix it by just copying the Rust work around, but this does beg two larger questions worth pondering:

  1. Is there a better way to handle this in the hook module, generically? e.g. a setupHooks option that can propagate to the check drv, but does not propagate to enabledPackages like above does. (Technically there's ways to make enabledPackages work now even in that case, but they're obviously not ideal.)
  2. Should more test cases be added? 99% of the hooks here are not tested in CI, leading lots of pretty glaring bugs like this just lurking.

Happy to help with the implementation(s) of any of these points. :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions