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

go-modules/generic: add missing PATHs to GOPATH when using nix-shell #26176

Merged
merged 1 commit into from
Jun 1, 2017

Conversation

qknight
Copy link
Member

@qknight qknight commented May 28, 2017

Motivation for this change

using nix-shell for hacking on my go project is nice but after hours of debugging i found that two GOPATHS would always be missing:

  • PWD
  • extraSrcPaths

this PR fixes it by adding both into GOPATH when using nix-shell.

i've tested it with nixcloud-backend and it works nicely. also, using nix-build instead of nix-shell is not affected from this change at all.

Things done
  • Tested using sandboxing
    (nix.useSandbox on NixOS,
    or option build-use-sandbox in nix.conf
    on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • Linux
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Fits CONTRIBUTING.md.

@mention-bot
Copy link

@qknight, thanks for your PR! By analyzing the history of the files in this pull request, we identified @wkennington, @ehmry and @lethalman to be potential reviewers.

@@ -198,7 +198,7 @@ go.stdenv.mkDerivation (
ln -s "${dep.src}" "$d/src/${dep.goPackagePath}"
''
) goPath) + ''
export GOPATH="$d:$GOPATH"
export GOPATH=${lib.concatStringsSep ":" ( ["$d"] ++ ["$GOPATH"] ++ ["$PWD"] ++ extraSrcPaths)}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is PWD here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(12:47) <  qknight_> if 'go build' yields: cannot find package "nixcloud/backend/root" in any of and my project is src/nixcloud/backends then i simply lack a entry in GOPATH with the absolute path to the 
                     parent of 'src', right?
(12:47) <  qknight_> because if i add this, it compiles
(12:47) -!- Poky [~michal@ip-89-177-75-53.net.upcbroadband.cz] has quit [Ping timeout: 268 seconds]
(12:48) <  qknight_> so that said, the project root must always be part of the GOPATH or is that wrong?
(12:48) -!- mperillo [~mperillo@host169-59-dynamic.43-79-r.retail.telecomitalia.it] has joined #go-nuts
(12:48) <      acln> qknight_: that is correct, all of your Go code usually lives under GOPATH.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually this is up to the user to set this and people might have different opinions how they organize their GOPATH.
Some may create one GOPATH per project others might use one global GOPATH for all go code (https://github.com/golang/go/wiki/GOPATH#use-a-single-gopath).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zimbatm might also have an opinion on that.

Copy link
Member Author

@qknight qknight May 29, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Mic92
do you think your usecase your one global GOPATH fits the concept of using nix-shell? isn't nix-shell usually used an a 'per project' basis?

the shellHook is only used for nix-shell on interactive shells for hacking and not for nix-build like scenarios.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't that a vendor/ use case? Like for example https://github.com/hashicorp/consul/tree/master/vendor ?

Copy link
Member

@zimbatm zimbatm Jun 1, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@qknight all my go projects are checked out inside of $GOPATH, that's what most go projects assume.

To be fair it sucks, I don't think that a project should be influencing anything external to it's repository. This and vendor/ all the project dependencies.

Copy link
Member

@Mic92 Mic92 Jun 1, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@qknight After thinking about it, it is a sane default. If someone would have a GOPATH set, it would still do things as before. Otherwise it writes to the nix-shell invocation directory.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kamilchm also ok with this PR? if so i will merge it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's do it. You can't break Go dependency resolution more :/
It will have even more corner cases with Go 1.8 https://beta.golang.org/doc/go1.8#gopath

@qknight qknight merged commit f30dd71 into NixOS:master Jun 1, 2017
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 this pull request may close these issues.

None yet

5 participants