aboutsummaryrefslogtreecommitdiff
path: root/app/backup/build/backup-psql/default.nix
blob: 2cd8d93ced2e3a95c10d25731a7d2f2d803d1b00 (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
let
  common = import ./common.nix;
  pkgs = import common.pkgsSrc {};
  python-with-my-packages = pkgs.python3.withPackages (p: with p; [
    minio
  ]);
in
  pkgs.stdenv.mkDerivation {
    name = "backup-psql";
    src = pkgs.lib.sourceFilesBySuffices ./. [ ".py" ];

    buildInputs = [
      python-with-my-packages
      pkgs.age
      pkgs.postgresql_14
    ];

    buildPhase = ''
      cat > backup-psql <<EOF
      #!${pkgs.bash}/bin/bash

      export PYTHONPATH=${python-with-my-packages}/${python-with-my-packages.sitePackages}
      export PATH=${python-with-my-packages}/bin:${pkgs.age}/bin:${pkgs.postgresql_14}/bin

      ${python-with-my-packages}/bin/python3 $out/lib/backup-psql.py
      EOF

      chmod +x backup-psql
    '';

    installPhase = ''
      mkdir -p $out/{bin,lib}
      cp *.py $out/lib/backup-psql.py
      cp backup-psql $out/bin/backup-psql
    '';
  }