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