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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

echoip: Init at unstable-2018-11-20 #50965

Closed
wants to merge 1 commit into from

Conversation

rvolosatovs
Copy link
Member

@rvolosatovs rvolosatovs commented Nov 23, 2018

Motivation for this change

The power behind https://ifconfig.co now in nixpkgs 馃帀
The project uses go modules - I did not find an automated solution to convert the go module files into deps.nix, so I first converted it to use dep, then used dep2nix to generate the deps.nix.
Still had to do some manual tweaking to make it build, however, as golang.org/x/sys was not included in deps.nix by some reason.

Turns out https://github.com/adisbladis/vgo2nix exists, so I just used the tool to generate deps.nix

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • 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/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Assured whether relevant documentation is up to date
  • Fits CONTRIBUTING.md.

@rvolosatovs rvolosatovs changed the title echoip: Init at 4bfaf67 echoip: Init at unstable-2018-11-20 Nov 24, 2018
@rvolosatovs
Copy link
Member Author

@worldofpeace

  • fixed version
  • moved to servers
  • added index.html to out

Example usage: https://github.com/rvolosatovs/infrastructure/blob/fae0779f897a527a628f5faeca88bcb61df12be4/nixos/echoip.nix#L17

@rvolosatovs
Copy link
Member Author

...And fixed a typo

@worldofpeace
Copy link
Contributor

The project uses go modules - I did not find an automated solution to convert the go module files into deps.nix, so I first converted it to use dep, then used to dep2nix to generate the deps.nix.
Still had to do some manual tweaking to make it build, however, as golang.org/x/sys was not included in deps.nix by some reason.

To be fair that sounds kind of scary 馃槃
I'm not sure if anything is being done for the new go modules stuff.

Tried to build it and got

fixed-output derivation produced path '/nix/store/ll9hiknw3w3n4l3l0in3fff0p52wmraq-geoip2-golang-7118115' with sha256 hash '0d3kykb1xqh4a1qkpsbl7bbk1pcffshj2dvp5b3xrhyvxfs2cdxs' instead of the expected hash '0zpgpz577rghvgis6ji9l99pq87z5izbgzmnbyn3dy533bayrgpw'

So I think one of the hashes in the deps.nix is wrong.

@worldofpeace
Copy link
Contributor

Corrected the hash manually just to test with https://github.com/rvolosatovs/infrastructure/blob/fae0779f897a527a628f5faeca88bcb61df12be4/nixos/echoip.nix#L17 and it does work.

A NixOS module would be nice too, but it's not required.

@rvolosatovs
Copy link
Member Author

Regarding the module:
It would be nice indeed, however a use case for this service would be quite niche I think.
Maybe in a follow-up PR?

Regarding the hash:
The issue seems to be because of the submodules in https://github.com/oschwald/geoip2-golang, which are only used for testing.
This is the output of
nix-prefetch-git --rev 711811 https://github.com/oschwald/geoip2-golang

{
  "url": "https://github.com/oschwald/geoip2-golang",
  "rev": "7118115686e16b77967cdbf55d1b944fe14ad312",
  "date": "2018-02-22T13:45:52-08:00",
  "sha256": "0zpgpz577rghvgis6ji9l99pq87z5izbgzmnbyn3dy533bayrgpw",
  "fetchSubmodules": false
}

And
nix-prefetch-git --rev 711811 --fetch-submodules https://github.com/oschwald/geoip2-golang

{
  "url": "https://github.com/oschwald/geoip2-golang",
  "rev": "7118115686e16b77967cdbf55d1b944fe14ad312",
  "date": "2018-02-22T13:45:52-08:00",
  "sha256": "0d3kykb1xqh4a1qkpsbl7bbk1pcffshj2dvp5b3xrhyvxfs2cdxs",
  "fetchSubmodules": true
}

I tried to turn the dependency in deps.nix into:

  {
    goPackagePath  = "github.com/oschwald/geoip2-golang";
    fetch = {
      type = "git";
      url = "https://github.com/oschwald/geoip2-golang";
      rev =  "7118115686e16b77967cdbf55d1b944fe14ad312";
      sha256 = "0zpgpz577rghvgis6ji9l99pq87z5izbgzmnbyn3dy533bayrgpw";
      fetchSubmodules = false;
    };
  }

But that does not seem to help and submodules are still pulled in.(and, hence, there's a hash mismatch). Any ideas on how to fix this?

@rvolosatovs
Copy link
Member Author

rg 'fetchSubmodules|submodule' $(find $(nix eval '(<nixpkgs>)') -name 'deps.nix')

Does not find anything either, is it not possible to control the submodule fetching in go package builds?

@worldofpeace
Copy link
Contributor

@rvolosatovs

Looking at the buildGoPackage source, this looks pertinent:

dep2src = goDep:
    {
      inherit (goDep) goPackagePath;
      src = if goDep.fetch.type == "git" then
        fetchgit {
          inherit (goDep.fetch) url rev sha256;
        }
...

It doesn't care about fetchSubmodules = false;. That's probably something we should fix in the future.

If you want to you can work around this by changing the fetch type to FromGitHub which will use a github archive without any submodules.

 {
    goPackagePath  = "github.com/oschwald/geoip2-golang";
    fetch = {
      type = "FromGitHub";
      owner = "oschwald";
      repo = "geoip2-golang";
      rev =  "7118115686e16b77967cdbf55d1b944fe14ad312";
      sha256 = "0zpgpz577rghvgis6ji9l99pq87z5izbgzmnbyn3dy533bayrgpw";
    };
  }

(hash retrieved from nix-prefetch-github)

@rvolosatovs
Copy link
Member Author

@worldofpeace implemented the workaround

@worldofpeace
Copy link
Contributor

Still getting a hash issue so I think the FetchGitHub workaround is still needed.

fixed-output derivation produced path '/nix/store/g2x3lfhppx3g9lwrffjxkjwal7cz51ki-geoip2-golang' with sha256 hash '0d3kykb1xqh4a1qkpsbl7bbk1pcffshj2dvp5b3xrhyvxfs2cdxs' instead of the expected hash '0zpgpz577rghvgis6ji9l99pq87z5izbgzmnbyn3dy533bayrgpw'

@worldofpeace
Copy link
Contributor

@rvolosatovs
I went ahead and fixed this up in fc42a76.
Thanks for working on this.

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

Successfully merging this pull request may close these issues.

None yet

3 participants