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

Add sources to override sources fetcher #123

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

juliens
Copy link

@juliens juliens commented Sep 4, 2023

This PR is a proposition to be able to override the source fetcher.

This can collide with #42 but I think it's a simpler solution to the problem.

User needs to define by itself how to fetch the dependency, but with that it works with all repository etc.. (no guessing).

The usage is pretty simple:

pkgs.buildGoApplication {
  pname = "my-app";
  version = "0.1";
  pwd = ./.;
  src = ./.;
  modules = ./gomod2nix.toml;
  sources = {
    "my-dependency_v0.10.0"= builtins.fetchGit {
      url = "[email protected]:test/my-dependency.git";
      ref = "master";
      rev = "xxxxxxxxx";
    };
  };
}

I just wonder if it is a problem that we don't verify the origin sha of the dependency and that we move the responsability of the "sha" on the fetchGit

WDYT?

@frederictobiasc
Copy link

frederictobiasc commented Feb 14, 2024

Hi, this works for my private repositories. Would also be interested in knowing what the maintainers think of this solution.

@anthr76
Copy link

anthr76 commented Apr 12, 2024

It would be nice to have support to pass in packages of private go modules so they can be easily re-used between derivations.

@tonybutt
Copy link

Anyway we can have this merged?

@frederictobiasc
Copy link

Anyway we can have this merged?

@marcusramberg: You merged some PRs recently. Maybe there is a chance you could have a look at that as well, since @adisbladis seems out of office?

@tonybutt
Copy link

tonybutt commented Oct 17, 2024

I went down a huge path to get this working for myself and I landed on this as the cleanest way, imo

test = pkgs.buildGoModule {
            name = "test";
            src = gitignore.lib.gitignoreSource ./.;
            doCheck = false;
            ldFlags = "-mod=mod";
            vendorHash = "sha256-ZKp4eeZRFWbogDadB8ZJfBXhSYyVYq1uPpz2WekvtPg=";
            CGO_ENABLED = 0;
            overrideModAttrs = (oldAttrs: {
              impureEnvVars = oldAttrs.impureEnvVars or [ ] ++ [
                "NIX_GITLAB_TOKEN"
              ];
              preBuild = /* bash */ ''
                export HOME=$(mktemp -d)
                cat > ~/.netrc <<EOF
                machine YOUR_PRIVATE_REPO
                  login oauth2
                  password $NIX_GITLAB_TOKEN
                EOF
                export GOPRIVATE=YOUR_PRIVATE_REPO/*
                export GONOSUMDB=YOUR_PRIVATE_REPO
              '';

              preferLocalBuild = true;
            });
          };

Maybe we can use this as a way to inspire something that will support private repos? I actually don't even mind having to update the vendorHash when depends change with this method.

anthr76 added a commit to anthr76/gomod2nix that referenced this pull request Nov 4, 2024
@anthr76
Copy link

anthr76 commented Nov 4, 2024

@juliens can you rebase this branch?

anthr76 added a commit to anthr76/gomod2nix that referenced this pull request Nov 5, 2024
nix-community#123

Signed-off-by: Anthony Rabbito <[email protected]>
@anthr76
Copy link

anthr76 commented Nov 5, 2024

Thanks @juliens! I am noticing an issue in build:

error: builder for '/nix/store/bp37lm1x2l79sfmm5gz92xrnmyhxdi3y-omit-1.28.0.drv' failed with exit code 1;
       last 11 log lines:
       > Running phase: unpackPhase
       > unpacking source archive /nix/store/a3d53dch6pg6d36m4rgrg2my3nin03jg-source
       > source root is source
       > Running phase: patchPhase
       > Running phase: updateAutotoolsGnuConfigScriptsPhase
       > Running phase: configurePhase
       > Running phase: buildPhase
       > Building subPackage .
       > internal/omit/omit.go:8:2: cannot find module providing package github.com/omit/omit/api/v1alpha1: import lookup disabled by -mod=vendor

I assume this is because the go.mod in github.com/omit/omitcontains a replace.

So inside the vendor directory github.com/omit/omit/api/v1alpha1 is actually github.com/omit/omit is there any suggestions on working around 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.

5 participants