Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gomod2nix generate results in error path is not valid #72

Open
storvik opened this issue Aug 16, 2022 · 5 comments · May be fixed by #105
Open

gomod2nix generate results in error path is not valid #72

storvik opened this issue Aug 16, 2022 · 5 comments · May be fixed by #105

Comments

@storvik
Copy link

storvik commented Aug 16, 2022

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.

@jgresty
Copy link

jgresty commented Sep 21, 2022

Oddly the expression evaluates perfectly fine in a nix repl, I wish nix-instantiate would give useful errors...

@jjthiessen
Copy link

jjthiessen commented Feb 13, 2023

I'm having the same issues. It seems to affect not only all private repos, but also public ones where the module ref doesn't correspond to a released version (updating to a given commit or branch — e.g., go get example.net/fake/mod@branch).

For example, I'm getting this (upon gomod2nix import) in one of my projects:

INFO[0000] Importing sources                             goPackagePath=golang.org/x/oauth2
error: path '/nix/store/m5x1qfq4yqdn8zyx4gm4z12m112mmj9b-oauth2_v0.0.0-20220411215720-9780585627b5' is not valid
(use '--show-trace' to show detailed location information)
/run/current-system/sw/bin/nix-instantiate --eval --expr 
builtins.filterSource (name: type: baseNameOf name != ".DS_Store") (
  builtins.path {
    path = "/home/jt/go/pkg/mod/golang.org/x/[email protected]";
    name = "oauth2_v0.0.0-20220411215720-9780585627b5";
  }
)

Like @jgresty said, running it in nix repl works (and, moreover, resolves the issue for future invocations).
Another way around it is to run nix-instantiate without --eval first, like so (original+show-trace, no eval+show-trace, original+show-trace):

$ /run/current-system/sw/bin/nix-instantiate --eval --expr 'builtins.filterSource (name: type: baseNameOf name != ".DS_Store") (
  builtins.path {
    path = "/home/jt/go/pkg/mod/golang.org/x/[email protected]";
    name = "oauth2_v0.0.0-20220411215720-9780585627b5";
  }
)' --show-trace
error: path '/nix/store/m5x1qfq4yqdn8zyx4gm4z12m112mmj9b-oauth2_v0.0.0-20220411215720-9780585627b5' is not valid

       … while adding path '/nix/store/m5x1qfq4yqdn8zyx4gm4z12m112mmj9b-oauth2_v0.0.0-20220411215720-9780585627b5'

       at «string»:1:1:

            1| builtins.filterSource (name: type: baseNameOf name != ".DS_Store") (
             | ^
            2|   builtins.path {
$ /run/current-system/sw/bin/nix-instantiate --expr 'builtins.filterSource (name: type: baseNameOf name != ".DS_Store") (
  builtins.path {
    path = "/home/jt/go/pkg/mod/golang.org/x/[email protected]";
    name = "oauth2_v0.0.0-20220411215720-9780585627b5";
  }
)' --show-trace
error: expression does not evaluate to a derivation (or a set or list of those)
$ /run/current-system/sw/bin/nix-instantiate --eval --expr 'builtins.filterSource (name: type: baseNameOf name != ".DS_Store") (
  builtins.path {
    path = "/home/jt/go/pkg/mod/golang.org/x/[email protected]";
    name = "oauth2_v0.0.0-20220411215720-9780585627b5";
  }
)' --show-trace
"/nix/store/c7z9bm9qzashlcqiv5v2jwcch6gq2hwv-m5x1qfq4yqdn8zyx4gm4z12m112mmj9b-oauth2_v0.0.0-20220411215720-9780585627b5"

I haven't looked at the gomod2nix import code, but I imagine it wouldn't be too difficult to update it to make it work (I'm not sure whether it can be done in a single invocation of nix-instantiate, or not, or even whether it's better to run something else here).

🤷

@jjthiessen
Copy link

I just noticed that I'm also getting

error: path '/nix/store/mqn6p2m3qvzqwan59c3xlyvjxgjjhyhy-sys_v0.1.0' is not valid
(use '--show-trace' to show detailed location information)
/run/current-system/sw/bin/nix-instantiate --eval --expr 
builtins.filterSource (name: type: baseNameOf name != ".DS_Store") (
  builtins.path {
    path = "/home/jt/go/pkg/mod/golang.org/x/[email protected]";
    name = "sys_v0.1.0";
  }
)

so I'm guessing that it's actually more general/not specific to the handling of private or untagged module versions.

@jjthiessen
Copy link

jjthiessen commented Feb 13, 2023

It looks like nix eval --impure --expr ... would be a suitable replacement (but would require a semi-recent nix version — OTOH, it would work).

@jjthiessen
Copy link

@storvik, I should probably have reread your original issue description before trying to add my own notes/comments. I just reread now and saw where you said (only three sentences in, even) that it wasn't specific to private (or untagged) repos (and refs), but I already came here having discovered the same issue from working with private modules, and just latched on to that instead.

Still, either using nix eval --impure --expr ... or nix-instantiate --expr ...; nix-instantiate --eval --expr ... should work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants