summaryrefslogtreecommitdiffstats
path: root/shell.nix
blob: 33fa1ecfd35ca883a6a6c87a1facbec6a40eb4ed (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
{ compiler ? "default" }: let

  stockholm = import <stockholm>;
  inherit (stockholm.systems.${lib.krops.getHostName}) config pkgs;
  inherit (stockholm) lib;

  haskellPackages =
    if compiler == "default"
      then pkgs.haskellPackages
      else pkgs.haskell.packages.${compiler};

  drv = haskellPackages.callPackage (import ./.) {};

in

  lib.overrideDerivation drv.env (oldAttrs: {

    buildInputs = [
      pkgs.flameshot
      pkgs.xwaitforwindow
    ];

    shellHook = ''
      pkg_name=${lib.escapeShellArg (builtins.baseNameOf (toString ./.))}

      WORKDIR=${lib.escapeShellArg (toString ./.)}
      CACHEDIR=$HOME/tmp/$pkg_name
      HISTFILE=$CACHEDIR/bash_history

      mkdir -p "$CACHEDIR"

      exe=$CACHEDIR/${lib.currentSystem}

      build() {(
        set -efu
        cd "$WORKDIR"
        options=$(
          ${pkgs.cabal-read}/bin/ghc-options "$pkg_name.cabal" "$pkg_name"
        )
        exec ghc $options \
            -isrc \
            -odir "$CACHEDIR" \
            -hidir "$CACHEDIR" \
            -o "$exe" \
            src/main.hs
      )}

      run() {(
        exec "$exe" "$@"
      )}

      export SHELL=/run/current-system/sw/bin/bash
      export FLAMESHOT_CAPTURE_PATH="$CACHEDIR/captures"

      cd "$WORKDIR"
    '';
  })