about summary refs log tree commit diff
path: root/pkgs/tools/backup/duplicity/default.nix
blob: 1da3131f85b048eb8e8f9f34a4bef2c06f583e3f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
{ lib
, stdenv
, fetchFromGitLab
, python3
, librsync
, ncftp
, gnupg
, gnutar
, par2cmdline
, util-linux
, rsync
, makeWrapper
, gettext
, getconf
, testers
, nix-update-script
}:

let self = python3.pkgs.buildPythonApplication rec {
  pname = "duplicity";
  version = "2.2.3";

  src = fetchFromGitLab {
    owner = "duplicity";
    repo = "duplicity";
    rev = "rel.${version}";
    hash = "sha256-4IwKqXlG7jh1siuPT5pVgiYB+KlmCzF6+OMPT3I3yTQ=";
  };

  patches = [
    ./keep-pythonpath-in-testing.patch
  ];

  postPatch = ''
    patchShebangs duplicity/__main__.py

    # don't try to use gtar on darwin/bsd
    substituteInPlace testing/functional/test_restart.py \
      --replace-fail 'tarcmd = "gtar"' 'tarcmd = "tar"'
  '' + lib.optionalString stdenv.isDarwin ''
    # tests try to access these files in the sandbox, but can't deal with EPERM
    substituteInPlace testing/unit/test_globmatch.py \
      --replace-fail /var/log /test/log
    substituteInPlace testing/unit/test_selection.py \
      --replace-fail /usr/bin /dev
    # don't use /tmp/ in tests
    substituteInPlace duplicity/backends/_testbackend.py \
      --replace-fail '"/tmp/' 'os.environ.get("TMPDIR")+"/'
  '';

  disabledTests = lib.optionals stdenv.isDarwin [
    # uses /tmp/
    "testing/unit/test_cli_main.py::CommandlineTest::test_intermixed_args"
  ];

  nativeBuildInputs = [
    makeWrapper
    gettext
    python3.pkgs.wrapPython
    python3.pkgs.setuptools-scm
  ];

  buildInputs = [
    librsync
  ];

  pythonPath = with python3.pkgs; [
    b2sdk
    boto3
    cffi
    cryptography
    ecdsa
    idna
    pygobject3
    fasteners
    lockfile
    paramiko
    pyasn1
    pycrypto
    pydrive2
    future
  ];

  nativeCheckInputs = [
    gnupg # Add 'gpg' to PATH.
    gnutar # Add 'tar' to PATH.
    librsync # Add 'rdiff' to PATH.
    par2cmdline # Add 'par2' to PATH.
  ] ++ lib.optionals stdenv.isLinux [
    util-linux # Add 'setsid' to PATH.
  ] ++ lib.optionals stdenv.isDarwin [
    getconf
  ] ++ (with python3.pkgs; [
    lockfile
    mock
    pexpect
    pytest
    pytest-runner
    fasteners
  ]);

  postInstall = let
    binPath = lib.makeBinPath ([
      gnupg
      ncftp
      rsync
    ] ++ lib.optionals stdenv.isDarwin [
      getconf
    ]); in ''
    wrapProgram $out/bin/duplicity \
      --prefix PATH : "${binPath}"
  '';

  preCheck = ''
    # tests need writable $HOME
    HOME=$PWD/.home

    wrapPythonProgramsIn "$PWD/testing/overrides/bin" "$pythonPath"
  '';

  doCheck = true;

  passthru = {
    updateScript = nix-update-script {
      extraArgs = [ "--version-regex" "rel\.(.*)" ];
    };

    tests.version = testers.testVersion {
      package = self;
    };
  };

  meta = with lib; {
    description = "Encrypted bandwidth-efficient backup using the rsync algorithm";
    homepage = "https://duplicity.gitlab.io/duplicity-web/";
    license = licenses.gpl2Plus;
    maintainers = with maintainers; [ corngood ];
  };
};

in self