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
{ depot, pkgs, lib, ... }:

let

  exes = [
    {
      exeName = "copy";
      toolsVar = "COPY_TOOLS";
      exeTools = { };
    }

    {
      exeName = "camera";
      toolsVar = "CAMERA_TOOLS";
      exeTools = {
        exiftool = "${pkgs.exiftool}/bin/exiftool";
      };
    }
  ];

  drv = pkgs.haskellPackages.mkDerivation {
    pname = "my-tools";
    version = "0.0.1-unreleased";

    src = depot.users.Profpatsch.exactSource ./. [
      ./my-tools.cabal
      ./src/MyTools.hs
      ./exe/Copy.hs
      ./exe/Camera.hs
    ];

    isLibrary = false;

    executableToolDepends = [ pkgs.makeWrapper ];

    libraryHaskellDepends = [
      depot.users.Profpatsch.my-prelude
      pkgs.haskellPackages.optparse-simple
    ];

    # I copied this from `__generateOptparseApplicativeCompletion` because I can’t be bothered
    # to figure out how the haskellPackages override callPackage bs really works.
    postInstall = lib.concatMapStringsSep "\n"
      (exe: ''
        # Wrap the tools around the executable
        wrapProgram "''${!outputBin}/bin/${exe.exeName}" --set ${exe.toolsVar} '${builtins.toJSON exe.exeTools}'

        bashCompDir="''${!outputBin}/share/bash-completion/completions"
        zshCompDir="''${!outputBin}/share/zsh/vendor-completions"
        fishCompDir="''${!outputBin}/share/fish/vendor_completions.d"
        mkdir -p "$bashCompDir" "$zshCompDir" "$fishCompDir"
        "''${!outputBin}/bin/${exe.exeName}" --bash-completion-script "''${!outputBin}/bin/${exe.exeName}" >"$bashCompDir/${exe.exeName}"
        "''${!outputBin}/bin/${exe.exeName}" --zsh-completion-script "''${!outputBin}/bin/${exe.exeName}" >"$zshCompDir/_${exe.exeName}"
        "''${!outputBin}/bin/${exe.exeName}" --fish-completion-script "''${!outputBin}/bin/${exe.exeName}" >"$fishCompDir/${exe.exeName}.fish"
      '')
      exes;

    license = lib.licenses.mit;

  };

in
drv