@@ -0,0 +1,102 @@
1+# This overlay helps accessing common executable components.
2+# Typically we want to make these available in a nix-shell
3+# created with shellFor. In most cases the package name
4+# will be the same as the executable, but we have a
5+# `toolPackageName` mapping to help when it is not.
6+#
7+# To get a single tool:
8+# haskell-nix.tool "cabal" "3.2.0.0"
9+#
10+# This does the same thing as:
11+# (haskell-nix.hackage-package {
12+# name = "cabal-install"
13+# version = "3.2.0.0"
14+# }).components.exes.cabal
15+#
16+# To get an attr set containing multiple tools:
17+# haskell-nix.tools { cabal = "3.2.0.0"; hlint = "2.2.11"; }
18+#
19+# To add tools to a shell:
20+# shellFor { tools = { cabal = "3.2.0.0"; hlint = "2.2.11"; }; }
21+#
22+# When used in shellFor the tools will be compiled with the same version
23+# of ghc used in the shell (the build ghc in the case of cross compilation).
24+#
25+# Instead of a version string we can use an attr set containing
26+# arguments that will be passed to `cabalProject`.
27+#
28+# For instance to specify the ghc used to compile. Use:
29+# haskell-nix.tool "cabal" {
30+# version = "3.2.0.0";
31+# ghc = haskell-nix.compiler.ghc883;
32+# }
33+#
34+self: super:
35+let
36+ inherit (self) lib;
37+
38+in { haskell-nix = super.haskell-nix // {
39+
40+ # Some times the package name in hackage is not the same as tool name.
41+ toolPackageName = {
42+ cabal = "cabal-install";
43+ };
44+
45+ hackage-tool = { name, ... }@args:
46+ (self.haskell-nix.hackage-package
47+ (args // { name = self.haskell-nix.toolPackageName."${name}" or name; }))
48+ .components.exes."${name}";
49+
50+ tool = name: versionOrArgs:
51+ let
52+ args = self.haskell-nix.haskellLib.versionOrArgsToArgs versionOrArgs;
53+ in
54+ (if self.haskell-nix.custom-tools ? "${name}"
55+ && self.haskell-nix.custom-tools."${name}" ? "${args.version}"
56+ then self.haskell-nix.custom-tools."${name}"."${args.version}"
57+ else self.haskell-nix.hackage-tool) (args // { inherit name; });
58+
59+ tools = lib.mapAttrs self.haskell-nix.tool;
60+
61+ # Like `tools` but allows default ghc to be specified
62+ toolsForGhc = ghc: toolSet:
63+ self.haskell-nix.tools (
64+ lib.mapAttrs (name: versionOrArgs:
65+ # Add default ghc if not specified in the args
66+ { inherit ghc; }
67+ // self.haskell-nix.haskellLib.versionOrArgsToArgs versionOrArgs
68+ ) toolSet
69+ );
70+
71+ # Tools not in hackage yet
72+ custom-tools = {
73+ ghcide.object-code = args:
74+ (self.haskell-nix.cabalProject (args // {
75+ name = "ghcide";
76+ src = self.fetchFromGitHub {
77+ owner = "mpickering";
78+ repo = "ghcide";
79+ rev = "706c59c97c25c66798815c1dc3ee6885a298918a";
80+ sha256 = "0d158xifwvz0y69ah98ckxakzqpz229mq7rpf2bpbmwhnpw3jmm6";
81+ };
82+ modules = [({config, ...}: {
83+ packages.ghcide.configureFlags = [ "--enable-executable-dynamic" ];
84+ nonReinstallablePkgs = [ "Cabal" "array" "base" "binary" "bytestring" "containers" "deepseq"
85+ "directory" "filepath" "ghc" "ghc-boot" "ghc-boot-th" "ghc-compact"
86+ "ghc-heap" "ghc-prim" "ghci" "haskeline" "hpc" "integer-gmp"
87+ "libiserv" "mtl" "parsec" "pretty" "process" "rts" "stm"
88+ "template-haskell" "terminfo" "text" "time" "transformers" "unix"
89+ "xhtml"
90+ ];
91+ })];
92+ pkg-def-extras = [
93+ (hackage: {
94+ packages = {
95+ "alex" = (((hackage.alex)."3.2.5").revisions).default;
96+ "happy" = (((hackage.happy)."1.19.12").revisions).default;
97+ };
98+ })
99+ ];
100+ })).ghcide.components.exes.ghcide;
101+ };
102+}; }