btrbk: add mainProgram
[NixPkgs.git] / pkgs / by-name / bt / btrbk / package.nix
blob19dcb047f2e9e8b1edeb934e923f750415d1302d
1 { lib
2 , stdenv
3 , fetchurl
4 , bash
5 , btrfs-progs
6 , openssh
7 , perl
8 , perlPackages
9 , util-linux
10 , asciidoctor
11 , mbuffer
12 , makeWrapper
13 , genericUpdater
14 , curl
15 , writeShellScript
16 , nixosTests
19 stdenv.mkDerivation rec {
20   pname = "btrbk";
21   version = "0.32.6";
23   src = fetchurl {
24     url = "https://digint.ch/download/btrbk/releases/${pname}-${version}.tar.xz";
25     sha256 = "AuKsZHyRhGMgLL5ge7lVV6T3/SNwaRJDM8VNpbK7t2s=";
26   };
28   nativeBuildInputs = [ asciidoctor makeWrapper ];
30   buildInputs = with perlPackages; [ perl DateCalc ];
32   preInstall = ''
33     for f in $(find . -name Makefile); do
34       substituteInPlace "$f" \
35         --replace "/usr" "$out" \
36         --replace "/etc" "$out/etc"
37     done
39     # Tainted Mode disables PERL5LIB
40     substituteInPlace btrbk \
41       --replace "perl -T" "perl" \
42       --replace "\$0" "\$ENV{'program_name'}"
44     # Fix SSH filter script
45     sed -i '/^export PATH/d' ssh_filter_btrbk.sh
46     substituteInPlace ssh_filter_btrbk.sh --replace logger ${util-linux}/bin/logger
47   '';
49   preFixup = ''
50     wrapProgram $out/bin/btrbk \
51       --set PERL5LIB $PERL5LIB \
52       --run 'export program_name=$0' \
53       --prefix PATH ':' "${lib.makeBinPath [ btrfs-progs bash mbuffer openssh ]}"
54   '';
56   passthru.tests = {
57     inherit (nixosTests) btrbk btrbk-no-timer btrbk-section-order btrbk-doas;
58   };
60   passthru.updateScript = genericUpdater {
61     versionLister = writeShellScript "btrbk-versionLister" ''
62       ${curl}/bin/curl -s https://digint.ch/download/btrbk/releases/ | ${perl}/bin/perl -lne 'print $1 if /btrbk-([0-9.]*)\.tar/'
63     '';
64   };
66   meta = with lib; {
67     description = "Backup tool for btrfs subvolumes";
68     homepage = "https://digint.ch/btrbk";
69     license = licenses.gpl3Only;
70     platforms = platforms.unix;
71     maintainers = with maintainers; [ asymmetric ];
72     mainProgram = "btrbk";
73   };