From 394a8818e45efb2754a37d698f1864d643d9521a Mon Sep 17 00:00:00 2001 From: Andrew Dunham Date: Thu, 15 Feb 2018 00:16:22 -0800 Subject: [PATCH] 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 --- .../syncthing/add-stcli-target.patch | 17 +++ .../networking/syncthing/default.nix | 138 ++++++++++++------ pkgs/top-level/all-packages.nix | 6 +- 3 files changed, 114 insertions(+), 47 deletions(-) create mode 100644 pkgs/applications/networking/syncthing/add-stcli-target.patch diff --git a/pkgs/applications/networking/syncthing/add-stcli-target.patch b/pkgs/applications/networking/syncthing/add-stcli-target.patch new file mode 100644 index 000000000000..58ac15253aed --- /dev/null +++ b/pkgs/applications/networking/syncthing/add-stcli-target.patch @@ -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() { diff --git a/pkgs/applications/networking/syncthing/default.nix b/pkgs/applications/networking/syncthing/default.nix index f5e8876e2b34..64c0b31a2a4d 100644 --- a/pkgs/applications/networking/syncthing/default.nix +++ b/pkgs/applications/networking/syncthing/default.nix @@ -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 + ''; }; } diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 9cd275c84bf3..254e20b2563e 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -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 { };