nur-packages

My NUR packages
git clone git://git.sikmir.ru/nur-packages
Log | Files | Refs | README | LICENSE

mbtileserver.nix (2382B)


      1 {
      2   config,
      3   lib,
      4   pkgs,
      5   ...
      6 }:
      7 
      8 with lib;
      9 
     10 let
     11   cfg = config.services.mbtileserver;
     12 in
     13 {
     14   options.services.mbtileserver = {
     15     enable = mkEnableOption "mbtileserver";
     16     package = mkOption {
     17       type = types.package;
     18       default = pkgs.mbtileserver;
     19       defaultText = literalMD "pkgs.mbtileserver";
     20       description = "Which mbtileserver package to use.";
     21     };
     22     tileDir = mkOption {
     23       type = types.path;
     24       default = "/srv/tilesets";
     25       description = "The path where *.mbtiles files stored.";
     26     };
     27     nginx = mkOption {
     28       default = { };
     29       description = ''
     30         Configuration for nginx reverse proxy.
     31       '';
     32       type = types.submodule {
     33         options = {
     34           enable = mkOption {
     35             type = types.bool;
     36             default = false;
     37             description = ''
     38               Configure the nginx reverse proxy settings.
     39             '';
     40           };
     41           hostName = mkOption {
     42             type = types.str;
     43             description = ''
     44               The hostname use to setup the virtualhost configuration
     45             '';
     46           };
     47         };
     48       };
     49     };
     50   };
     51 
     52   config = mkIf cfg.enable (mkMerge [
     53     {
     54       systemd.services.mbtileserver = {
     55         description = "MBTiles server";
     56         after = [ "network.target" ];
     57         wantedBy = [ "multi-user.target" ];
     58         environment.TILE_DIR = cfg.tileDir;
     59         serviceConfig = {
     60           DynamicUser = true;
     61           LogsDirectory = "mbtileserver";
     62           ExecStart = "${lib.getBin cfg.package}/bin/mbtileserver --enable-reload-signal --tiles-only";
     63           Restart = "always";
     64         };
     65       };
     66     }
     67     (mkIf cfg.nginx.enable {
     68       services.nginx = {
     69         enable = true;
     70         virtualHosts."${cfg.nginx.hostName}" = {
     71           locations."/" = {
     72             root = cfg.tileDir;
     73             extraConfig = ''
     74               autoindex on;
     75               autoindex_exact_size off;
     76             '';
     77           };
     78           locations."/services" = {
     79             proxyPass = "http://localhost:8000";
     80             extraConfig = ''
     81               #proxy_set_header Host ''$host;
     82               #proxy_set_header X-Forwarded-Host ''$server_name;
     83               #proxy_set_header X-Real-IP ''$remote_addr;
     84               add_header Cache-Control 'public, max-age=3600, must-revalidate';
     85             '';
     86           };
     87         };
     88       };
     89     })
     90   ]);
     91 }