Skip to content

Conversation

@adriansalamon
Copy link

@adriansalamon adriansalamon commented Oct 23, 2025

Add go module file. This is needed to make Nix builds work, since it assumes to compile with go 1.16 otherwise, which obviously fails.

Ref of how to use with Nix:

 services.coredns = {
  enable = true;

  package = pkgs.coredns.override {
    externalPlugins = lib.singleton {
      name = "blocker";
      repo = "github.com/icyflame/blocker";
      version = "some_version";
      position.before = "forward";
    };
    vendorHash = lib.fakeHash; # replace with real hash after failing to build once
  };
};  

@icyflame
Copy link
Owner

icyflame commented Oct 27, 2025 via email

@adriansalamon
Copy link
Author

I think adding dependencies would actually be worse in terms of bundling like above with Nix, since this would necessitate you versioning this together with coredns releases. For example, adding a go.mod file with

require (
	github.com/coredns/coredns v1.13.1
)

Could make this be incompatible (not build) with other versions of coredns. I can't speak for compiling coredns manually like in your readme instructions, but I assume there would be problems there also. It's a little sad that go has no good way of specifying dependencies except for exact versions.

@icyflame
Copy link
Owner

icyflame commented Oct 28, 2025 via email

@icyflame
Copy link
Owner

I have been testing this locally. I am unable to build CoreDNS from source with a go.mod file inside the plugin/blocker directory. This is the error that I am seeing:

$ make
go generate coredns.go
go get
go: github.com/coredns/coredns imports
        github.com/coredns/coredns/core/plugin imports
        github.com/coredns/coredns/plugin/blocker: cannot find module providing package github.com/coredns/coredns/plugin/blocker
go: module github.com/Azure/go-autorest/autorest is deprecated: use github.com/Azure/azure-sdk-for-go/sdk/azcore instead.
go: module github.com/Azure/go-autorest/autorest/azure/auth is deprecated: use github.com/Azure/azure-sdk-for-go/sdk/azidentity instead.
make: *** [Makefile:27: core/plugin/zplugin.go] Error 1

Did you run into this?

This is a longer example. The go.mod file inside the blocker plugin seems to be the reason CoreDNS can not be built:

$ g log --oneline | head -1
1db4568df Bump version to 1.13.1 (#7599)

$ make
CGO_ENABLED=0  go build -v -ldflags="-s -w -X github.com/coredns/coredns/coremain.GitCommit=1db4568df-dirty" -o coredns
core/plugin/zplugin.go:14:2: no required module provides package github.com/coredns/coredns/plugin/blocker; to add it:
        go get github.com/coredns/coredns/plugin/blocker
make: *** [Makefile:20: coredns] Error 1

$ cat plugin/blocker/go.mod
module github.com/icyflame/blocker

go 1.23.0

$ mv plugin/blocker/go.mod plugin/blocker/go.mod.1

$ make
CGO_ENABLED=0  go build -v -ldflags="-s -w -X github.com/coredns/coredns/coremain.GitCommit=1db4568df-dirty" -o coredns

@adriansalamon
Copy link
Author

Sorry for not getting back to you. I am able to compile this manually using the same steps as outlined in the official docs.

$ git clone git@github.com:coredns/coredns.git
$ cd coredns
# change plugins.cfg
$ cat plugins.cfg
...
blocker:github.com/adriansalamon/blocker
forward:forward
...
$ go get github.com/adriansalamon/blocker@mine
$ go generate
$ make
$ ./coredns -plugins | grep blocker
blocker

obviously, we can replace the URL to github.com/icyflame/blocker if/once it is merged. We can also run tests with:

go test -v -count=1 github.com/adriansalamon/blocker
=== RUN   TestIsDomainBlocked_ABP
=== RUN   TestIsDomainBlocked_ABP/base_case
=== PAUSE TestIsDomainBlocked_ABP/base_case
=== CONT  TestIsDomainBlocked_ABP/base_case
--- PASS: TestIsDomainBlocked_ABP (0.00s)
    --- PASS: TestIsDomainBlocked_ABP/base_case (0.00s)
=== RUN   TestIsDomainBlocked
=== RUN   TestIsDomainBlocked/base_case
=== PAUSE TestIsDomainBlocked/base_case
=== CONT  TestIsDomainBlocked/base_case
--- PASS: TestIsDomainBlocked (0.00s)
    --- PASS: TestIsDomainBlocked/base_case (0.00s)
=== RUN   TestConcurrentBlocklistAccess_PoC
--- PASS: TestConcurrentBlocklistAccess_PoC (0.09s)
PASS
ok  	github.com/adriansalamon/blocker	0.366s

If you want do develop against a local directory. You can simply add:

replace github.com/icyflame/blocker => <path_to_local_dir>/blocker

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.

2 participants