nix-community / gomod2nix

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`nix build` hangs on `Building subPackage .`

marcuswhybrow opened this issue · comments

Hello, it's my first time using gomod2nix. My flake builds my hello world main.go, but always hangs for 8 seconds at Building subPackage . It hangs for much longer on a real project I'm attempting to transition. It feels like a setup cost I should be paying once, which is then cached, but it's happening on every code change. Am I doing something wrong?

❯ ls
flake.lock  flake.nix  go.mod  gomod2nix.toml main.go

❯ cat go.mod
module github.com/marcuswhybrow/myproject

go 1.20

❯ cat gomod2nix.toml
schema = 3

[mod]

❯ nix build  --verbose --log-format bar-with-logs
this derivation will be built:
  /nix/store/pw50p05dxlnnz16j7a9dvq1p29gcr7q0-myproject.drv
building '/nix/store/pw50p05dxlnnz16j7a9dvq1p29gcr7q0-myproject.drv'...
myproject> unpacking sources
myproject> unpacking source archive /nix/store/wycclwg1dgyrhx4j0z6w94ch707cdc8j-golang
myproject> source root is golang
myproject> patching sources
myproject> configuring
myproject> building
myproject> Building subPackage .        <-- Hangs here for 8 seconds
myproject> internal/goarch
myproject> internal/unsafeheader
myproject> internal/abi
myproject> internal/cpu
myproject> internal/bytealg
...

My flake.nix is dead simple...

{
  description = "Static Site Generator written in Golang";

  inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
  inputs.flake-utils.url = "github:numtide/flake-utils";
  inputs.gomod2nix.url = "github:nix-community/gomod2nix";

  outputs = inputs: inputs.flake-utils.lib.eachDefaultSystem (system: let
    pkgs = import inputs.nixpkgs {
      inherit system;
      overlays = [ inputs.gomod2nix.overlays.default ];
    };
  in {
    packages.default = pkgs.buildGoApplication {
      name = "myproject";
      pwd = ./.;
      src = ./.;
      modules = ./gomod2nix.toml;
    };

    devShells.default = pkgs.mkShell {
      name = "myproject";
      packages = [
        (pkgs.mkGoEnv { pwd = ./.; })
        pkgs.gomod2nix
      ];
    };
  });
}

I think these lines are the source of my troubles...

for pkg in $(getGoDirs ""); do
echo "Building subPackage $pkg"
buildGoDir install "$pkg"
done

Thanks for any suggestions.

I've also noticed the same thing. Despite the claim that each dependency is cached, building with gomod2nix is noticeably longer than building with the nixpkgs "buildGoModule". I've switched back to that.