at 25.11-pre 2.4 kB view raw
1{ 2 config, 3 lib, 4 pkgs, 5 ... 6}: 7let 8 9 cfg = config.services.hoogle; 10 11 hoogleEnv = pkgs.buildEnv { 12 name = "hoogle"; 13 paths = [ (cfg.haskellPackages.ghcWithHoogle cfg.packages) ]; 14 }; 15 16in 17{ 18 19 options.services.hoogle = { 20 enable = lib.mkEnableOption "Haskell documentation server"; 21 22 port = lib.mkOption { 23 type = lib.types.port; 24 default = 8080; 25 description = '' 26 Port number Hoogle will be listening to. 27 ''; 28 }; 29 30 packages = lib.mkOption { 31 type = lib.types.functionTo (lib.types.listOf lib.types.package); 32 default = hp: [ ]; 33 defaultText = lib.literalExpression "hp: []"; 34 example = lib.literalExpression "hp: with hp; [ text lens ]"; 35 description = '' 36 The Haskell packages to generate documentation for. 37 38 The option value is a function that takes the package set specified in 39 the {var}`haskellPackages` option as its sole parameter and 40 returns a list of packages. 41 ''; 42 }; 43 44 haskellPackages = lib.mkOption { 45 description = "Which haskell package set to use."; 46 type = lib.types.attrs; 47 default = pkgs.haskellPackages; 48 defaultText = lib.literalExpression "pkgs.haskellPackages"; 49 }; 50 51 home = lib.mkOption { 52 type = lib.types.str; 53 description = "Url for hoogle logo"; 54 default = "https://hoogle.haskell.org"; 55 }; 56 57 host = lib.mkOption { 58 type = lib.types.str; 59 description = "Set the host to bind on."; 60 default = "127.0.0.1"; 61 }; 62 63 extraOptions = lib.mkOption { 64 type = lib.types.listOf lib.types.str; 65 default = [ ]; 66 example = [ "--no-security-headers" ]; 67 description = '' 68 Additional command-line arguments to pass to 69 {command}`hoogle server` 70 ''; 71 }; 72 }; 73 74 config = lib.mkIf cfg.enable { 75 systemd.services.hoogle = { 76 description = "Haskell documentation server"; 77 78 wantedBy = [ "multi-user.target" ]; 79 80 serviceConfig = { 81 Restart = "always"; 82 ExecStart = '' 83 ${hoogleEnv}/bin/hoogle server --local --port ${toString cfg.port} --home ${cfg.home} --host ${cfg.host} \ 84 ${lib.concatStringsSep " " cfg.extraOptions} 85 ''; 86 87 DynamicUser = true; 88 89 ProtectHome = true; 90 91 RuntimeDirectory = "hoogle"; 92 WorkingDirectory = "%t/hoogle"; 93 }; 94 }; 95 }; 96 97}