lol
1{
2 buildGoModule,
3 fetchFromGitHub,
4 gzip,
5 iana-etc,
6 lib,
7 libredirect,
8 nodejs,
9 pnpm_9,
10 restic,
11 stdenv,
12 util-linux,
13 makeBinaryWrapper,
14}:
15let
16 pname = "backrest";
17 version = "1.9.2";
18
19 src = fetchFromGitHub {
20 owner = "garethgeorge";
21 repo = "backrest";
22 tag = "v${version}";
23 hash = "sha256-3lAWViC9K34R8la/z57kjGJmMmletGd8pJ1dDt+BeKQ=";
24 };
25
26 frontend = stdenv.mkDerivation (finalAttrs: {
27 inherit version;
28 pname = "${pname}-webui";
29 src = "${src}/webui";
30
31 nativeBuildInputs = [
32 nodejs
33 pnpm_9.configHook
34 ];
35
36 pnpmDeps = pnpm_9.fetchDeps {
37 inherit (finalAttrs) pname version src;
38 fetcherVersion = 1;
39 hash = "sha256-vJgsU0OXyAKjUJsPOyIY8o3zfNW1BUZ5IL814wmJr3o=";
40 };
41
42 buildPhase = ''
43 runHook preBuild
44 export BACKREST_BUILD_VERSION=${version}
45 pnpm build
46 runHook postBuild
47 '';
48
49 installPhase = ''
50 runHook preInstall
51 mkdir $out
52 cp -r dist/* $out
53 runHook postInstall
54 '';
55 });
56in
57buildGoModule {
58 inherit pname src version;
59
60 postPatch = ''
61 sed -i -e \
62 '/func installRestic(targetPath string) error {/a\
63 return fmt.Errorf("installing restic from an external source is prohibited by nixpkgs")' \
64 internal/resticinstaller/resticinstaller.go
65 '';
66
67 vendorHash = "sha256-oycV8JAJQF/PNc7mmYGzkZbpG8pMwxThmuys9e0+hcc=";
68
69 nativeBuildInputs = [
70 gzip
71 makeBinaryWrapper
72 ];
73
74 preBuild = ''
75 mkdir -p ./webui/dist
76 cp -r ${frontend}/* ./webui/dist
77
78 go generate -skip="npm" ./...
79 '';
80
81 nativeCheckInputs = [
82 util-linux
83 ]
84 ++ lib.optionals stdenv.hostPlatform.isDarwin [ libredirect.hook ];
85
86 checkFlags =
87 let
88 skippedTests = [
89 "TestMultihostIndexSnapshots"
90 "TestRunCommand"
91 "TestSnapshot"
92 ]
93 ++ lib.optionals stdenv.hostPlatform.isDarwin [
94 "TestBackup" # relies on ionice
95 "TestCancelBackup"
96 ];
97 in
98 [ "-skip=^${builtins.concatStringsSep "$|^" skippedTests}$" ];
99
100 preCheck = ''
101 # Use restic from nixpkgs, otherwise download fails in sandbox
102 export BACKREST_RESTIC_COMMAND="${restic}/bin/restic"
103 export HOME=$(pwd)
104 ''
105 + lib.optionalString (stdenv.hostPlatform.isDarwin) ''
106 export NIX_REDIRECTS=/etc/protocols=${iana-etc}/etc/protocols:/etc/services=${iana-etc}/etc/services
107 '';
108
109 doCheck = true;
110
111 postInstall = ''
112 wrapProgram $out/bin/backrest \
113 --set-default BACKREST_RESTIC_COMMAND "${lib.getExe restic}"
114 '';
115
116 meta = {
117 description = "Web UI and orchestrator for restic backup";
118 homepage = "https://github.com/garethgeorge/backrest";
119 changelog = "https://github.com/garethgeorge/backrest/releases/tag/v${version}";
120 license = lib.licenses.gpl3Only;
121 maintainers = with lib.maintainers; [ iedame ];
122 mainProgram = "backrest";
123 platforms = lib.platforms.unix;
124 };
125}