phylodb-container.nix 2.36 KB
Newer Older
1 2 3 4 5
{ config, pkgs, ... }:
{
  containers.phylodb =
    { config =
      { config, pkgs, ... }:
6
      {
7

8 9 10 11 12 13 14 15 16 17 18 19 20
        environment.systemPackages = with pkgs; [
          coreutils
          findutils
          su
          vim
          postgresql
          postgis
          gdal
          geos
          proj
          sass
          traceroute
          git
Bruno Bzeznik committed
21 22
          wget
          unzip
23
          (python36.withPackages(ps: with ps; [pip virtualenv psycopg2 urllib3 requests]))
24
        ];
25

26 27 28 29 30
         networking.hosts = {
           "127.0.0.1" = [ "localhost" "data.phylodev.org" ];
           "::1" = [ "localhost" ];
         };

31
        networking.nat.enable = true;
32 33 34 35 36 37 38 39 40 41 42 43
        services.openssh.enable = true;
        services.postgresql = {
          enable = true;
          package = pkgs.postgresql;
          authentication = "local all all ident";
          extraPlugins = [ pkgs.postgis ];
          initialScript = pkgs.writeText "backend-initScript" ''
            CREATE USER phyloalps WITH PASSWORD 'phyloalps';
            CREATE DATABASE browser_db OWNER phyloalps;
            CREATE DATABASE editor_db OWNER phyloalps;
          '';
        };
44 45 46 47 48 49 50 51 52

        users.extraUsers.phyloalps = {
          isNormalUser = true;
        };

        services.httpd = {
          enable = true;
          package = pkgs.apacheHttpd;
          adminAddr = "info@phyloalps.org";
53
          hostName = "localhost";
54 55 56 57
          logPerVirtualHost = true;
          extraModules = ["proxy" "proxy_http" "cache"];
          virtualHosts = [
            {
58
               hostName = "data.phylodev.org";
59 60 61 62
               documentRoot = "/var/lib/phyloalps/phylodb";
               extraConfig = ''
 
               ProxyPassReverse / http://localhost:8888/
63

64
               RewriteEngine on
65
               RewriteRule ^/\.well-known/?(.*)$ http://data.phylodev.org/static/%{REQUEST_URI} [L,P]
66 67 68 69 70 71 72 73 74 75
               RewriteRule ^/static/?(.*)$ - [L,P]
               RewriteRule ^/(.*)$ http://localhost:8888/$1 [P]
 
               <Directory /static/>
               Require all granted
               </Directory>
               '';
            }];
        };

76 77 78 79 80 81 82 83 84 85 86
        system.activationScripts = {
          django_init = {
            text = ''
              if [ \! -d /var/lib/django ]
              then
                mkdir /var/lib/django
              fi
            '';
            deps = [];
          };
        };
87
      };
88
    };
89
}