Code Monkey home page Code Monkey logo

gomod2nix's Introduction

Gomod2nix

Convert applications using Go modules -> Nix

Usage

From the Go project directory execute:

$ gomod2nix

This will create gomod2nix.toml that's used like so

let
  pkgs = import <nixpkgs> {
    overlays = [
      (self: super: {
        buildGoApplication = super.callPackage ./builder { };
      })
    ];
  };
in pkgs.buildGoApplication {
  pname = "gomod2nix-example";
  version = "0.1";
  src = ./.;
  modules = ./gomod2nix.toml;
}

For more in-depth usage check the Getting Started and the Nix API reference docs.

Motivation

The announcement blog post contains comparisons with other Go build systems for Nix and additional notes on the design choices made.

License

This project is licensed under the MIT License. See the LICENSE file for details.

About the project

The developmentent of Trustix (which Gomod2nix is a part of) has been sponsored by Tweag I/O and funded by the NLNet foundation and the European Commission’s Next Generation Internet programme through the NGI Zero PET (privacy and trust enhancing technologies) fund.

NGI0 logo NLNet banner Tweag logo

gomod2nix's People

Contributors

adisbladis avatar charles-dyfis-net avatar dependabot[bot] avatar doronbehar avatar gtrunsec avatar ldicarlo avatar martinbaillie avatar mic92 avatar srhb avatar xhalo32 avatar yihuang avatar zuqq avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

gomod2nix's Issues

Using flakes with go.mod replace directives

When building a go application with buildGoApplication, replace directives are always treated as relative values. Unfortunately with flakes, this means they are relative to the source's path in the nix store. E.g. /nix/store/i0mx81w7qj13i90f9xkzk0dzhk6h0hwv-source

{
  inputs = {
    gomod2nix = {
      inputs.nixpkgs.follows = "nixpkgs";
      url = "github:nix-community/gomod2nix";
    };
    nixpkgs.url = "github:NixOS/nixpkgs/master";
  };
  outputs = { self, gomod2nix, nixpkgs }:
    let
      pkgs = import nixpkgs {
        system = "x86_64-linux";
        overlays = [
          gomod2nix.overlays.default
        ];
      };
    in {
      packages.x86_64-linux.default = pkgs.buildGoApplication {
        modules = ./gomod2nix.toml;
        name = "demo";
        pwd = ./.;
        src = pkgs.lib.cleanSource ./.;
      };
    };
}
nix build --impure

This works with a replace directive such as:

replace github.com/owner/example => ../../../home/username/projects/example

But fails with a replace directive such as:

replace github.com/owner/example => /home/username/projects/example
/nix/store/i0mx81w7qj13i90f9xkzk0dzhk6h0hwv-source/home/username/projects/example': No such file or directory

Conversely, when running go mod tidy and gomod2nix to generate gomod2nix.toml, the replace directive must either be absolute, or relative to the source in my home directory. This means I maintain two replace directives, one for building, and one for updating dependencies, and swap between the two.

It would be nice if absolute paths were not concatenated with the nix store directory when building, so an absolute path could be used in both scenarios without constantly swapping directives.

I think this is the nix flakes variant of the issue that was addressed in #2.

panic: unrecognized import path

Describe the bug
While trying to package wireproxy using gomod2nix I ran into this:

$ git clone --recursive --depth=1 https://github.com/octeep/wireproxy.git && cd ./wireproxy/
$ gomod2nix
...
panic: unrecognized import path "golang.zx2c4.com/go118/netip"

goroutine 1 [running]:
main.main()
        /build/source/main.go:50 +0x9f3

To Reproduce
See above

Expected behavior
Should be able to recognize "golang.zx2c4.com/go118/netip" as an import path

Environment

  • OS name + version: Linux 5.16.11, NixOS, 22.05 (Quokka)
  • Version of the code:

Fail to build: run go mod vendor

Describe the bug
A clear and concise description of what the bug is.

Try to adding gomod2nix with using flake result in error:

error: builder for '/nix/store/nb278di7gkia1gg74w93nxvd7cj9pihd-gomod2nix-0.1.drv' failed with exit code 1;
       last 10 log lines:
       > building
       > Building subPackage ./.
       > go: inconsistent vendoring in /build/source:
       >         github.com/BurntSushi/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
       >  github.com/orivej/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
       >        github.com/sirupsen/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
       >  golang.org/x/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
       >    golang.org/x/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
       >
       > run 'go mod vendor' to sync, or use -mod=mod or -mod=readonly to ignore the vendor directory
       For full logs, run 'nix log /nix/store/nb278di7gkia1gg74w93nxvd7cj9pihd-gomod2nix-0.1.drv'.
error: 1 dependencies of derivation '/nix/store/w39zbwbbmf2jhh6qjh4x6726lxxnyzi8-nix-shell-env.drv' failed to build

To Reproduce
Steps to reproduce the behavior.

In flake.nix:

inputs.go2nix.url = "github:tweag/gomod2nix";
....

