syncthing: Add discovery/relay servers, improve build (#34831)

- Fix GOPATH checks
- Install manpages
- Also build and install discovery and relay servers + cli 
- Make the build more pure by explicitly setting the build username/host
This commit is contained in:
Andrew Dunham 2018-02-15 00:16:22 -08:00 committed by Peter Hoeg
parent a956c646fb
commit 394a8818e4
3 changed files with 114 additions and 47 deletions

View File

@ -0,0 +1,17 @@
diff --git i/build.go w/build.go
index 7d400d6f..1b5e1d25 100644
--- i/build.go
+++ w/build.go
@@ -175,6 +175,12 @@ var targets = map[string]target{
{src: "AUTHORS", dst: "deb/usr/share/doc/syncthing-relaypoolsrv/AUTHORS.txt", perm: 0644},
},
},
+ "stcli": {
+ name: "stcli",
+ description: "Syncthing CLI",
+ buildPkg: "github.com/syncthing/syncthing/cmd/stcli",
+ binaryName: "stcli", // .exe will be added automatically for Windows builds
+ },
}
func init() {

View File

@ -1,57 +1,103 @@
{ stdenv, lib, fetchFromGitHub, go, procps, removeReferencesTo }:
{ stdenv, lib, go, procps, removeReferencesTo, fetchFromGitHub }:
stdenv.mkDerivation rec {
version = "0.14.44";
name = "syncthing-${version}";
let
common = { stname, target, patches ? [], postInstall ? "" }:
stdenv.mkDerivation rec {
version = "0.14.44";
name = "${stname}-${version}";
src = fetchFromGitHub {
owner = "syncthing";
repo = "syncthing";
rev = "v${version}";
sha256 = "1gdkx6lbzmdz2hqc9slbq41rwgkxmdisnj0iywx4mppmc2b4v6wh";
src = fetchFromGitHub {
owner = "syncthing";
repo = "syncthing";
rev = "v${version}";
sha256 = "1gdkx6lbzmdz2hqc9slbq41rwgkxmdisnj0iywx4mppmc2b4v6wh";
};
inherit patches;
buildInputs = [ go ];
nativeBuildInputs = [ removeReferencesTo ];
buildPhase = ''
# Syncthing expects that it is checked out in $GOPATH, if that variable is
# set. Since this isn't true when we're fetching source, we can explicitly
# unset it and force Syncthing to set up a temporary one for us.
env GOPATH= BUILD_USER=nix BUILD_HOST=nix go run build.go -no-upgrade -version v${version} build ${target}
'';
installPhase = ''
install -Dm755 ${target} $out/bin/${target}
runHook postInstall
'';
inherit postInstall;
preFixup = ''
find $out/bin -type f -exec remove-references-to -t ${go} '{}' '+'
'';
meta = with lib; {
homepage = https://www.syncthing.net/;
description = "Open Source Continuous File Synchronization";
license = licenses.mpl20;
maintainers = with maintainers; [ pshendry joko peterhoeg andrew-d ];
platforms = platforms.unix;
};
};
in {
syncthing = common {
stname = "syncthing";
target = "syncthing";
postInstall = ''
# This installs man pages in the correct directory according to the suffix
# on the filename
for mf in man/*.[1-9]; do
mantype="$(echo "$mf" | awk -F"." '{print $NF}')"
mandir="$out/share/man/man$mantype"
install -Dm644 "$mf" "$mandir/$(basename "$mf")"
done
'' + lib.optionalString (stdenv.isLinux) ''
mkdir -p $out/lib/systemd/{system,user}
substitute etc/linux-systemd/system/syncthing-resume.service \
$out/lib/systemd/system/syncthing-resume.service \
--replace /usr/bin/pkill ${procps}/bin/pkill
substitute etc/linux-systemd/system/syncthing@.service \
$out/lib/systemd/system/syncthing@.service \
--replace /usr/bin/syncthing $out/bin/syncthing
substitute etc/linux-systemd/user/syncthing.service \
$out/lib/systemd/user/syncthing.service \
--replace /usr/bin/syncthing $out/bin/syncthing
'';
};
buildInputs = [ go removeReferencesTo ];
syncthing-cli = common {
stname = "syncthing-cli";
buildPhase = ''
mkdir -p src/github.com/syncthing
ln -s $(pwd) src/github.com/syncthing/syncthing
export GOPATH=$(pwd)
patches = [ ./add-stcli-target.patch ];
target = "stcli";
};
# Syncthing's build.go script expects this working directory
cd src/github.com/syncthing/syncthing
syncthing-discovery = common {
stname = "syncthing-discovery";
target = "stdiscosrv";
};
go run build.go -no-upgrade -version v${version} build
'';
syncthing-relay = common {
stname = "syncthing-relay";
target = "strelaysrv";
installPhase = ''
mkdir -p $out/lib/systemd/{system,user}
postInstall = lib.optionalString (stdenv.isLinux) ''
mkdir -p $out/lib/systemd/system
install -Dm755 syncthing $out/bin/syncthing
'' + lib.optionalString (stdenv.isLinux) ''
substitute etc/linux-systemd/system/syncthing-resume.service \
$out/lib/systemd/system/syncthing-resume.service \
--replace /usr/bin/pkill ${procps}/bin/pkill
substitute etc/linux-systemd/system/syncthing@.service \
$out/lib/systemd/system/syncthing@.service \
--replace /usr/bin/syncthing $out/bin/syncthing
substitute etc/linux-systemd/user/syncthing.service \
$out/lib/systemd/user/syncthing.service \
--replace /usr/bin/syncthing $out/bin/syncthing
'';
preFixup = ''
find $out/bin -type f -exec remove-references-to -t ${go} '{}' '+'
'';
meta = with stdenv.lib; {
homepage = https://www.syncthing.net/;
description = "Open Source Continuous File Synchronization";
license = licenses.mpl20;
maintainers = with maintainers; [ pshendry joko peterhoeg ];
platforms = platforms.unix;
substitute cmd/strelaysrv/etc/linux-systemd/strelaysrv.service \
$out/lib/systemd/system/strelaysrv.service \
--replace /usr/bin/strelaysrv $out/bin/strelaysrv
'';
};
}

View File

@ -17352,7 +17352,11 @@ with pkgs;
syncplay = callPackage ../applications/networking/syncplay { };
syncthing = callPackage ../applications/networking/syncthing { };
inherit (callPackages ../applications/networking/syncthing { })
syncthing
syncthing-cli
syncthing-discovery
syncthing-relay;
syncthing-gtk = python2Packages.callPackage ../applications/networking/syncthing-gtk { };