summaryrefslogtreecommitdiff
path: root/custom/run-opossum_bragi.nix
blob: 6d08fa4c7050b8b1d4a708bbfb44ca8aa09153b9 (plain)
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
{ stdenv
, zsh
, findutils
, coreutils
, makeWrapper
, wombat
, opossum
}:

stdenv.mkDerivation rec {
  name = "run-opossum-${version}";
  version = "0.0.0";
  buildInputs = [ makeWrapper ];
	src = builtins.toFile name ''
    #!/usr/bin/env zsh

    oversized() {
      l=$(du -BG -s -t 75 $BEUTEL | wc -l)
      [[ $l -ge 1 ]]
    }

    echo "Started $(date)" > $LOGFILE
    opossum &>> $LOGFILE

    wombat search "(not (seen or hidden)) and (not forced)" | \
      xargs -r -n 1 -d '\n' -- wombat force \
      &>> $LOGFILE

    find $BEUTEL -type f -iname '*.tgz.bak' -delete

    if oversized; then
      wombat search "(seen or hidden) and forced" | \
      while (read file && oversized); do
        wombat reset $file
        find $BEUTEL -type f -iname '*.tgz.bak' -delete
      done

      wombat search "seen or hidden" | \
        while (read file && oversized); do
          wombat delete $file
          size=$(du -BG $BEUTEL)
        done
    fi

    echo "Ended $(date)" >> $LOGFILE
  '';
  phases = [ "buildPhase"
             "installPhase"
             "fixupPhase"
           ];
  buildPhase = ''
    cp -prd --no-preserve=timestamps $src run-opossum
  '';
  installPhase = ''
    mkdir -p $out/bin
    cp run-opossum $out/bin
    chmod +x $out/bin/run-opossum
    wrapProgram $out/bin/run-opossum \
      --prefix PATH : ${wombat}/bin \
      --prefix PATH : ${opossum}/bin \
      --prefix PATH : ${findutils}/bin \
      --prefix PATH : ${coreutils}/bin \
      --set BEUTEL \$HOME/.beutel \
      --set LOGFILE \$HOME/.last_opossum.log
  '';
}