....
      {
        devShell."${system}" = import ./shell.nix {
          inherit pkgs attrs inputs system;
        };

in shell.nix

{ pkgs ? import <nixpkgs> {}, attrs, inputs, system, ... }:
pkgs.mkShell {
  buildInputs = with pkgs; [
    go
    inputs.go2nix.defaultPackage.${system}
  ];
  shellHook = with attrs; ''
    echo 'Entering ${pname}'
  '';
}

Expected behavior
A clear and concise description of what you expected to happen.

Build okay.

Environment

  • OS name + version: nxios
  • Version of the code: master

Additional context
Add any other context about the problem here.

Private repositories

Describe the bug
When I try to run gomod2nix it stucks on private dependency, asking username and pssword.
In .config/git/config I've got

[url "[email protected]:"]
	insteadOf = "https://github.com/"

But it does no effect. When I trying to build application locally with go mod it works fine.

No golang in dev environment/shell

Describe the bug
Starting a shell does not provide any go binary.

To Reproduce
Follow the steps in: https://github.com/tweag/gomod2nix/blob/master/docs/getting-started.md

mkdir test && cd test
nix flake init -t github:tweag/gomod2nix#app
nix develop
# Wait for shell
which go

Returns: which: no go in (...)

Expected behavior
I would expect mkGoEnv to give me the golang binary with the correct version from my go.mod file.

Environment

  • Linux
  • Version of the code: master

Overlay

I was experimenting with packaging a Go program recently I noticed gomod2nix was using an overlay for it's own copy of nixpkgs, which, after a cursory browse of the source, seems unnecessary. Have you thought about removing it?

See: nix-community/poetry2nix@05b788f / https://zimbatm.com/notes/1000-instances-of-nixpkgs

[overlays] have a real performance impact as each flake would introduce its own instance of nixpkgs, which can further multiply if these flakes are than import into multiple NixOS configurations

As an idea, perhaps expose buildGoApplication and mkGoEnv on a lib attribute like: https://github.com/cachix/pre-commit-hooks.nix/blob/5668d079583a5b594cb4e0cc0e6d84f1b93da7ae/flake.nix#L51

Hope I didn't come off as too critical - just an idea for the idea bin.

gomod2nix will hash `.DS_Store` file into output hash

With recent refactoring gomod2nix runs much faster now, because it use the host go and the go pkg cache directory, but one problem is, macos create .DS_Store files into directory automatically, which makes the output hash computed incorrect.

how to handle builder?

error: getting status of '/home/daniel/dev/obs-cli/builder': No such file or directory

support passing extra build flags

go 1.20 support a new build flag -cover which we'd like to use for integration test, currently the only way to pass that is through buildFlags parameter, but it trigger a warning.
I suggest we either remove the warning or support new method to customize build flags.

gomod2nix generate results in error path is not valid

Trying to use this to build a go package using some private modules. Looks like I should be able to do that using generate and import, but getting error path is not valid. Tried without private modules and the problem persists.

Describe the bug
nix-instantiate returns error: path /nix/store/*hash*-*package* is not valid. when running gomod2nix import.

To Reproduce

  1. go mod init
  2. create main.go file with content:
package main

import (
	"log"

	"github.com/rs/zerolog"
	"github.com/rs/zerolog/log"
)

func main() {
	zerolog.SetGlobalLevel(zerolog.InfoLevel)

	log.Error().Msg("Error message")
	log.Warn().Msg("Warning message")

}
  1. go mod tidy
  2. gomod2nix generate (succeeds)
  3. gomod2nix import (fails)

Expected behavior
Expected go dependencies to be imported into the nix store.

Environment

  • Ubuntu running under WSL
  • NixOS from recent nixos/unstable

Tested both OS but the same thing happened.

Additional context
The complete log is here

storvik@computer:~/developer/golang/gonixtest$ gomod2nix generate
INFO[0000] Parsing go.mod                                modPath=go.mod
INFO[0000] Downloading dependencies
INFO[0000] Done downloading dependencies
INFO[0000] Wrote: gomod2nix.toml
storvik@computer:~/developer/golang/gonixtest$ gomod2nix import
INFO[0000] Parsing go.mod                                modPath=go.mod
INFO[0000] Downloading dependencies
INFO[0000] Done downloading dependencies
INFO[0000] Importing sources                             goPackagePath=github.com/rs/zerolog
INFO[0000] Importing sources                             goPackagePath=github.com/mattn/go-isatty
INFO[0000] Importing sources                             goPackagePath=golang.org/x/sys
INFO[0000] Importing sources                             goPackagePath=github.com/mattn/go-colorable
error: path '/nix/store/83frfpjglh25xz7s32w28fw1p54k9170-go-isatty_v0.0.14' is not valid
(use '--show-trace' to show detailed location information)
error: path '/nix/store/gfqmz2qc8qsl29xan4kd3bdy7qjdnmdj-zerolog_v1.27.0' is not valid
(use '--show-trace' to show detailed location information)
/home/storvik/.nix-profile/bin/nix-instantiate --eval --expr
builtins.filterSource (name: type: baseNameOf name != ".DS_Store") (
  builtins.path {
    path = "/home/storvik/developer/gopath/pkg/mod/github.com/mattn/[email protected]";
    name = "go-isatty_v0.0.14";
  }
)

error: path '/nix/store/drh29dg8s120a21f1yicfrxsr4ykcwf0-go-colorable_v0.1.12' is not valid
(use '--show-trace' to show detailed location information)
/home/storvik/.nix-profile/bin/nix-instantiate --eval --expr
builtins.filterSource (name: type: baseNameOf name != ".DS_Store") (
  builtins.path {
    path = "/home/storvik/developer/gopath/pkg/mod/github.com/rs/[email protected]";
    name = "zerolog_v1.27.0";
  }
)

/home/storvik/.nix-profile/bin/nix-instantiate --eval --expr
builtins.filterSource (name: type: baseNameOf name != ".DS_Store") (
  builtins.path {
    path = "/home/storvik/developer/gopath/pkg/mod/github.com/mattn/[email protected]";
    name = "go-colorable_v0.1.12";
  }
)

panic: exit status 1

goroutine 1 [running]:
github.com/tweag/gomod2nix/internal/cmd.glob..func1(0xb16ee0?, {0x822d54?, 0x0?, 0x0?})
        /build/source/internal/cmd/root.go:109 +0x48
github.com/spf13/cobra.(*Command).execute(0xb16ee0, {0xb4d048, 0x0, 0x0})
        /build/source/vendor/github.com/spf13/cobra/command.go:860 +0x663
github.com/spf13/cobra.(*Command).ExecuteC(0xb169e0)
        /build/source/vendor/github.com/spf13/cobra/command.go:974 +0x3b4
github.com/spf13/cobra.(*Command).Execute(...)
        /build/source/vendor/github.com/spf13/cobra/command.go:902
github.com/tweag/gomod2nix/internal/cmd.Execute()
        /build/source/internal/cmd/root.go:124 +0x25
main.main()
        /build/source/main.go:6 +0x17
error: path '/nix/store/0076f6qx7f05ivh6hi71ddx0rnmplnhw-sys_v0.0.0-20210927094055-39ccf1dd6fa6' is not valid
(use '--show-trace' to show detailed location information)

I've tried to run the nix-instantiate command manually too, but same error.

A working solution to use private repos would be great, this is a promising start. Thanks for your contributions to the community.

Go deps in preBuild

Is your feature request related to a problem? Please describe.
I want to generate some files with go but the dependencies are needed for it.

Describe the solution you'd like
Somehow be able to access go deps in the preBuild phase.

Describe alternatives you've considered
Completely rewriting buildPhase in my flake. Kinda a bad solution.

error: value is null while a list was expected in parser.nix:158

error: value is null while a list was expected

       at /nix/store/y6p51jza33989fck64faj0wyk2b1cp15-source/builder/parser.nix:158:22:

          157|             } else {
          158|               path = elemAt m2 0;
             |                      ^
          159|             })

The contents of build file:

{ pkgs ? (
    let
      inherit (builtins) fetchTree fromJSON readFile;
      inherit ((fromJSON (readFile ./flake.lock)).nodes) nixpkgs gomod2nix;
    in
    import (fetchTree nixpkgs.locked) {
      overlays = [
        (import "${fetchTree gomod2nix.locked}/overlay.nix")
      ];
    }
  )
}:

pkgs.buildGoApplication {
  pname = "pkg";
  version = "0.1";
  pwd = builtins.path { path = ./..; };
  src = builtins.path { path = ../pkg; };
  modules = ../gomod2nix.toml;
}

overlay errors

using the flake, i receive the following error.

       error: cannot coerce null to a string

       at /nix/store/y6p51jza33989fck64faj0wyk2b1cp15-source/builder/default.nix:220:17:

          219|   buildGoApplication =
          220|     { modules ? pwd + "/gomod2nix.toml"
             |                 ^
          221|     , src ? pwd

If intentional, assert statements would clarify it.

Is the default overlay meant to be for the Apple silicon?

Hello!

As in the title; it seems that older channels cannot be used with the current overlay, even the latest stable nixos channel nixos-22.05, as its version of the darwin group does not currently have the apple_sdk_11_0 pkgs, and therefore cannot use its callPackage function. Was this intended?

Thank you kindly for the information!

How can the gomod2nix.toml be generated inside the derivation ?

Is your feature request related to a problem? Please describe.
I'm trying to convert a go project to nix using this default.nix:

let
  pkgs = import <nixpkgs> {
    overlays = [
      (self: super: {
        buildGoApplication = pkgs.callPackage ("${builtins.fetchTarball {
          url =  https://github.com/tweag/gomod2nix/archive/67f22dd738d092c6ba88e420350ada0ed4992ae8.tar.gz;
          sha256 = "0a9rhw6djgcrky5nzly3srsl8095q42f2nyzxyisp9fh9fg70nih";
        }}/builder") {};
        gomod2nix = pkgs.callPackage ("${builtins.fetchTarball {
          url =  https://github.com/tweag/gomod2nix/archive/67f22dd738d092c6ba88e420350ada0ed4992ae8.tar.gz;
          sha256 = "0a9rhw6djgcrky5nzly3srsl8095q42f2nyzxyisp9fh9fg70nih";
        }}/default.nix") {};
      })
    ];
  };
  # for available attrs check
  # nix-repl> :l default.nix
  # nix-repl> out.drvAttrs
in pkgs.buildGoApplication rec {
  pname = "zk";
  version = "main";
  #src = ./.;
  src = builtins.fetchGit{
    url = "https://github.com/mickael-menu/zk";
    ref = "main";
    rev = "8c7ec93ca53e8a67e69e49bc24fc6a4567683193";
  };
  patches = [ ./0001-Add-gomod2nix.toml.patch ];
  postPatch = ''
    readlink -f gomod2nix.toml
    head gomod2nix.toml
    '';
  pwd = src;
  modules = "${pwd}/gomod2nix.toml";
  doCheck = false;
  CGO_ENABLED = "1";
}

What is problematic is that tThe gomod2nix.toml exists only after the patch phase and thus I can't specify a useful modules attribute right now. Reason of not just using a local clone is I want to rely just on the sources fetched via git so I can pin the go project's version better.

Describe the solution you'd like
The module attribute should be possible to set in a lazy mannerIt should be possible to run gomod2nix in a runCommand, such that it is possible to convert go projects on-the-fly that have no gomod2nix.toml file yet.

Describe alternatives you've considered
#6 states that before module resolution it fetches the repo, so this could be a solution.

buildGoApplication.override fails

See https://discourse.nixos.org/t/overriding-stdenv-of-gomod2nix-buildgoapplication/26364 where I try to override stdenv of buildGoApplication. I believe override worked at some point, as evidenced by https://github.com/doronbehar/pistol/blob/d4a4290269357d3f98b03a4e8f730a2063ce22bb/flake.nix#L45

Error message:

% nix build github:eliasnaur/gomod2nix-stdenv
error:
       … while evaluating the attribute 'buildGoApplication.override'

         at /nix/store/y6p51jza33989fck64faj0wyk2b1cp15-source/overlay.nix:8:38:

            7| {
            8|   inherit (callPackage ./builder { }) buildGoApplication mkGoEnv;
             |                                      ^
            9|   gomod2nix = callPackage ./default.nix { };

       … while selecting an attribute

         at /nix/store/gg4swr5bg6md0rygxf8q7kbr0w053mh6-source/flake.nix:20:29:

           19|       in {
           20|         packages.default = (pkgs.buildGoApplication.override { stdenv = pkgs.llvmPackages_14.stdenv; }) {
             |                             ^
           21|           name = "test";

       error: value is a function while a set was expected

Source

https://github.com/eliasnaur/gomod2nix-stdenv/blob/8e6f64962cc51ff712980ed92904b193ad19f7f0/flake.nix#L20

Replace directives with commit hash not working

Describe the bug
This redirect directive seems to be leading to a bug at build time

thor> vendor/github.com/decred/dcrd/dcrec/edwards/ecdsa.go:18:2: cannot find package "." in:
thor>   /build/source/vendor/github.com/decred/ed25519
thor> vendor/github.com/decred/dcrd/dcrec/edwards/const.go:10:2: cannot find package "." in:
thor>   /build/source/vendor/github.com/decred/ed25519/edwards25519

To Reproduce
nix build github:JonathanLorimer/cosmos.nix/jonathan/relayer-module#thor

Expected behavior
Should build thorNode successfully

Environment
OS: NixOS 22.05 (Quokka) x86_64

Unable to build golang qt bindings using this tool

Describe the bug
Attempting to use gomod2nix to build https://github.com/therecipe/qt fails. The gomod2nix.toml file is generated successfully, but the buildGoApplication run hits an error:

Building subPackage ./cmd/env
cmd/env/linux_amd64.go:5:8: cannot find package "." in:
        /build/source/vendor/github.com/therecipe/env_linux_amd64_513

To Reproduce
run nix-build on the attached default.nix file with the gomod2nix.toml in the same directory. Nix fails to build the cmd/env subpackage.

default.nix and gomod2nix.toml files

default.nix:

let
  pkgs = import <nixpkgs> {};

  gomod2nixSrc = pkgs.fetchFromGitHub {
    owner = "tweag";
    repo = "gomod2nix";
    rev = "67f22dd738d092c6ba88e420350ada0ed4992ae8";
    sha256 = "0a9rhw6djgcrky5nzly3srsl8095q42f2nyzxyisp9fh9fg70nih";
  };
  buildGoApplication = pkgs.callPackage "${gomod2nixSrc}/builder/default.nix" {};

  goqtSource = pkgs.fetchFromGitHub {
    owner = "therecipe";
    repo = "qt";
    rev = "c0c124a5770d357908f16fa57e0aa0ec6ccd3f91";
    sha256 = "197wdh2v0g5g2dpb1gcd5gp0g4wqzip34cawisvy6z7mygmsc8rd";
  };

  goqtToml = ./gomod2nix.toml;

  goqt = buildGoApplication rec {
    pname = "go-qt";
    version = "c0c124a5770d357908f16fa57e0aa0ec6ccd3f91";
    src = goqtSource;
    modules = goqtToml;
  };
in
  goqt

gomod2nix.toml:

["github.com/davecgh/go-spew"]
  sumVersion = "v1.1.1"
  ["github.com/davecgh/go-spew".fetch]
    type = "git"
    url = "https://github.com/davecgh/go-spew"
    rev = "8991bc29aa16c548c550c7ff78260e27b9ab7c73"
    sha256 = "0hka6hmyvp701adzag2g26cxdj47g21x6jz4sc6jjz1mn59d474y"

["github.com/gopherjs/gopherjs"]
  sumVersion = "v0.0.0-20190411002643-bd77b112433e"
  ["github.com/gopherjs/gopherjs".fetch]
    type = "git"
    url = "https://github.com/gopherjs/gopherjs"
    rev = "bd77b112433e999447bf4bc599e36214ba494a99"
    sha256 = "0bsj69jb0glfvqhqld4c78840iagd0iy2b92878i5w4sgp40k7i1"

["github.com/konsorten/go-windows-terminal-sequences"]
  sumVersion = "v1.0.2"
  ["github.com/konsorten/go-windows-terminal-sequences".fetch]
    type = "git"
    url = "https://github.com/konsorten/go-windows-terminal-sequences"
    rev = "f55edac94c9bbba5d6182a4be46d86a2c9b5b50e"
    sha256 = "09mn209ika7ciy87xf2x31dq5fnqw39jidgaljvmqxwk7ff1hnx7"

["github.com/pmezard/go-difflib"]
  sumVersion = "v1.0.0"
  ["github.com/pmezard/go-difflib".fetch]
    type = "git"
    url = "https://github.com/pmezard/go-difflib"
    rev = "792786c7400a136282c1664665ae0a8db921c6c2"
    sha256 = "0c1cn55m4rypmscgf0rrb88pn58j3ysvc2d0432dp3c6fqg6cnzw"

["github.com/sirupsen/logrus"]
  sumVersion = "v1.4.1"
  ["github.com/sirupsen/logrus".fetch]
    type = "git"
    url = "https://github.com/sirupsen/logrus"
    rev = "8bdbc7bcc01dcbb8ec23dc8a28e332258d25251f"
    sha256 = "1m7ny9jkb98cxqhsp13xa5hnqh1s9f25x04q6arsala4zswsw33c"

["github.com/stretchr/objx"]
  sumVersion = "v0.2.0"
  ["github.com/stretchr/objx".fetch]
    type = "git"
    url = "https://github.com/stretchr/objx"
    rev = "ea4fe68685ee0d3cee7032121851b57e7494e8ea"
    sha256 = "0pcdvakxgddaiwcdj73ra4da05a3q4cgwbpm2w75ycq4kzv8ij8k"

["github.com/stretchr/testify"]
  sumVersion = "v1.3.0"
  ["github.com/stretchr/testify".fetch]
    type = "git"
    url = "https://github.com/stretchr/testify"
    rev = "ffdc059bfe9ce6a4e144ba849dbedead332c6053"
    sha256 = "0wjchp2c8xbgcbbq32w3kvblk6q6yn533g78nxl6iskq6y95lxsy"

["golang.org/x/crypto"]
  sumVersion = "v0.0.0-20190418165655-df01cb2cc480"
  vendorPath = "github.com/golang/crypto"
  ["golang.org/x/crypto".fetch]
    type = "git"
    url = "https://github.com/golang/crypto"
    rev = "df01cb2cc480549d72034218dd98bf97671450ac"
    sha256 = "1fhz0rym06j0fds0wg8xf6i9mm37m6qgdv83qxfh3nh0mgzf19qs"

["golang.org/x/net"]
  sumVersion = "v0.0.0-20190420063019-afa5a82059c6"
  vendorPath = "github.com/golang/net"
  ["golang.org/x/net".fetch]
    type = "git"
    url = "https://github.com/golang/net"
    rev = "afa5a82059c6356159f699d81beff22a81842231"
    sha256 = "1zhcr1m7n550m0lqjqg1rl2qrnghkl3a25vcm6cgpiqvk89f8lba"

["golang.org/x/sys"]
  sumVersion = "v0.0.0-20190419153524-e8e3143a4f4a"
  vendorPath = "github.com/golang/sys"
  ["golang.org/x/sys".fetch]
    type = "git"
    url = "https://github.com/golang/sys"
    rev = "e8e3143a4f4a00f1fafef0dd82ba78223281b01b"
    sha256 = "02pdj4gr658r99kqwxy6v4lb8w2h0zaiqq1jyqrsxqiyapijhw87"

["golang.org/x/text"]
  sumVersion = "v0.3.1-0.20190410012825-f4905fbd45b6"
  vendorPath = "github.com/golang/text"
  ["golang.org/x/text".fetch]
    type = "git"
    url = "https://github.com/golang/text"
    rev = "f4905fbd45b6790792202848439271c74074bbfd"
    sha256 = "184d6ap2g92jvx0532lymdqbnx9vi9ips4dq5lnqbby0caccc6r1"

["golang.org/x/tools"]
  sumVersion = "v0.0.0-20190420181800-aa740d480789"
  vendorPath = "github.com/golang/tools"
  ["golang.org/x/tools".fetch]
    type = "git"
    url = "https://github.com/golang/tools"
    rev = "aa740d4807891cb493e9f727901baf334b9fabce"
    sha256 = "0431y2xw39dss0ldxhbmm7ip4d2cr2w9km2a5psgwan6v481kz0a"

Expected behavior
The package should build correctly.

Environment

  • OS name + version: Nixos unstable
  • Version of the code: 67f22dd (lastest commit)

Additional context
I have basically no experience with golang and even less packaging it with nix. I tried using the nixpkgs buildGoModule function but that didn't work in other ways. Some Googling led me to this package which appears to make it further in the process but still fails. The goal is to build https://github.com/akiyosi/goneovim which depends on the qt bindings.

The qt package seems to be pretty large and complicated so I'm not sure how to begin to debug this.

x509: OSStatus -26276

This is a x-post from peterldowns/nix-search-cli#7 (comment) and as suggested, I am reporting a problem here

I'm getting this on my machine

❯ nix run github:peterldowns/nix-search-cli -- --help
error: builder for '/nix/store/d3b79195anc6303dpdjr480qv0bnslfk-ansi-escapes_v0.2.0.drv' failed with exit code 1;
       last 1 log lines:
       > go: github.com/snugfox/[email protected]: Get "https://proxy.golang.org/github.com/snugfox/ansi-escapes/@v/v0.2.0.info": x509: OSStatus -26276
       For full logs, run 'nix log /nix/store/d3b79195anc6303dpdjr480qv0bnslfk-ansi-escapes_v0.2.0.drv'.
error: 1 dependencies of derivation '/nix/store/dwin1bmf0vk3w3km072vnfc493a99n29-vendor-env.drv' failed to build
error: 1 dependencies of derivation '/nix/store/0cb3mpass027908fc3fw9c1rnvpr7wxs-nix-search-cli-0.0.4.drv' failed to build

MacOS 13.2.1 (22D68)
nix (Nix) 2.13.2

Build error, vendor/modules.txt not found

Describe the bug
Failed to build gomod2nix itself with nix.

To Reproduce
In this repo:

$ nix-shell
$ nix repl
nix-repl> pkgs = import <nixpkgs> { overlays = [(import ./overlay.nix)]; }
nix-repl> :b pkgs.gomod2nix
builder for '/nix/store/pdnfnmdr4b8ldyhha2yvvsmdwi8cwg3c-gomod2nix-0.1.drv' failed with exit code 1; last 10 log lines:
  building
  Building subPackage ./.
  go: inconsistent vendoring in /private/tmp/nix-build-gomod2nix-0.1.drv-0/source:
        github.com/BurntSushi/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
          github.com/orivej/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
        github.com/sirupsen/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
          golang.org/x/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
    golang.org/x/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt

  run 'go mod vendor' to sync, or use -mod=mod or -mod=readonly to ignore the vendor directory
[1 built (1 failed), 1 copied (0.0 MiB), 0.0 MiB DL]
error: build of '/nix/store/pdnfnmdr4b8ldyhha2yvvsmdwi8cwg3c-gomod2nix-0.1.drv' failed

Expected behavior
Build success

Environment

  • macosx Big Sur
  • Version of the code: master

Undefined entities in vendor

Describe the bug
When I try to build terra core I am getting this error:

github.com/CosmWasm/wasmvm/api
# github.com/CosmWasm/wasmvm/api
vendor/github.com/CosmWasm/wasmvm/api/mock_failure.go:15:27: undefined: GoAPI
vendor/github.com/CosmWasm/wasmvm/api/mocks.go:192:2: undefined: GasMeter
vendor/github.com/CosmWasm/wasmvm/api/mocks.go:193:20: undefined: Gas

The issue seems to be that certain entities are undefined? But the github UI intellisense suggests that they are. Is it possible that there is some issue with dependency resolution?

To Reproduce
I created a repro repo here. You should just have to run nix build to get the error. Since the repo is a flake you can just run nix build github:JonathanLorimer/gomod-repro-2 without even cloning the repo.

Expected behavior
I expected this module to build without errors

Environment

  • OS name + version: NixOS 21.11 (Porcupine) x86_64
  • Version of the code: 67f22dd738d092c6ba88e420350ada0ed4992ae8

Additional context
I have very limited golang knowledge so there might be something completely wrong with the go side of things and I am just missing it. Thank you for your help in advance!

Cannot find package "." in

Describe the bug
gomod2nix seems to struggle with go dependencies that are part of the repo and referenced by relative paths. When I try and package regen-network I am getting this error:

app/app.go:10:2: cannot find package "." in:
        /build/source/vendor/github.com/regen-network/regen-ledger/types/module
app/app.go:95:2: cannot find package "." in:
        /build/source/vendor/github.com/regen-network/regen-ledger/types/module/server
app/app.go:96:2: cannot find package "." in:
        /build/source/vendor/github.com/regen-network/regen-ledger/x/ecocredit
app/app.go:11:2: cannot find package "." in:
        /build/source/vendor/github.com/regen-network/regen-ledger/x/ecocredit/module

The issue seems to be with these dependencies. The relevant error sites are listed below:

I also think that this has something to do with the local replace directives here
To Reproduce
I created a repro repo here. You should just have to run nix build to get the error. Since the repo is a flake you can just run nix build github:JonathanLorimer/gomod-repro-1 without even cloning the repo.

Expected behavior
I expected this module to build without errors

Environment

  • OS name + version: NixOS 21.11 (Porcupine) x86_64
  • Version of the code: 67f22dd738d092c6ba88e420350ada0ed4992ae8

Additional context
I have very limited golang knowledge so there might be something completely wrong with the go side of things and I am just missing it. Thank you for your help in advance!

cross compiling don't work

gomod2nix will pick a go version if the go parameter is missing, but that don't work with cross compiling. After specify go explicitly in buildGoApplication, it works.

/nix/store/zggnfyiminnmwz85y4z7wliq0b41lrax-go-x86_64-unknown-linux-gnu-1.18.4/bin/go: cannot execute binary file: Exec format error

The error seems suggest it runs the host version compiler.

Make `mkVendorEnv` generate `modules.txt`

So to my understanding, this package emulates go mod vendor. However, in order to use the vendor directory with buildGoModule (see #116), the modules.txt file is required:

go: inconsistent vendoring in /build/source:
    github.com/adrg/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
    github.com/alecthomas/chroma/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
 ...

A build failure message is ignored

Describe the bug
A failed build message is ignored and build an empty package.

package github.com/crypto-org-chain/cronos/cmd/cronosd
        imports github.com/crypto-org-chain/cronos/app
        imports github.com/crypto-org-chain/cronos/x/cronos/rpc
        imports github.com/tharsis/ethermint/rpc
        imports github.com/tharsis/ethermint/rpc/namespaces/ethereum/eth
        imports github.com/tharsis/ethermint/crypto/hd
        imports github.com/btcsuite/btcd/chaincfg: no Go files in /private/tmp/nix-build-cronosd-v0.7.0.drv-0/nd692855262djv1xsd7yq7iimlqcgsan-source/vendor/github.com/btcsuite/btcd/chaincfg

The no Go files matches the re, cause the error ignored.

To Reproduce
Steps to reproduce the behavior.

Expected behavior
A clear and concise description of what you expected to happen.

Environment

  • OS name + version:
  • Version of the code:

Additional context
Add any other context about the problem here.

Prefetch Go package

Is your feature request related to a problem? Please describe.
I would like to have one command to prefetch a Go package and generate whatever metadata I need to build it with a static Nix expression. Go doesn't expose how it resolves package paths to the command line, so any solution to fetch the VCS repo corresponding to a Go package needs to happen in Go anyway, so it might as well live in gomod2nix.

Describe the solution you'd like
I've added a -prefetch path[@version] option (PR incoming) which fetches the corresponding package repo before running the rest of gomod2nix.

Describe alternatives you've considered
I considered writing another tool that resolves Go modules to repository roots and calls gomod2nix functions, but I figured this would be useful in gomod2nix itself.

Build is not reproducible

Describe the bug
After migrated to gomod2nix, builing is not reproducible anymore.

To Reproduce
Clone and switch to this branch: https://github.com/yihuang/chain-main/tree/gomod2nix

$ nix-build -A chain-maind

Run that command again, it'll rebuild, and the output hash is different.

Expected behavior

Build again should not change the output hash and reuse the built cache.

Environment

Additional context
Add any other context about the problem here.

Question How to use this on non-flakes system ?

Is your feature request related to a problem? Please describe.
I want to build https://github.com/mickael-menu/zk via gomod2nix.
First problem was how to get the gomod2nix binary.
When I had a nix-shell running with gomod2nix finally I wanted to utilize the generated gomod2nix.toml in my checkout of zk.
Latter which fails as I am not able to utilize the overlay correctly, in terms of as the README here says.

Describe the solution you'd like
It would like to bind the overlay here in my zk checkout's default.nix such that nix-build can be satisfied.

Describe alternatives you've considered
This is the default.nix I'm using (nix-build it):

let
  pkgs = import <nixpkgs> {
    overlays = [
      (self: super: {
        buildGoApplication = pkgs.callPackage (builtins.fetchTarball {
          url =  https://github.com/tweag/gomod2nix/archive/67f22dd738d092c6ba88e420350ada0ed4992ae8.tar.gz;
          sha256 = "0a9rhw6djgcrky5nzly3srsl8095q42f2nyzxyisp9fh9fg70nih";
        }) {};
      })
    ];
  };
in pkgs.buildGoApplication {
  pname = "zk";
  version = "master";
  src = ./.;
  modules = ./gomod2nix.toml;
}

Additional context
Regarding the gomod2nix binary I started a nix-shell of https://github.com/GTrunSec/photoprism2nix and added buildInputs = [ pkgs.gomod2nix ]; to devShell there in the flake.nix file. In the nix-shell started I can use gomod2nix.

Unclear documentation

Describe the bug
The sample nix code in the README.md is without context. Is this a default.nix? Is this a shell.nix? Is this to be pasted into one's configuration.nix? I've been using Nix for almost a year now, but I still had to dig through the Issues here to find a complete (albeit breaking) example of how one might use this in situ to create a default.nix for an arbitrary Go project on github. (Thank you #18)

To Reproduce
Be new to Nix and attempt to understand what it is one is looking at here :)

Expected behavior
A clear and concise description of what this is, how it works, why it's necessary, and compare/contrast with other build tooling the user might already know. E.g. https://github.com/DavHau/nix-pypi-fetcher is the only other not-included-by-default build tool I've used; other people will come to this with other context; help ease us in to your paradigm. Work with us here :)

Environment
NixOS 21.05 + a bunch of unstable packages

  • Version of the code:67f22dd738d092c6ba88e420350ada0ed4992ae8

Additional context
Thank you nonetheless for this fantastic contribution to Nix and NixOS.

Breaks vendoring github.com/Azure/go-autorest/autorest/azure

Describe the bug

sops-install-secrets>   imports github.com/Azure/go-autorest/autorest/azure: no Go files in /build/vdmnln67rk3dnfybrb91ny9azi6n2fqf-source/vendor/github.com/Azure/go-autorest/autorest/azure

also see https://github.com/Mic92/sops-nix/pull/101/checks?check_run_id=2978436662#step:6:33

To Reproduce

Build sops-nix: (nix build --no-link .#unit-tests -L here: https://github.com/Mic92/sops-nix)

Expected behavior

Environment

  • OS name + version: linux
  • Version of the code: latest

Additional context
Add any other context about the problem here.

How to get gomod2nix on nox-flake setups ?

Is your feature request related to a problem? Please describe.
If I want to generate a gomod2nix.toml file on systems that are not flake-enabled I currently use a binary generated by starting a nix-shell of https://github.com/GTrunSec/photoprism2nix after adding buildInputs = [ pkgs.gomod2nix ]; to their flake.nix file (devShell = mkShell { buildInputs = [ pkgs.gomod2nix ]; (...)). This is tedious.

Describe the solution you'd like
It would be cool to just nix-shell in a checkout of https://github.com/tweag/gomod2nix to achieve this.

Describe alternatives you've considered
I have tried to run a nix-shell of https://github.com/tweag/gomod2nix already but this gave me no gomod2nix binary.

When will this be considered stable and hit nixpkgs?

The current situation is a bit sketchy, there is buildGoModule, which is not ideal and for good reason and then vgo2nix which seems to have gone unmaintained and its infrastructure in nixpkgs. Then this project, which unfortunately isn't yet in nixpkgs and requires its users to pull in another dependency. What are the blockers for this to get upstreamed, preferably before the next nixpkgs release.

Does not symlink modules with overlapping paths

Suppose a go.mod contains:

require (
    repo/foo v1.0.0
    repo/foo/bar v1.0.0
)

then go mod will store the directory structure:

go
└── pkg
    └── mod
        └── repo
            ├── foo
            │   └── bar
            └── [email protected]

so that repo/foo v1.0.0 is installed under go/pkg/mod/repo/[email protected] to avoid conflicts.

However when gomod2nix creates the vendor-env derivation it seems to be only linking the longest path, in this case repo/foo/bar.

Discovered with go.opentelemetry.io/otel and related packages.

Build failure with opentelemetry dependency: cannot find package "."

Hi, first off big fan of your work and thank you for making a much nicer way to build go binaries. So much nicer as a developer than having to figure out the current SHA all the time :)

I recently encountered an issue where gomod2nix seems to result in a build failure when I import a specific dependency, go.opentelemetry.io/otel/exporters/otlp/otlptrace. The build failure is as follows:

$ nix build .
warning: Git tree '/Users/pd/code/gomod2nix-failure-repro' is dirty
error: builder for '/nix/store/92rq9r8nv8nhpdl0z9dnic98hhizmw4y-demo-0.0.1.drv' failed with exit code 1;
       last 10 log lines:
       > unpacking sources
       > unpacking source archive /nix/store/x5s2b55ans4iz9alw39n3zw95bp2515g-1bgxmfm63niqndrby5yxqb55dlm97ncz-source
       > source root is 1bgxmfm63niqndrby5yxqb55dlm97ncz-source
       > patching sources
       > updateAutotoolsGnuConfigScriptsPhase
       > configuring
       > building
       > Building subPackage .
       > vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/exporter.go:22:2: cannot find package "." in:
       > 	/private/tmp/nix-build-demo-0.0.1.drv-0/1bgxmfm63niqndrby5yxqb55dlm97ncz-source/vendor/go.opentelemetry.io/otel/exporters/otlp/internal
       For full logs, run 'nix log /nix/store/92rq9r8nv8nhpdl0z9dnic98hhizmw4y-demo-0.0.1.drv'.
$ nix log /nix/store/92rq9r8nv8nhpdl0z9dnic98hhizmw4y-demo-0.0.1.drv
@nix { "action": "setPhase", "phase": "unpackPhase" }
unpacking sources
unpacking source archive /nix/store/x5s2b55ans4iz9alw39n3zw95bp2515g-1bgxmfm63niqndrby5yxqb55dlm97ncz-source
source root is 1bgxmfm63niqndrby5yxqb55dlm97ncz-source
@nix { "action": "setPhase", "phase": "patchPhase" }
patching sources
@nix { "action": "setPhase", "phase": "updateAutotoolsGnuConfigScriptsPhase" }
updateAutotoolsGnuConfigScriptsPhase
@nix { "action": "setPhase", "phase": "configurePhase" }
configuring
@nix { "action": "setPhase", "phase": "buildPhase" }
building
Building subPackage .
vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/exporter.go:22:2: cannot find package "." in:
        /private/tmp/nix-build-demo-0.0.1.drv-0/1bgxmfm63niqndrby5yxqb55dlm97ncz-source/vendor/go.opentelemetry.io/otel/exporters/otlp/internal

The opentelemetry project / packages are quite complex and involve URLs that don't match the resolved package names, complicated versioning, etc. Here are some helpful links:

In order to make this easier to debug, here is a repository with full information on the problem and steps to repro. I hope it helps. If you could even give me some advice on how to debug this sort of thing, I'm happy to try to learn.

`nix build` hangs on `Building subPackage .`

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.

`gomod2nix` triggers "too many open files" error

Describe the bug

It triggers panic: fcntl /.../[email protected]: too many open files error. I guess because the new version generate lots of coroutines simultaneously which opens lots of files at the same time.

To Reproduce
run gomod2nix on a relatively large project.

Expected behavior
It would be good to work under the default ulimit.

Environment

  • OS name + version: macOS
  • Version of the code: master

Additional context
Add any other context about the problem here.

zsh: command not found: gomod2nix

Quick question here, as I'm new to this tool and Nix.

I followed the instructions to set up the tool like this:

nix flake init -t github:tweag/gomod2nix#app
nix develop # (also tried nix shell)
nix build
go get github.com/mattn/go-sqlite3
gomod2nix

But even though I've opened the dev environment, it's not finding gomod2nix in my path.

Can anyone point me to a way of troubleshooting this?

Here's the output of nix flake metadata

Resolved URL:  git+file:///Users/erikc96/Projects/golang/nix
Locked URL:    git+file:///Users/erick96/Projects/golang/nix?ref=refs%2fheads%2fmain&rev=cb3bdd84986c85a2d0e52bd7e53efabafc57b967
Description:   A basic gomod2nix flake
Path:          /nix/store/q645qa21ynhxmfl949ymrpmbc9wzwi6l-source
Revision:      cb3bdd84986c85a2d0e52bd7e53efabafc57b967
Revisions:     1
Last modified: 2022-12-14 20:47:30
Inputs:
├───flake-utils: github:numtide/flake-utils/5aed5285a952e0b949eb3ba02c12fa4fcfef535f
├───gomod2nix: github:nix-community/gomod2nix/89cd0675b96775aa3ee86e7c0cf5bc238dd27976
│   ├───nixpkgs: github:NixOS/nixpkgs/5342fc6fb59d0595d26883c3cadff16ce58e44f3
│   └───utils: github:numtide/flake-utils/1ed9fb1935d260de5fe1c2f7ee0ebaae17ed2fa1
└───nixpkgs: github:NixOS/nixpkgs/1710ed1f6f8ceb75cf7d1cf55ee0cc21760e1c7a

Edit:

I have the same issue if I go the niv route.

`gomod2nix generate` fails

Describe the bug
gomod2nix generate or gomod2nix import fails when Prometheus go client is in dependencies.

To Reproduce

nix flake init -t github:tweag/gomod2nix#app
go get github.com/prometheus/client_golang
gomod2nix generate

Expected behavior
gomod2nix.toml is expected to be generated/

Environment

  • OS name + version: NixOS 22.05
  • Version of the code: latest

Additional context
Output:

INFO[0000] Parsing go.mod                                modPath=go.mod
INFO[0000] Downloading dependencies
panic: error generating pkgs: exit status 1

goroutine 1 [running]:
github.com/tweag/gomod2nix/internal/cmd.generateFunc(0xafd160, {0xb333e0, 0x0, 0x0})
	/build/source/internal/cmd/root.go:67 +0x416
github.com/spf13/cobra.(*Command).execute(0xafd160, {0xb333e0, 0x0, 0x0})
	/build/source/vendor/github.com/spf13/cobra/command.go:860 +0x5f8
github.com/spf13/cobra.(*Command).ExecuteC(0xafcee0)
	/build/source/vendor/github.com/spf13/cobra/command.go:974 +0x3bc
github.com/spf13/cobra.(*Command).Execute(...)
	/build/source/vendor/github.com/spf13/cobra/command.go:902
github.com/tweag/gomod2nix/internal/cmd.Execute()
	/build/source/internal/cmd/root.go:124 +0x25
main.main()
	/build/source/main.go:6 +0x17

Design assumption / dependency graph

The blog post introducing gomod2nix states:

After squinting at these files for a while we can already see some radical differences in semantics, most notably that go.sum is structured as a flat list rather than a graph. Of course, all dependencies to the build are listed in go.sum, but we don’t know what depends on what. What this means for us in Nix is that we have no good unit of incrementality — everything has to be built together — while Poetry can build dependencies separately.

Would the output of go mod graph suffice? (https://go.dev/ref/mod#go-mod-graph) E.g.,

git clone https://github.com/benbjohnson/tmpl
cd tmpl
go mod graph

Outputs:

➜  tmpl git:(master) go mod graph
github.com/benbjohnson/tmpl github.com/Masterminds/[email protected]
github.com/benbjohnson/tmpl github.com/Masterminds/[email protected]
github.com/benbjohnson/tmpl github.com/Masterminds/[email protected]+incompatible
github.com/benbjohnson/tmpl github.com/dustin/[email protected]
github.com/benbjohnson/tmpl github.com/google/[email protected]
github.com/benbjohnson/tmpl github.com/huandu/[email protected]
github.com/benbjohnson/tmpl github.com/imdario/[email protected]
github.com/benbjohnson/tmpl github.com/mitchellh/[email protected]
github.com/benbjohnson/tmpl github.com/stretchr/[email protected]
github.com/benbjohnson/tmpl golang.org/x/[email protected]
github.com/imdario/[email protected] gopkg.in/[email protected]
github.com/mitchellh/[email protected] github.com/mitchellh/[email protected]
github.com/stretchr/[email protected] github.com/davecgh/[email protected]
github.com/stretchr/[email protected] github.com/pmezard/[email protected]
github.com/stretchr/[email protected] github.com/stretchr/[email protected]
github.com/stretchr/[email protected] gopkg.in/[email protected]
golang.org/x/[email protected] golang.org/x/[email protected]
golang.org/x/[email protected] golang.org/x/[email protected]
golang.org/x/[email protected] golang.org/x/[email protected]
gopkg.in/[email protected] gopkg.in/[email protected]
gopkg.in/[email protected] gopkg.in/[email protected]
golang.org/x/[email protected] golang.org/x/[email protected]
golang.org/x/[email protected] golang.org/x/[email protected]
golang.org/x/[email protected] golang.org/x/[email protected]
golang.org/x/[email protected] golang.org/x/[email protected]
golang.org/x/[email protected] golang.org/x/[email protected]

Relative path modules are not vendored

To Reproduce
Replace a module to relative path in go.mod like this:

replace github.com/owner/package => ./third_party/package

Then build with gomod2nix and nix, the package is not in the vendor directory, thus go build fails.

Expected behavior
The package should be in the vendor directory, and build success.

Go Workspace guidance

Hi, I know they're a relatively new feature, but how does gomod2nix interact with Go workspaces. Are there any examples available for how to set up workspaces with gomod2nix?

Building with a private dependency

Not sure if this is a bug, or perhaps it's just advice needed.

I have problem with building a project that contains a private dependency. It appears to be slightly different problem than described in #3.

After gomod2nix asked me for credentials I just entered it and it did its job, but when I'm trying to build and that dependency came up this is what I got:

exporting https://gitlab.<snip>/<snip>/go-commons (rev 0b8910c77d4eac6c27ef7024e7596bfcfa07feff) into /nix/store/1348m1ip818a03dj49d4ljv5qm14rj7g-go-commons-0b8910c
Initialized empty Git repository in /nix/store/1348m1ip818a03dj49d4ljv5qm14rj7g-go-commons-0b8910c/.git/
fatal: could not read Username for 'https://gitlab.<snip>': Device not configured
fatal: could not read Username for 'https://gitlab.<snip>': Device not configured
fatal: could not read Username for 'https://gitlab.<snip>': Device not configured
Unable to checkout 0b8910c77d4eac6c27ef7024e7596bfcfa07feff from https://gitlab.<snip>/<snip>/go-commons.

Is there a way to let me compile to project? During build I don't even have an opportunity to enter credentials. Of course saved credentials as well like using insteadOf in git configuration don't work.

mkGoEnv: different locations for `tools.go` and `go.mod/sum`?

Thanks for the excellent work you've done here! I'm especially interested in the mkGoEnv / tools.go pattern for providing Go tooling via Nix that's clamped to the go.sum.

I've been looking through the code tonight to see if it would be suitable for a monorepo I work in that shares a single go.mod but has many subfolders each with their own shell.nix/tools.go that want to utilise a subset of the go.mod to put some Go-based tools on the developer's path.

I was wondering:

  • Is there a way to provide a different location from pwd for the tools.go during mkGoEnv that I missed?
  • Will mkGoEnv always build everything in the go.mod even if the tools.go only references a tiny subset of import _ <gitforge>/<user>/<blahprj>/cmd/<blah>

Pass tags to go build?

I've searched the previous issues for "build tags" and couldn't find anything.
I have a project with go-sqlite3, and I require the 'sqlite_math_functions' tag.
I usually add --tags sqlite_math_functions to go build, how do I do so
using buildGoApplication in my nix flake?

Fetcher does not account for branch names

Describe the bug
You can use branch names in go.mod files, but gomod2nix only looks for tags

I have a very simple solution here but I am not sure if this will cause other issues (I don't have that much experience with go and how it manages dependencies).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.