2020-04-24 23:36:52 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.services.hoogle;
|
|
|
|
|
|
|
|
hoogleEnv = pkgs.buildEnv {
|
|
|
|
name = "hoogle";
|
|
|
|
paths = [ (cfg.haskellPackages.ghcWithHoogle cfg.packages) ];
|
|
|
|
};
|
|
|
|
|
|
|
|
in {
|
|
|
|
|
|
|
|
options.services.hoogle = {
|
2024-09-19 14:19:46 +00:00
|
|
|
enable = lib.mkEnableOption "Haskell documentation server";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
port = lib.mkOption {
|
|
|
|
type = lib.types.port;
|
2020-04-24 23:36:52 +00:00
|
|
|
default = 8080;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Port number Hoogle will be listening to.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
packages = lib.mkOption {
|
|
|
|
type = lib.types.functionTo (lib.types.listOf lib.types.package);
|
2020-04-24 23:36:52 +00:00
|
|
|
default = hp: [];
|
2024-09-19 14:19:46 +00:00
|
|
|
defaultText = lib.literalExpression "hp: []";
|
|
|
|
example = lib.literalExpression "hp: with hp; [ text lens ]";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-04-24 23:36:52 +00:00
|
|
|
The Haskell packages to generate documentation for.
|
|
|
|
|
|
|
|
The option value is a function that takes the package set specified in
|
2022-09-09 14:08:57 +00:00
|
|
|
the {var}`haskellPackages` option as its sole parameter and
|
2020-04-24 23:36:52 +00:00
|
|
|
returns a list of packages.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
haskellPackages = lib.mkOption {
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "Which haskell package set to use.";
|
2024-09-19 14:19:46 +00:00
|
|
|
type = lib.types.attrs;
|
2020-04-24 23:36:52 +00:00
|
|
|
default = pkgs.haskellPackages;
|
2024-09-19 14:19:46 +00:00
|
|
|
defaultText = lib.literalExpression "pkgs.haskellPackages";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
home = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "Url for hoogle logo";
|
2020-04-24 23:36:52 +00:00
|
|
|
default = "https://hoogle.haskell.org";
|
|
|
|
};
|
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
host = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "Set the host to bind on.";
|
2021-01-09 10:05:03 +00:00
|
|
|
default = "127.0.0.1";
|
|
|
|
};
|
2024-04-21 15:54:59 +00:00
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
extraOptions = lib.mkOption {
|
|
|
|
type = lib.types.listOf lib.types.str;
|
2024-04-21 15:54:59 +00:00
|
|
|
default = [];
|
|
|
|
example = [ "--no-security-headers" ];
|
|
|
|
description = ''
|
|
|
|
Additional command-line arguments to pass to
|
|
|
|
{command}`hoogle server`
|
|
|
|
'';
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
config = lib.mkIf cfg.enable {
|
2020-04-24 23:36:52 +00:00
|
|
|
systemd.services.hoogle = {
|
|
|
|
description = "Haskell documentation server";
|
|
|
|
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
Restart = "always";
|
2024-04-21 15:54:59 +00:00
|
|
|
ExecStart = ''
|
|
|
|
${hoogleEnv}/bin/hoogle server --local --port ${toString cfg.port} --home ${cfg.home} --host ${cfg.host} \
|
2024-09-19 14:19:46 +00:00
|
|
|
${lib.concatStringsSep " " cfg.extraOptions}
|
2024-04-21 15:54:59 +00:00
|
|
|
'';
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2020-12-03 08:41:04 +00:00
|
|
|
DynamicUser = true;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
ProtectHome = true;
|
|
|
|
|
|
|
|
RuntimeDirectory = "hoogle";
|
|
|
|
WorkingDirectory = "%t/hoogle";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|