summary refs log tree commit diff
path: root/pkgs/applications/networking/syncthing
diff options
context:
space:
mode:
authorAndrew Dunham <andrew@du.nham.ca>2018-02-15 00:16:22 -0800
committerPeter Hoeg <peter@hoeg.com>2018-02-15 16:16:22 +0800
commit394a8818e45efb2754a37d698f1864d643d9521a (patch)
treefda0b8602a92686c47cb5005aad0173c69d09b33 /pkgs/applications/networking/syncthing
parenta956c646fbdf46d973afac0034558751e69fdb7b (diff)
downloadnixpkgs-394a8818e45efb2754a37d698f1864d643d9521a.tar
nixpkgs-394a8818e45efb2754a37d698f1864d643d9521a.tar.gz
nixpkgs-394a8818e45efb2754a37d698f1864d643d9521a.tar.bz2
nixpkgs-394a8818e45efb2754a37d698f1864d643d9521a.tar.lz
nixpkgs-394a8818e45efb2754a37d698f1864d643d9521a.tar.xz
nixpkgs-394a8818e45efb2754a37d698f1864d643d9521a.tar.zst
nixpkgs-394a8818e45efb2754a37d698f1864d643d9521a.zip
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
Diffstat (limited to 'pkgs/applications/networking/syncthing')
-rw-r--r--pkgs/applications/networking/syncthing/add-stcli-target.patch17
-rw-r--r--pkgs/applications/networking/syncthing/default.nix130
2 files changed, 105 insertions, 42 deletions
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 00000000000..58ac15253ae
--- /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 f5e8876e2b3..64c0b31a2a4 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;
 
-  buildInputs = [ go removeReferencesTo ];
+      preFixup = ''
+        find $out/bin -type f -exec remove-references-to -t ${go} '{}' '+'
+      '';
 
-  buildPhase = ''
-    mkdir -p src/github.com/syncthing
-    ln -s $(pwd) src/github.com/syncthing/syncthing
-    export GOPATH=$(pwd)
+      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;
+      };
+    };
 
-    # Syncthing's build.go script expects this working directory
-    cd src/github.com/syncthing/syncthing
+in {
+  syncthing = common {
+    stname = "syncthing";
+    target = "syncthing";
 
-    go run build.go -no-upgrade -version v${version} build
-  '';
+    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
 
-  installPhase = ''
-    mkdir -p $out/lib/systemd/{system,user}
+    '' + lib.optionalString (stdenv.isLinux) ''
+      mkdir -p $out/lib/systemd/{system,user}
 
-    install -Dm755 syncthing $out/bin/syncthing
+      substitute etc/linux-systemd/system/syncthing-resume.service \
+                 $out/lib/systemd/system/syncthing-resume.service \
+                 --replace /usr/bin/pkill ${procps}/bin/pkill
 
-  '' + 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/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
+    '';
+  };
+
+  syncthing-cli = common {
+    stname = "syncthing-cli";
+
+    patches = [ ./add-stcli-target.patch ];
+    target = "stcli";
+  };
+
+  syncthing-discovery = common {
+    stname = "syncthing-discovery";
+    target = "stdiscosrv";
+  };
 
-    substitute etc/linux-systemd/user/syncthing.service \
-               $out/lib/systemd/user/syncthing.service \
-               --replace /usr/bin/syncthing $out/bin/syncthing
-  '';
+  syncthing-relay = common {
+    stname = "syncthing-relay";
+    target = "strelaysrv";
 
-  preFixup = ''
-    find $out/bin -type f -exec remove-references-to -t ${go} '{}' '+'
-  '';
+    postInstall = lib.optionalString (stdenv.isLinux) ''
+      mkdir -p $out/lib/systemd/system
 
-  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
+    '';
   };
 }