aboutsummaryrefslogtreecommitdiffstats
path: root/default.nix
blob: 0d16bcbd8e5286917cc4e270410fbc486599e980 (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
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
{ pkgs ? import (import ./nix/sources.nix).nixpkgs {
    overlays = [
      (self: super: {
        tree-sitter = super.tree-sitter.overrideAttrs (oldAttrs: {
          buildInputs = oldAttrs.buildInputs or [ ] ++ [
            super.makeWrapper
          ];
          postInstall = oldAttrs.postInstall or "" + ''
            wrapProgram $out/bin/tree-sitter \
              --prefix LD_LIBRARY_PATH : "${super.tree-sitter.withPlugins (_: self.tree-sitter.allGrammars)}"
          '';
        });
      })
      (self: super: {
        tree-sitter-grammars = pkgs.lib.mapAttrs
          (name: grammar:
            if self.lib.isDerivation grammar then
              pkgs.stdenv.mkDerivation
                {
                  inherit (grammar) pname version;
                  phases = [ "installPhase" ];
                  installPhase = ''
                    mkdir -p $out/lib
                    cp ${grammar}/parser $out/lib/lib${name}.so
                  '';
                }
            else
              grammar

          )
          super.tree-sitter-grammars;
      })
      (self: super: {
        anissue = pkgs.writers.writeDashBin "anissue" ''
          set -efu
          cwd=$PWD
          cd ${self.lib.escapeShellArg (toString ./.)}
          cabal build anissue
          anissue=$(find dist-newstyle -type f -executable -name anissue -exec realpath '{}' \; | head -1)
          cd $cwd
          exec $anissue "$@"
        '';
      })
    ];
  }
}:

let

  haskellPackages = pkgs.haskellPackages.override {
    overrides = self: super: {
      diff-parse = pkgs.haskell.lib.appendPatch super.diff-parse
        ./diff-parse.patch;
      lingo = pkgs.haskell.lib.doJailbreak
        (pkgs.haskell.lib.markUnbroken super.lingo);
      sh = pkgs.haskell.lib.dontCheck (super.callCabal2nix "sh" (import ./nix/sources.nix).sh { });
      anissue = (super.callCabal2nix "anissue" ./. ({
        inherit (pkgs) tree-sitter;
      } // pkgs.lib.filterAttrs (_: pkgs.lib.isDerivation)
        pkgs.tree-sitter-grammars
      )).overrideAttrs (oldAttrs: rec {
        nativeBuildInputs = [ pkgs.installShellFiles ];
        buildInputs = oldAttrs.buildInputs or [ ] ++ [ pkgs.makeWrapper ];
        passthru = oldAttrs.passthru // {
          dependencies = [
            pkgs.coreutils
            pkgs.git
            pkgs.patchutils
          ];
        };
        postInstall = ''
          exe=${oldAttrs.pname}

          wrapProgram $out/bin/$exe --prefix PATH : ${pkgs.lib.makeBinPath passthru.dependencies}

          installShellCompletion --cmd $exe  \
            --bash <($out/bin/$exe --bash-completion-script $out/bin/.$exe-wrapped) \
            --fish <($out/bin/$exe --fish-completion-script $out/bin/.$exe-wrapped) \
            --zsh  <($out/bin/$exe --zsh-completion-script $out/bin/.$exe-wrapped)
        '';
      });
    };
  };

in

rec {
  inherit (haskellPackages) anissue;
  inherit (pkgs) tree-sitter-grammars;
  shell = haskellPackages.shellFor {
    packages = _: [ anissue ];
    buildInputs = [
      haskellPackages.cabal-install
      haskellPackages.hlint
      haskellPackages.ormolu
      haskellPackages.pointfree
      pkgs.anissue
      pkgs.ghcid
      pkgs.haskell-language-server
      pkgs.tree-sitter
    ]
    ++ (
      pkgs.lib.filter pkgs.lib.isDerivation
        (pkgs.lib.attrValues pkgs.tree-sitter-grammars)
    )
    ++ anissue.passthru.dependencies;
    withHoogle = true;
    withHaddock = true;
    shellHook = ''
      HISTFILE=${pkgs.lib.escapeShellArg ./.}/.history; export HISTFILE
    '';
  };
}