nixpkgs/pkgs/servers/dns/coredns/default.nix
Brendan Taylor 95e66809de coredns: allow adding external plugins
Solves https://github.com/NixOS/nixpkgs/issues/146603

CoreDNS has support for plugins that are added at compile time. This
exposes an argument `externalPlugins` that will build coredns with
the specified plugins.

Example:
```
coredns-fanout = pkgs.coredns.override {
  externalPlugins = [
    {name = "fanout"; repo = "github.com/networkservicemesh/fanout"; version = "v1.9.1";}
  ];
  vendorHash = "<SRI hash>";
};
```
2023-09-27 23:35:47 +02:00

80 lines
2.1 KiB
Nix

{ lib
, stdenv
, buildGoModule
, fetchFromGitHub
, installShellFiles
, externalPlugins ? []
, vendorHash ? "sha256-TvIswNQ7DL/MtYmMSxXf+VqKHcmzZVZwohOCvRWxBkY="
}:
let
attrsToPlugins = attrs:
builtins.map ({name, repo, version}: "${name}:${repo}") attrs;
attrsToSources = attrs:
builtins.map ({name, repo, version}: "${repo}@${version}") attrs;
in buildGoModule rec {
pname = "coredns";
version = "1.11.0";
src = fetchFromGitHub {
owner = "coredns";
repo = "coredns";
rev = "v${version}";
sha256 = "sha256-Mn8hOsODTlnl6PJaevMcyIKkIx/1Lk2HGA7fSSizR20=";
};
inherit vendorHash;
nativeBuildInputs = [ installShellFiles ];
outputs = [ "out" "man" ];
# Override the go-modules fetcher derivation to fetch plugins
modBuildPhase = ''
for plugin in ${builtins.toString (attrsToPlugins externalPlugins)}; do echo $plugin >> plugin.cfg; done
for src in ${builtins.toString (attrsToSources externalPlugins)}; do go get $src; done
go generate
go mod vendor
'';
modInstallPhase = ''
mv -t vendor go.mod go.sum plugin.cfg
cp -r --reflink=auto vendor "$out"
'';
preBuild = ''
chmod -R u+w vendor
mv -t . vendor/go.{mod,sum} vendor/plugin.cfg
go generate
'';
postPatch = ''
substituteInPlace test/file_cname_proxy_test.go \
--replace "TestZoneExternalCNAMELookupWithProxy" \
"SkipZoneExternalCNAMELookupWithProxy"
substituteInPlace test/readme_test.go \
--replace "TestReadme" "SkipReadme"
# this test fails if any external plugins were imported.
# it's a lint rather than a test of functionality, so it's safe to disable.
substituteInPlace test/presubmit_test.go \
--replace "TestImportOrdering" "SkipImportOrdering"
'' + lib.optionalString stdenv.isDarwin ''
# loopback interface is lo0 on macos
sed -E -i 's/\blo\b/lo0/' plugin/bind/setup_test.go
'';
postInstall = ''
installManPage man/*
'';
meta = with lib; {
homepage = "https://coredns.io";
description = "A DNS server that runs middleware";
license = licenses.asl20;
maintainers = with maintainers; [ rushmorem rtreffer deltaevo ];
};
}