summary refs log tree commit diff
path: root/pkgs/development/tools/haskell/lambdabot/default.nix
blob: f2462ed54e170d47d81f958586364ddf6729fa5a (plain) (blame)
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
{ lib, makeWrapper, haskellngPackages
, mueval
, withDjinn ? true
, aspell ? null
, packages ? (pkgs: [])
, modules ? ''
    haskellPlugins
    ++ ["irc", "localtime", "topic"]
    ++ ["dummy", "fresh", "todo"]
    ++ ["bf", "dice", "elite", "filter", "quote", "slap", "unlambda", "vixen"]
    ++ referencePlugins
    ++ socialPlugins
''
, configuration ? "[]"
}:

# FIXME: fix hoogle search

let allPkgs = pkgs: mueval.defaultPkgs pkgs ++ [ pkgs.lambdabot-trusted ] ++ packages pkgs;
    mueval' = mueval.override {
      inherit haskellngPackages;
      packages = allPkgs;
    };
    bins = lib.makeSearchPath "bin" ([ mueval'
                                       (haskellngPackages.ghcWithPackages allPkgs)
                                       haskellngPackages.unlambda
                                       haskellngPackages.brainfuck
                                     ]
                                     ++ lib.optional withDjinn haskellngPackages.djinn
                                     ++ lib.optional (aspell != null) aspell
                                    );
    modulesStr = lib.replaceChars ["\n"] [" "] ("corePlugins ++ " + modules);
    configStr = lib.replaceChars ["\n"] [" "] configuration;

in lib.overrideDerivation haskellngPackages.lambdabot (self: {
  postPatch = (self.postPatch or "") + ''
    sed -i 's/\(\$(modules \$ \).*/\1@modules@)/; /@modules@/q' src/Modules.hs
    # not via sed to avoid escaping issues
    substituteInPlace src/Modules.hs \
      --replace '@modules@' '${modulesStr}'
    sed -i 's/\[dataDir :=> dir\]/@config@ ++ \0/' src/Main.hs
    substituteInPlace src/Main.hs \
      --replace '@config@' '${configStr}'
  '';

  buildInputs = self.buildInputs ++ [ makeWrapper ];

  postInstall = (self.postInstall or "") + lib.optionalString (bins != "") ''
    wrapProgram $out/bin/lambdabot \
      --prefix PATH ":" '${bins}'
  '';
})