Unverified Commit 80b9606f authored by Michele Guerini Rocco's avatar Michele Guerini Rocco Committed by GitHub
Browse files

Merge pull request #331542 from rnhmjoj/pr-ncdns

ncdns: fix ncdns.goModules derivation, 2022-10-07 -> 2024-05-18
parents dd5fddab 632d9a85
Loading
Loading
Loading
Loading
+67 −65
Original line number Diff line number Diff line
{ lib
, stdenv
, fetchpatch
, buildGoModule
, fetchFromGitHub
, nixosTests
, libcap
, go
}:

let

  # ncdns source
  ncdns = fetchFromGitHub {
    owner = "namecoin";
    repo = "ncdns";
    rev = "5adda8d4726d389597df432eb2e17eac1677cea2";
    sha256 = "sha256-Q/RrUTY4WfrByvQv1eCX29DQNf2vSIR29msmhgS73xk=";
  };
  # Note: this module is actually the source code of crypto/x509
  # taken from the Go stdlib and patcheed. So, it can't simply
  # be pinned and added to the vendor dir as everything else.
  x509 = stdenv.mkDerivation rec {
    pname = "x509-compressed";
    version = "0.0.3";

  # script to patch the crypto/x509 package
  x509 = fetchFromGitHub {
    src = fetchFromGitHub {
      owner = "namecoin";
      repo = "x509-compressed";
    rev = "2e30a62a69dac54a977410f283308df232a5d244";
    sha256 = "sha256-/Bd1gYjguj8AiKHyiaIKT+Y3R7kq5gLZlJhY9g/xFXk=";
    # ncdns must be put in a subdirectory for this to work.
    postFetch = ''
      cp -r --no-preserve=mode "${ncdns}" "$out/ncdns"
    '';
      rev = "v${version}";
      hash = "sha256-BmVtClZ3TsUbQrhwREXa42pUOlkBA4a2HVBzl1sdBIo=";
    };

in
    patches = [
      # https://github.com/namecoin/x509-compressed/pull/4
      (fetchpatch {
        url = "https://github.com/namecoin/x509-compressed/commit/b4fb598b.patch";
        hash = "sha256-S4Y4B4FH15IyaTJtSb03C8QffnsMXSYc6q1Gka/PVV4=";
      })
    ];

buildGoModule {
  pname = "ncdns";
  version = "unstable-2022-10-07";

  src = x509;
    nativeBuildInputs = [ go ];

  vendorHash = "sha256-ENtTnDsz5WhRz1kiqnWQ5vyEpZtgi7ZeYvksffgW78k=";
    buildPhase = ''
      # Put in our own lockfiles
      cp ${./x509-go.mod} go.mod
      cp ${./x509-go.sum} go.sum

  # Override the goModules fetcher derivation to apply
  # upstream's patch of the crypto/x509 library.
  modBuildPhase = ''
    go mod init github.com/namecoin/x509-compressed
    go generate ./...
    go mod tidy
      # Generate Go code
      env HOME=/tmp go generate ./...

    cd ncdns
    go mod init github.com/namecoin/ncdns
    go mod edit \
      -replace github.com/coreos/go-systemd=github.com/coreos/go-systemd/v22@latest \
      -replace github.com/namecoin/x509-compressed=$NIX_BUILD_TOP/source
    go mod tidy
      # Clean up more references to internal modules
      # (see https://github.com/namecoin/x509-compressed/pull/4)
      sed -e '/import "internal/d' \
          -e 's/goos.IsAndroid/0/g' -i x509/*.go
    '';

  # Copy over the lockfiles as well, because the source
  # doesn't contain it. The fixed-output derivation is
  # probably not reproducible anyway.
  modInstallPhase = ''
    mv -t vendor go.mod go.sum
    cp -r --reflink=auto vendor "$out"
    installPhase = ''
      cp -r . "$out"
    '';
  };

  buildInputs = [ libcap ];
in

  # The fetcher derivation must run with a different
  # $sourceRoot, but buildGoModule doesn't allow that,
  # so we use this ugly hack.
  unpackPhase = ''
    runHook preUnpack
buildGoModule {
  pname = "ncdns";
  version = "unstable-2024-05-18";

    unpackFile "$src"
    sourceRoot=$PWD/source/ncdns
    chmod -R u+w -- "$sourceRoot"
    cd $sourceRoot
  src = fetchFromGitHub {
    owner = "namecoin";
    repo = "ncdns";
    rev = "8a9f7c3037384f12fae400268d0a7f79d26b5532";
    hash = "sha256-lFpjfpOAgvYoV3ci2oSdy8ZOlQ2rWlApiFWcvOMdkyk=";
  };

    runHook postUnpack
  # Note: to update ncdns add the following lines
  #
  #   chmod -R +w .
  #   go mod tidy
  #   cat go.mod go.sum
  #   exit 1
  #
  # to the `preBuild` here and update the lock files
  preBuild = ''
    # Sideload the generated x509 module
    ln -s '${x509}' x509
  '';

  # Same as above: can't use `patches` because that would
  # be also applied to the fetcher derivation, thus failing.
  patchPhase = ''
    runHook prePatch
    patch -p1 < ${./fix-tpl-path.patch}
    runHook postPatch
  '';
  vendorHash = "sha256-FoCK2qkhbc+6D4V77pNLiC9d68nkeYJxb7uiNYEP2Xw=";

  preBuild = ''
    chmod -R u+w vendor
    mv -t . vendor/go.{mod,sum}
  buildInputs = [ libcap ];

  patches = [./fix-tpl-path.patch ];

  # Put in our own lockfiles
  postPatch = ''
    cp ${./ncdns-go.mod} go.mod
    cp ${./ncdns-go.sum} go.sum
  '';

  preCheck = ''
    # needed to run the ncdns test suite
    ln -s $PWD/vendor ../../go/src
    ln -s $PWD/vendor ../go/src
  '';

  postInstall = ''
+59 −0
Original line number Diff line number Diff line
module github.com/namecoin/ncdns

go 1.22.5

replace github.com/namecoin/x509-compressed => ./x509
replace gopkg.in/alecthomas/kingpin.v2 => github.com/alecthomas/kingpin/v2 v2.3.2

require (
  github.com/btcsuite/btcd v0.24.2
  github.com/fxamacker/cbor v1.5.1
  github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da
  github.com/hlandau/buildinfo v0.0.0-20161112115716-337a29b54997
  github.com/hlandau/degoutils v0.0.0-20161011040956-8fa2440b6344
  github.com/hlandau/dexlogconfig v0.0.0-20220319061854-86a3fc314fe7
  github.com/hlandau/nctestsuite v0.0.0-20151129185958-a9b78806c85c
  github.com/hlandau/xlog v1.0.0
  github.com/kr/pretty v0.3.1
  github.com/miekg/dns v1.1.61
  github.com/namecoin/certinject v0.1.1
  github.com/namecoin/ncbtcjson v0.1.0
  github.com/namecoin/ncrpcclient v0.1.0
  github.com/namecoin/splicesign v0.0.1
  github.com/namecoin/tlsrestrictnss v0.0.5
  github.com/namecoin/x509-compressed v0.0.0-00010101000000-000000000000
  gopkg.in/hlandau/easyconfig.v1 v1.0.18
  gopkg.in/hlandau/madns.v2 v2.0.2
  gopkg.in/hlandau/service.v2 v2.0.17
)
require (
  github.com/BurntSushi/toml v1.4.0 // indirect
  github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 // indirect
  github.com/btcsuite/btcd/btcec/v2 v2.1.3 // indirect
  github.com/btcsuite/btcd/btcutil v1.1.5 // indirect
  github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0 // indirect
  github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f // indirect
  github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd // indirect
  github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792 // indirect
  github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf // indirect
  github.com/decred/dcrd/crypto/blake256 v1.0.0 // indirect
  github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect
  github.com/erikdubbelboer/gspt v0.0.0-20210805194459-ce36a5128377 // indirect
  github.com/kr/text v0.2.0 // indirect
  github.com/mattn/go-isatty v0.0.20 // indirect
  github.com/namecoin/crosssignnameconstraint v0.0.3 // indirect
  github.com/ogier/pflag v0.0.1 // indirect
  github.com/rogpeppe/go-internal v1.9.0 // indirect
  github.com/shiena/ansicolor v0.0.0-20230509054315-a9deabde6e02 // indirect
  github.com/x448/float16 v0.8.4 // indirect
  github.com/xhit/go-str2duration/v2 v2.1.0 // indirect
  golang.org/x/crypto v0.25.0 // indirect
  golang.org/x/mod v0.18.0 // indirect
  golang.org/x/net v0.26.0 // indirect
  golang.org/x/sync v0.7.0 // indirect
  golang.org/x/sys v0.22.0 // indirect
  golang.org/x/tools v0.22.0 // indirect
  gopkg.in/alecthomas/kingpin.v2 v2.0.0-00010101000000-000000000000 // indirect
  gopkg.in/hlandau/configurable.v1 v1.0.1 // indirect
  gopkg.in/hlandau/svcutils.v1 v1.0.11 // indirect
)
+195 −0

File added.

Preview size limit exceeded, changes collapsed.

+5 −0
Original line number Diff line number Diff line
module github.com/namecoin/x509-compressed

go 1.22.4

require golang.org/x/crypto v0.25.0
+2 −0
Original line number Diff line number Diff line
golang.org/x/crypto v0.25.0 h1:ypSNr+bnYL2YhwoMt2zPxHFmbAN1KZs/njMG3hxUp30=
golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M=