nur-packages

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

tracks_storage_server.nix (2140B)


      1 {
      2   config,
      3   lib,
      4   pkgs,
      5   ...
      6 }:
      7 
      8 with lib;
      9 
     10 let
     11   cfg = config.services.tracks_storage_server;
     12 in
     13 {
     14   options.services.tracks_storage_server = {
     15     enable = mkEnableOption "tracks_storage_server";
     16     package = mkPackageOption pkgs "tracks_storage_server" { };
     17     nginx = mkOption {
     18       default = { };
     19       description = ''
     20         Configuration for nginx reverse proxy.
     21       '';
     22       type = types.submodule {
     23         options = {
     24           enable = mkOption {
     25             type = types.bool;
     26             default = false;
     27             description = ''
     28               Configure the nginx reverse proxy settings.
     29             '';
     30           };
     31           hostName = mkOption {
     32             type = types.str;
     33             description = ''
     34               The hostname use to setup the virtualhost configuration
     35             '';
     36           };
     37         };
     38       };
     39     };
     40   };
     41 
     42   config = mkIf cfg.enable (mkMerge [
     43     {
     44       services.uwsgi.enable = true;
     45       services.uwsgi.plugins = [ "python3" ];
     46       services.uwsgi.instance = {
     47         type = "emperor";
     48         vassals.tracks = {
     49           type = "normal";
     50           master = true;
     51           workers = 2;
     52           socket = "127.0.0.1:8181";
     53           module = "server:application";
     54           pythonPackages = self: [ cfg.package ];
     55         };
     56       };
     57     }
     58     (mkIf cfg.nginx.enable {
     59       services.nginx = {
     60         enable = true;
     61         virtualHosts."${cfg.nginx.hostName}" = {
     62           locations."/" = {
     63             extraConfig = ''
     64               uwsgi_pass localhost:8181;
     65               include ${config.services.nginx.package}/conf/uwsgi_params;
     66 
     67               more_clear_headers Access-Control-Allow-Origin;
     68               more_clear_headers Access-Control-Allow-Credentials;
     69               more_set_headers 'Access-Control-Allow-Origin: $http_origin';
     70               more_set_headers 'Access-Control-Allow-Credentials: true';
     71               more_set_headers 'Cache-Control: max-age=315360000';
     72               more_set_headers 'Expires: Thu, 31 Dec 2037 23:55:55 GMT';
     73               more_set_headers 'Vary: Origin';
     74             '';
     75           };
     76         };
     77       };
     78     })
     79   ]);
     80 }