1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6
7 cfg = config.services.hoogle;
8
9 hoogleEnv = pkgs.buildEnv {
10 name = "hoogle";
11 paths = [ (cfg.haskellPackages.ghcWithHoogle cfg.packages) ];
12 };
13
14in {
15
16 options.services.hoogle = {
17 enable = mkEnableOption "Haskell documentation server";
18
19 port = mkOption {
20 type = types.int;
21 default = 8080;
22 description = ''
23 Port number Hoogle will be listening to.
24 '';
25 };
26
27 packages = mkOption {
28 default = hp: [];
29 defaultText = "hp: []";
30 example = "hp: with hp; [ text lens ]";
31 description = ''
32 The Haskell packages to generate documentation for.
33
34 The option value is a function that takes the package set specified in
35 the <varname>haskellPackages</varname> option as its sole parameter and
36 returns a list of packages.
37 '';
38 };
39
40 haskellPackages = mkOption {
41 description = "Which haskell package set to use.";
42 default = pkgs.haskellPackages;
43 defaultText = "pkgs.haskellPackages";
44 };
45
46 };
47
48 config = mkIf cfg.enable {
49 systemd.services.hoogle = {
50 description = "Haskell documentation server";
51
52 wantedBy = [ "multi-user.target" ];
53
54 serviceConfig = {
55 Restart = "always";
56 ExecStart = ''${hoogleEnv}/bin/hoogle server --local -p ${toString cfg.port}'';
57
58 User = "nobody";
59 Group = "nogroup";
60
61 PrivateTmp = true;
62 ProtectHome = true;
63
64 RuntimeDirectory = "hoogle";
65 WorkingDirectory = "%t/hoogle";
66 };
67 };
68 };
69
70}