fork
Configure Feed
Select the types of activity you want to include in your feed.
lol
fork
Configure Feed
Select the types of activity you want to include in your feed.
1{ pkgsBuildBuild
2, go
3, buildGoModule
4, stdenv
5, lib
6, procps
7, fetchFromGitHub
8, nixosTests
9, autoSignDarwinBinariesHook
10}:
11
12let
13 common = { stname, target, postInstall ? "" }:
14 buildGoModule rec {
15 pname = stname;
16 version = "1.26.1";
17
18 src = fetchFromGitHub {
19 owner = "syncthing";
20 repo = "syncthing";
21 rev = "v${version}";
22 hash = "sha256-R7JTHlNP1guKRfiDjPVi1lnvfUAXuPDNDAMTGmbj3Hc=";
23 };
24
25 vendorHash = "sha256-XYXIj+7xe33hCYM6Z9tqGSgr/P0LVlaPNf3T0PrxU7I=";
26
27 nativeBuildInputs = lib.optionals stdenv.isDarwin [
28 # Recent versions of macOS seem to require binaries to be signed when
29 # run from Launch Agents/Daemons, even on x86 devices where it has a
30 # more lax code signing policy compared to Apple Silicon. So just sign
31 # the binaries on both architectures to make it possible for launchd to
32 # auto-start Syncthing at login.
33 autoSignDarwinBinariesHook
34 ];
35
36 doCheck = false;
37
38 BUILD_USER = "nix";
39 BUILD_HOST = "nix";
40
41 buildPhase = ''
42 runHook preBuild
43 (
44 export GOOS="${pkgsBuildBuild.go.GOOS}" GOARCH="${pkgsBuildBuild.go.GOARCH}" CC=$CC_FOR_BUILD
45 go build build.go
46 go generate github.com/syncthing/syncthing/lib/api/auto github.com/syncthing/syncthing/cmd/strelaypoolsrv/auto
47 )
48 ./build -goos ${go.GOOS} -goarch ${go.GOARCH} -no-upgrade -version v${version} build ${target}
49 runHook postBuild
50 '';
51
52 installPhase = ''
53 runHook preInstall
54 install -Dm755 ${target} $out/bin/${target}
55 runHook postInstall
56 '';
57
58 inherit postInstall;
59
60 passthru.tests = {
61 inherit (nixosTests) syncthing syncthing-init syncthing-relay;
62 };
63
64 meta = with lib; {
65 homepage = "https://syncthing.net/";
66 description = "Open Source Continuous File Synchronization";
67 changelog = "https://github.com/syncthing/syncthing/releases/tag/v${version}";
68 license = licenses.mpl20;
69 maintainers = with maintainers; [ joko peterhoeg andrew-d ];
70 mainProgram = target;
71 platforms = platforms.unix;
72 };
73 };
74
75in
76{
77 syncthing = common {
78 stname = "syncthing";
79 target = "syncthing";
80
81 postInstall = ''
82 # This installs man pages in the correct directory according to the suffix
83 # on the filename
84 for mf in man/*.[1-9]; do
85 mantype="$(echo "$mf" | awk -F"." '{print $NF}')"
86 mandir="$out/share/man/man$mantype"
87 install -Dm644 "$mf" "$mandir/$(basename "$mf")"
88 done
89
90 '' + lib.optionalString (stdenv.isLinux) ''
91 mkdir -p $out/lib/systemd/{system,user}
92
93 substitute etc/linux-systemd/system/syncthing-resume.service \
94 $out/lib/systemd/system/syncthing-resume.service \
95 --replace /usr/bin/pkill ${procps}/bin/pkill
96
97 substitute etc/linux-systemd/system/syncthing@.service \
98 $out/lib/systemd/system/syncthing@.service \
99 --replace /usr/bin/syncthing $out/bin/syncthing
100
101 substitute etc/linux-systemd/user/syncthing.service \
102 $out/lib/systemd/user/syncthing.service \
103 --replace /usr/bin/syncthing $out/bin/syncthing
104 '';
105 };
106
107 syncthing-discovery = common {
108 stname = "syncthing-discovery";
109 target = "stdiscosrv";
110 };
111
112 syncthing-relay = common {
113 stname = "syncthing-relay";
114 target = "strelaysrv";
115
116 postInstall = lib.optionalString (stdenv.isLinux) ''
117 mkdir -p $out/lib/systemd/system
118
119 substitute cmd/strelaysrv/etc/linux-systemd/strelaysrv.service \
120 $out/lib/systemd/system/strelaysrv.service \
121 --replace /usr/bin/strelaysrv $out/bin/strelaysrv
122 '';
123 };
124}