nix-community / gomod2nix

Convert applications using Go modules to Nix expressions [maintainer=@adisbladis]

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`getGoDirs` and `buildGoDir` are undefined in check when using custom `buildPhase`

niklashhh opened this issue · comments

Passing

  buildPhase = ''
runHook preBuild
make
runHook postBuild
  '';

to buildGoApplication causes checkPhase to error with

/nix/store/rk3g4mxrs84bv1vanqnzpdkhm73ksr0z-stdenv-linux/setup: line 1601: getGoDirs: command not found

Or if getGoDirs is defined, then the error is

/nix/store/rk3g4mxrs84bv1vanqnzpdkhm73ksr0z-stdenv-linux/setup: line 1602: buildGoDir: command not found

this happens because getGoDirs and buildGoDir are defined in the default buildPhase.

Both checkPhase and buildPhase share the same code for looping over subCommands:

          for pkg in $(getGoDirs test); do
            buildGoDir test "$pkg"
          done

In my opinion this should be refactored out and the getGoDirs and buildGoDir both be inputs to the buildGoApplication function.

I do understand that overriding buildPhase and/or checkPhase isn't exactly intended, but my use-case is to run the make command in buildPhase which isn't supported by the default buildPhase build command:

if ! OUT="$(go $cmd "''${flags[@]}" $dir 2>&1)"; then

In my case it was rather simple to write the checkPhase manually, so that is a reasonable workaround.